1

Can't seem to get TickRate to change when playing back sample, when playing sample with 's' or 'd' key, both play at the same rate, trying to make it so that when playing different keys it will play a different pitch of the recorded sound like a sort of piano keyboard. It's probably a silly mistake but any help would be appreciated thanks. :)

import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.signals.*;
import ddf.minim.ugens.*;
import ddf.minim.spi.*;

Minim minim;
AudioOutput out;
AudioSample sample1;
AudioInput in;
AudioRecorder recorder;
boolean recorded;
FilePlayer player;
TickRate rateControl;
float rate =2;

void setup()
{

  size(512, 200, P3D);
  minim = new Minim(this);

  in = minim.getLineIn(Minim.STEREO, 512);

  recorder = minim.createRecorder(in, "myrecording.wav");
  rateControl = new TickRate(1.f);
  out = minim.getLineOut(Minim.STEREO, 512);
  player = new FilePlayer(minim.loadFileStream("myrecording.wav") );

  player.patch(rateControl).patch(out);
}

void draw()
{

}



void keyReleased()
{
  if ( !recorded && key == 'r' ) 
  {
    if ( recorder.isRecording() ) 
    {
      recorder.endRecord();
      recorded = true;
    }
    else 
    {
      recorder.beginRecord();
    }
  }
  if ( recorded && key == 'q' )
  {
    player = new FilePlayer( recorder.save() );
    sample1 = minim.loadSample( "myrecording.wav" , 512 );
    if ( sample1 == null ) println("didn't get sample");
  }
}


void keyPressed()
{

  if ( key == 's' ) 
  {
    sample1.trigger();
  }

  else if ( key == 'd' )
  {

    rateControl.value.setLastValue(rate);
    sample1.trigger(); 

  }

}
  • Like I said in your last question, you need to get into the habit of [debugging your code](http://happycoding.io/tutorials/processing/debugging). If it's a silly mistake, then debugging should help you figure it out. You should also really try to [break your problem down into smaller pieces](http://happycoding.io/tutorials/how-to/program) and post a [mcve] instead of your whole project. Please narrow the problem down to a smaller example. Maybe try just playing a single sound with a different pitch, without any user interaction? – Kevin Workman Dec 28 '17 at 17:21
  • @KevinWorkman honestly i can't get this working, I've tried this without user input for the sound but can't figure out how to do it at all, been trying this for a couple of weeks now. – michael doherty Dec 28 '17 at 18:58
  • Then please post a [mcve] that shows a minimal attempt at modifying the pitch of a sound file. For example, your problem has nothing to do with setting the font, right? So don't include lines like that. Start over with a blank sketch and add just enough code to show how you're modifying the pitch. – Kevin Workman Dec 28 '17 at 19:35
  • @KevinWorkman just updated code in original post above i think this is as concise as i can make it while still being complete. – michael doherty Dec 28 '17 at 21:46
  • @KevinWorkman ???? – michael doherty Dec 30 '17 at 01:13

0 Answers0