Realtime changes to playback rate

I’m having trouble changing the playback rate as I stream a buffer. I’d like to be able to use a hardware controller to change the rate as the buffer is playing.
At the moment I am reading an external sample into a buffer. Here is the player. I am using doneAction:1 so that triggering the gate just pauses playback, which can recommence when the player is restarted:

   player = { | gate=1, rate=1.0, startPos=0 |
      var env;
      env = EnvGen.kr (
         Env.adsr(1, 0.5, 0.95, 0.3, 0.5, 1.0, -6.0), 
            gate,
            doneAction:1);
      PlayBuf.ar( 1,
         buf, 
         BufRateScale.kr(buf) * rate, 
         startPos:startPos,
         loop:1 ) * env };

New samples are loaded into a buffer like this:

        buf = Buffer.read(s, path);

and they are played and stopped like this:

        // start
        controller = player.play;
        // stop / pause
        controller.set(\gate, 0)

I had hoped that by setting the rate using:

        BufRateScale.kr(pInfo[\buffer]) * rate

eg. I assumed I would be able to continuously change the rate by setting the value of rate using:

        controller.set(\rate, -0.5)

But that doesn’t work. What should I be doing?

Thanks in advance
Andy

the problem is the t_ in your argument name - the control here is simply rate !! so

controller.set(\rate, -0.5)

controls can be defined with different rates - if you prepend t_ to an argument name (when defining it!), the resulting control will be defined as a trigger rate control. That’s just a shortcut - there are other ways to set the rate of controls. I’d suggest you have a peek at the NamedControl and Control helps

You’ve already defined this control as simply rate and it so will be running at the default - control rate. Either way the set argument needs to be same as the defined name.

Whoops. That t_rate is a typo. I simplified my code a little in the interests of comprehensibility but forgot t edit that. I’ve edited the OP to fix that. Thanks for spotting it!

haha sorry for the unnecessary pedantry! So it’s working for you yes?

(
var buf = Buffer.read(s,"~/tank/super/samples/La_Mer_fx.aif".standardizePath);
var player = { | gate=1, rate=1.0, startPos=0 |
      var env;
      env = EnvGen.kr (
         Env.adsr(1, 0.5, 0.95, 0.3, 0.5, 1.0, -6.0), 
            gate,
            doneAction:1);
      PlayBuf.ar( 1,
         buf, 
         BufRateScale.kr(buf) * rate, 
         startPos:startPos,
         loop:1 ) * env };
)
	 ~controller = player.play;
	 ~controller.set(\rate,-3)
1 Like

that works. thanks!!