Which is the recommended way for 'startpos' in PlayBuf.ar when Buffer's sample rate is different from the server's?

Which is the recommended way for ‘startpos’ in PlayBuf.ar when Buffer’s sample rate is different from the server’s?

Let’s assume that “aTestFile.wav” has three channels and its duration is 10 seconds:

b = Buffer.read(s, Platform.resourceDir +/+ "sounds/aTestFile.wav");

I want to start playing it at 3 seconds.

The shortest and most straightforward way seems to be as follows:

x = { PlayBuf.ar(b.numChannels, b.bufnum, BufRateScale.kr(b.bufnum), startPos:  3 * b.sampleRate, doneAction: Done.freeSelf) }.play

The following way seems to be a bit weird, but it works:

y = { PlayBuf.ar(b.numChannels, b.bufnum, BufRateScale.kr(b.bufnum), startPos:  3 * BufRateScale.kr(b.bufnum) * SampleRate.ir, doneAction: Done.freeSelf) }.play

Which way could be referred to as a standard one? The first one seems better for me because the code is shorter than the latter.

Best regards,

I don’t think there’s a standard idiom, but I’d write it like this (basically your first version, but by using BufSampleRate.kr changes to the buffer such as reallocation are tracked):

y = { PlayBuf.ar(b.numChannels, b, BufRateScale.kr(b), startPos: 3 * BufSampleRate.kr(b), doneAction: Done.freeSelf) }.play
1 Like