CtkBuffer cueSoundFile

Hi @josh especially,

I am trying to wrap my head around Ctk and reached a stumbling point here:

I would like to generate a score which streams audio files from disk, one at a time, but many different files for a very long time. I can see how to make a CtkBuffer to do this once, but I can’t figure out how to schedule it to re-cue itself at a certain time in the score…

var audioPath = "/Users/ericsluyter/mono.wav";
var score = CtkScore();

var stream = CtkNoteObject(
  SynthDef(\stream, { 
    var buf = \buf.kr(0);
    var sig = VDiskIn.ar(1, buf, 1);
    var amp = \amp.kr(0.1);
    var out = \out.kr(0);
    Out.ar(out, sig * amp);

var streamBuf = CtkBuffer.diskin(audioPath, startFrame: 5.8 * 60 * 48000).addTo(score);

stream.new(0.5, 15).buf_(streamBuf).out_(0).addTo(score);

/* would like to cue a different point in potentially a different soundfile
and then add another stream using the same buffer at say 16 seconds */ 

~score = score;

Is this possible using Ctk?

Thanks in advance,

I think I’ve managed to roll my own with Score, so no urgency on this question. Still curious though if there’s a way to do this with Ctk

Can you please share what your OSC messages wound up looking like?

Thanks! That will help me see if there is a way already to do this, or if there is a good way to add it.



Hi Josh,

Sure, at the beginning of the score I have:

[0.0, ['/d_recv',
  SynthDef(\stream, {
    var buf = \buf.kr(0);
    var sig = VDiskIn.ar(1, buf, 1);
    var amp = \amp.kr(0.1);
    var out = \out.kr(0);
    Out.ar(out, sig * amp);

followed by several

[0.0, [\b_alloc, bufnum, 32768, 1]]

then for each bit of a sound file to be played:

[startTime, [\b_close, bufnum]],
[startTime, [\b_read, bufnum, audioPath, startTimeInFile * 48000, 32768, 0, 1]],
[startTime, (x = Synth.basicNew(\stream, server, nextNodeID)).newMsg(args: [buf: bufnum, out: speaker])],
[endTime, x.freeMsg]

(Of course I should have used an envelope instead of freeing the synth like this but the bits of the sound files are separated by silence and I was lazy…)


Is each not using a new bufnim? Or are you reusing the same buffer?

Josh Parmenter

I’m reusing the same four bufnums.

(edit: my purpose is, in this piece there will be thousands of buffer playback events, and I am trying to reduce this down to a manageable amount of VDiskIn buffers…)