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.
27 Note:: If the buffer has a larger number of frames than the sound file there will be a noticeable gap between the first and the following loop iterations. In that case chose a smaller buffer size or use link::Classes/PlayBuf##PlayBuf:: instead::
30 This UGen will set the link::Classes/Done##'done' flag:: when finished playing.
42 s.boot; // start the server
44 // examples below will use this synthdef
46 SynthDef("help-Diskin", { arg bufnum = 0;
47 Out.ar(0, DiskIn.ar(1, bufnum));
52 subsection:: Normal usage (with Buffer; "Object Style")
54 b = Buffer.cueSoundFile(s, Platform.resourceDir +/+ "sounds/a11wlk01-44_1.aiff", 0, 1);
56 x = { DiskIn.ar(1, b.bufnum) }.play;
61 // note the like named instance method, but different arguments
62 b.cueSoundFile(Platform.resourceDir +/+ "sounds/a11wlk01-44_1.aiff", 0);
64 x.free; b.close; b.free;
68 // loop it (for better looping use PlayBuf!)
70 p = Platform.resourceDir +/+ "sounds/a11wlk01-44_1.aiff";
73 d = a.numFrames/s.sampleRate; // get the duration
74 a.close; // don't forget
75 b = Buffer.cueSoundFile(s, p, 0, 1);
76 f = { DiskIn.ar(1, b.bufnum) };
79 loop({ d.wait; x.free; x = f.play; b.close( b.cueSoundFileMsg(p, 0)) });
81 r.stop; x.free; b.close; b.free; // you need to do all these to properly cleanup
85 // cue and play right away
87 SynthDef("help-Diskin", { arg bufnum = 0;
88 Out.ar(0, DiskIn.ar(1, bufnum));
92 x = Synth.basicNew("help-Diskin");
93 m = { arg buf; x.addToHeadMsg(nil, [\bufnum,buf.bufnum])};
95 b = Buffer.cueSoundFile(s,Platform.resourceDir +/+ "sounds/a11wlk01-44_1.aiff",0,1, completionMessage: m);
101 subsection:: OSC Messaging Style
103 // allocate a disk i/o buffer
104 s.sendMsg("/b_alloc", 0, 65536, 1);
106 // open an input file for this buffer, leave it open
107 s.sendMsg("/b_read", 0, Platform.resourceDir +/+ "sounds/a11wlk01-44_1.aiff", 0, 65536, 0, 1);
109 // create a diskin node
110 s.sendMsg("/s_new", "help-Diskin", x = s.nextNodeID, 1, 1);
112 s.sendMsg("/b_close", 0); // close the file (very important!)
116 // don't need to reallocate and Synth is still reading
117 s.sendMsg("/b_read", 0, Platform.resourceDir +/+ "sounds/a11wlk01-44_1.aiff", 0, 0, 0, 1);
119 s.sendMsg("/n_free", x); // stop reading
121 s.sendMsg("/b_close", 0); // close the file.
123 s.sendMsg("/b_free", 0); // frees the buffer