2 summary:: Stream in audio from a file.
3 related:: Classes/PlayBuf, Classes/DiskOut
4 categories:: UGens>InOut, UGens>Buffer
8 Continously play a longer soundfile from disk. This requires a buffer to
9 be preloaded with one buffer size of sound.
18 Number of channels. This must match the number of channels in the buffer.
22 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. ::
25 If set to 1, the soundfile will loop.
28 This UGen will set the link::Classes/Done##'done' flag:: when finished playing.
36 s.boot; // start the server
39 SynthDef("help-Diskin", { arg bufnum = 0;
40 Out.ar(0, DiskIn.ar(1, bufnum));
45 subsection:: OSC Messaging Style
47 // allocate a disk i/o buffer
48 s.sendMsg("/b_alloc", 0, 65536, 1);
50 // open an input file for this buffer, leave it open
51 s.sendMsg("/b_read", 0, Help.dir +/+ "sounds/a11wlk01-44_1.aiff", 0, 65536, 0, 1);
53 // create a diskin node
54 s.sendMsg("/s_new", "help-Diskin", x = s.nextNodeID, 1, 1);
56 s.sendMsg("/b_close", 0); // close the file (very important!)
60 // don't need to reallocate and Synth is still reading
61 s.sendMsg("/b_read", 0, Help.dir +/+ "sounds/a11wlk01-44_1.aiff", 0, 0, 0, 1);
63 s.sendMsg("/n_free", x); // stop reading
65 s.sendMsg("/b_close", 0); // close the file.
67 s.sendMsg("/b_free", 0); // frees the buffer
70 subsection:: Using Buffer (Object Style)
72 b = Buffer.cueSoundFile(s, Help.dir +/+ "sounds/a11wlk01-44_1.aiff", 0, 1);
74 x = { DiskIn.ar(1, b.bufnum) }.play;
79 // note the like named instance method, but different arguments
80 b.cueSoundFile(Help.dir +/+ "sounds/a11wlk01-44_1.aiff", 0);
82 x.free; b.close; b.free;
86 // loop it (for better looping use PlayBuf!)
88 p = Help.dir +/+ "sounds/a11wlk01-44_1.aiff";
91 d = a.numFrames/s.sampleRate; // get the duration
92 a.close; // don't forget
93 b = Buffer.cueSoundFile(s, p, 0, 1);
94 f = { DiskIn.ar(1, b.bufnum) };
97 loop({ d.wait; x.free; x = f.play; b.close( b.cueSoundFileMsg(p, 0)) });
99 r.stop; x.free; b.close; b.free; // you need to do all these to properly cleanup
103 // cue and play right away
105 SynthDef("help-Diskin", { arg bufnum = 0;
106 Out.ar(0, DiskIn.ar(1, bufnum));
110 x = Synth.basicNew("help-Diskin");
111 m = { arg buf; x.addToHeadMsg(nil, [\bufnum,buf.bufnum])};
113 b = Buffer.cueSoundFile(s,Help.dir +/+ "sounds/a11wlk01-44_1.aiff",0,1, completionMessage: m);