I want to playback a sample in a SynthDef and want to define the playback position in seconds. 0 seconds in, 120 seconds in etc?
Anybody good at this math?
If you pass in the time in seconds as an argument, in your SynthDef you can use BufSampleRate.kr with your buffer id:
SynthDef(\test, {arg timeInSeconds = 120, yourBuffer = 0;
var startPos;
startPos = timeInSeconds * BufSampleRate.kr(yourBuffer);
…
})
Something like that.
Hope that helps!
Josh
Thanks! Came up with this and this also works
(
SynthDef.new(\simpsampHMS, {
arg buf, amp=0.5, rate=1, h=0, min=0, sek=0;
var sig;
sig= PlayBuf.ar(2, buf, rate,startPos: (((h*60*60)+(min*60)+sek) * SampleRate.ir(buf)).clip(0,BufFrames.ir(buf)-1),doneAction: 2);
sig= sig*amp;
Out.ar(0,sig);
}).add
)
I can see that it is not the SampleRate of the server that I want but of the sample. But in this case they were both 41000 so it worked the same