2 summary:: Stream in audio from a file, with variable rate
3 categories:: UGens>InOut, UGens>Buffer
4 related:: Classes/PlayBuf, Classes/BufRd, Classes/DiskIn
7 Continuously play a longer soundfile from disk. This requires a buffer to be preloaded with one buffer size of sound.
12 argument:: numChannels
17 Note:: The Buffer's numFrames must be a power of two and is recommended to be at least 65536 -- preferably 131072 or 262144. Smaller buffer sizes mean more frequent disk access, which can cause glitches. ::
20 controls the rate of playback. Values below 4 are probably fine, but the higher the value, the more disk activity there is, and the more likelihood there will be a problem.
23 the rate does have a practical limit. The following must be true: rate < Buffer's size / ( 2 * s.options.blockSize) e.g with typical default values, this wil be 32768 / (2 * 64) = 256.
26 If the rate is too high, the UGen will not execute, posting a warning.
29 If loop is set to 1, the soundfile will loop.
32 If a sendID is given, the UGen sends an osc message with this id and the file position each time it reloads the buffer: code::['/diskin', nodeID, sendID, frame]::
35 This UGen will set the link::Classes/Done##'done' flag:: when finished playing.
39 b = Buffer.cueSoundFile(s, Help.dir +/+ "sounds/a11wlk01-44_1.aiff", 0, 1);
41 x = { VDiskIn.ar(1, b, LFNoise2.kr(0.2).range(0.5, 2), 1, loop:1) }.play;
46 // note the like named instance method, but different arguments
47 b.cueSoundFile(Help.dir +/+ "sounds/a11wlk01-44_1.aiff", 0);
49 x.free; b.close; b.free;
52 // cue and play right away
54 SynthDef("help-VDiskin", { arg bufnum = 0;
55 Out.ar(0, VDiskIn.ar(1, bufnum, MouseX.kr(0.5, 2.0)));
59 x = Synth.basicNew("help-VDiskin");
60 m = { arg buf; x.addToHeadMsg(nil, [\bufnum, buf])};
62 b = Buffer.cueSoundFile(s,Help.dir +/+ "sounds/a11wlk01-44_1.aiff",0,1, completionMessage: m);
65 x.free; b.close; b.free; // clean up
69 // sending back the file position.
71 // the ugen knows nothing of the loop (apply a modulo).
72 // if you load another file, you need to free the buffer and re-allocate it (see below)
74 b = Buffer.cueSoundFile(s, Help.dir +/+ "sounds/a11wlk01-44_1.aiff", 0, 1, bufferSize: 4096);
75 c = SoundFile(Help.dir +/+ "sounds/a11wlk01-44_1.aiff").info;
76 x = { VDiskIn.ar(1, b, LFNoise2.kr(0.2).range(0.2, 0.9), 1, sendID: 14) }.play;
78 // register to receive this message
81 o = OSCFunc({ arg msg;
85 "id: % pos: % frames (% sec)\n"
86 .postf(sendID, index % c.numFrames, (index % c.numFrames / c.sampleRate));
92 b.alloc; b.cueSoundFile(Help.dir +/+ "sounds/a11wlk01-44_1.aiff", 0); c = SoundFile(Help.dir +/+ "sounds/a11wlk01-44_1.aiff").info;
94 x.free; b.close; b.free; o.free; // clean up eventually
98 // the same example in OSC Messaging style, see link::Guides/NodeMessaging::
100 // allocate a disk i/o buffer
101 s.sendMsg("/b_alloc", 0, 65536, 1);
103 // open an input file for this buffer, leave it open
104 s.sendMsg("/b_read", 0, Help.dir +/+ "sounds/a11wlk01-44_1.aiff", 0, 65536, 0, 1);
106 // create a diskin node
107 s.sendMsg("/s_new", "help-VDiskin", x = s.nextNodeID, 1, 1);
109 s.sendMsg("/b_close", 0); // close the file (very important!)
113 // don't need to reallocate and Synth is still reading
114 s.sendMsg("/b_read", 0, Help.dir +/+ "sounds/a11wlk01-44_1.aiff", 0, 0, 0, 1);
116 s.sendMsg("/n_free", x); // stop reading
118 s.sendMsg("/b_close", 0); // close the file.
120 s.sendMsg("/b_free", 0); // frees the buffer