Fix echoes on my NoteSheet Player

I was working on a music notes player loaded through .csv file. Is there any way to reduce that echo when the play speed increase or perhaps smooth out the playback? Here's my current code:-

import ddf.minim.ugens.*;
import ddf.minim.*;

Minim minim;
AudioOutput out;

Track t1;

void setup() {
  size(600, 600);
  frameRate(8);

  minim = new Minim(this);
  out = minim.getLineOut();

  t1 = new Track("CanonRock.csv");
}

void draw() {
  background(51);
  t1.play();
}

class ToneInstrument implements Instrument{
  Oscil toneOsc;
  ADSR adsr;
  AudioOutput out;

  ToneInstrument( String note, float amplitude, Waveform wave, AudioOutput output ){
    out = output;

    float frequency = Frequency.ofPitch( note ).asHz();

    toneOsc = new Oscil( frequency, amplitude, wave );
    adsr = new ADSR( 1.0, 0.04, 0.01, 1.0, 0.1 );

    toneOsc.patch( adsr );
  }

  void noteOn( float dur ){
    adsr.noteOn();
    adsr.patch( out );
  }

  void noteOff(){
    adsr.noteOff();
    adsr.unpatchAfterRelease( out );
  }
}

class Track{
  ArrayList<String> type;
  ArrayList<String> chords;
  int current = 0;
  boolean stop = false;

  float vol = 0.45;
  Waveform disWave = Waves.sawh( 4 );

  Track(String csv){
    type = new ArrayList<String>();
    chords = new ArrayList<String>();

    String[] notes = loadStrings(csv);
    for(int i=0;i<notes.length;i++){
      String[] delims = notes[i].split(";");
      type.add(delims[0]);
      chords.add(delims[1]);
    }
  }

  void addChord(String chord){
    chords.add(chord);
  }

  void addChords(ArrayList<String> chord){
    chords.addAll(chord);
  }

  void play(){
    if(chords.size() == 0 || stop)return;

    out.playNote( 1.0, 1.0, new ToneInstrument(chords.get(current), vol, disWave, out ) );

    textSize(72);
    text(chords.get(current),40,vol* 200);

    int wait = 0;
    switch(type.get(current)){
      case "Minim":
        wait = 2; // 8 / 2
        break;
      case "Crochet":
        wait = 4;
        break;
    }
    float sleep = (wait == 0) ? 0 : 8.0 / (wait * wait / 3);

    if(wait != 0)delay((int)(200 * sleep));

    current++;
    if(current >= chords.size()){
      current = 0;  //Enable repeat
      //stop = true;
      //stop();
    }
  }

  void stop(){
    vol = 0;
  }
}

You can get the "CanonRock.csv" file here

Reference:- https://www.jellynote.com/en/sheet-music-tabs/jerryc/canon-rock/5076e948d2235a7374cdd6c1#tabs:A

Sign In or Register to comment.