supernova: fixes for boost-1.49 and gcc-4.7
[supercollider.git] / Help / ServerArchitecture / Buffer.html
blob58fd531db0ac9330ec7e11d58e60c26ef5ebb3ec
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="1038.32">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica; min-height: 17.0px}
14 p.p5 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 12.0px Helvetica}
15 p.p6 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 12.0px Helvetica; min-height: 14.0px}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
18 p.p9 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco; min-height: 12.0px}
19 p.p10 {margin: 0.0px 0.0px 0.0px 56.0px; text-indent: -56.0px; font: 12.0px Helvetica}
20 p.p11 {margin: 0.0px 0.0px 0.0px 85.0px; text-indent: -85.0px; font: 12.0px Helvetica}
21 p.p12 {margin: 0.0px 0.0px 0.0px 85.0px; text-indent: -85.0px; font: 12.0px Helvetica; min-height: 14.0px}
22 p.p13 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco; color: #941f1a}
23 p.p14 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco}
24 p.p15 {margin: 0.0px 0.0px 0.0px 56.0px; text-indent: -56.0px; font: 12.0px Helvetica; min-height: 14.0px}
25 p.p16 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #941f1a}
26 p.p17 {margin: 0.0px 0.0px 0.0px 56.0px; text-indent: -56.0px; font: 9.0px Monaco}
27 p.p18 {margin: 0.0px 0.0px 0.0px 85.0px; text-indent: -85.0px; font: 9.0px Monaco; min-height: 12.0px}
28 p.p19 {margin: 0.0px 0.0px 0.0px 85.0px; text-indent: -85.0px; font: 9.0px Monaco; color: #941f1a}
29 p.p20 {margin: 0.0px 0.0px 0.0px 85.0px; text-indent: -85.0px; font: 9.0px Monaco}
30 p.p21 {margin: 0.0px 0.0px 0.0px 85.0px; text-indent: -85.0px; font: 9.0px Monaco; color: #606060}
31 p.p22 {margin: 0.0px 0.0px 0.0px 85.0px; text-indent: -85.0px; font: 9.0px Monaco; color: #426d24}
32 p.p23 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #606060}
33 span.s1 {font: 18.0px Helvetica}
34 span.s2 {color: #0b24ae}
35 span.s3 {color: #001ff0}
36 span.s4 {font: 12.0px Helvetica}
37 span.s5 {color: #000000}
38 span.s6 {color: #941f1a}
39 span.s7 {font: 9.0px Monaco}
40 span.s8 {color: #426d24}
41 span.s9 {color: #606060}
42 span.s10 {font: 12.0px Helvetica; color: #000000}
43 span.Apple-tab-span {white-space:pre}
44 </style>
45 </head>
46 <body>
47 <p class="p1"><span class="s1"><b>Buffer<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b></span><b>client-side representation of a buffer on a server</b></p>
48 <p class="p2"><br></p>
49 <p class="p1"><b>superclass: Object</b></p>
50 <p class="p2"><br></p>
51 <p class="p1">A buffer is most often used to hold sampled audio, such as a soundfile loaded into memory, but can be used to hold other types of data as well. It is a globally available array of floating-point numbers on the server. The Buffer class encapsulates a number of common tasks, OSC messages, and capabilities related to server-side buffers – see the examples lower down this document for many examples of using Buffers for sound playback and recording.</p>
52 <p class="p2"><br></p>
53 <p class="p1">Buffers are commonly used with <a href="../UGens/Playback and Recording/PlayBuf.html"><span class="s2">PlayBuf</span></a>, <a href="../UGens/Playback and Recording/RecordBuf.html"><span class="s2">RecordBuf</span></a>, <a href="../UGens/Playback and Recording/DiskIn.html"><span class="s2">DiskIn</span></a>, <a href="../UGens/Playback and Recording/DiskOut.html"><span class="s2">DiskOut</span></a>, <a href="../UGens/Oscillators/BufWr.html"><span class="s2">BufWr</span></a>, <a href="../UGens/Oscillators/BufRd.html"><span class="s2">BufRd</span></a>, and other <a href="../UGens/UGen.html"><span class="s2">UGens</span></a>. (See their individual help files for more examples.) Buffers can be freed or altered even while being accessed. See <a href="Server-Architecture.html"><span class="s2">Server-Architecture</span></a> for some technical details.</p>
54 <p class="p2"><br></p>
55 <p class="p1">Buffer objects should not be created or modified within a <a href="SynthDef.html"><span class="s3">SynthDef</span></a>. If this is needed, see <a href="../UGens/InOut/LocalBuf.html"><span class="s3">LocalBuf</span></a>.</p>
56 <p class="p2"><br></p>
57 <p class="p3"><b>Buffer Numbers and Allocation</b></p>
58 <p class="p2"><br></p>
59 <p class="p1">Although the number of buffers on a server is set at the time it is booted, memory must still be allocated within the server app before they can hold values. (At boot time all buffers have a size of 0.)<span class="Apple-converted-space"> </span></p>
60 <p class="p2"><br></p>
61 <p class="p1">Server-side buffers are identified by number, starting from 0. When using Buffer objects, buffer numbers are automatically allocated from the Server's bufferAllocator, unless you explicitly supply one. When you call <b>.free</b> on a Buffer object it will release the buffer's memory on the server, and free the buffer number for future reallocation. See <a href="ServerOptions.html"><span class="s2">ServerOptions</span></a> for details on setting the number of available buffers.</p>
62 <p class="p2"><br></p>
63 <p class="p1">Normally you should not need to supply a buffer number. You should only do so if you are sure you know what you are doing. Similarly, in normal use you should not need to access the buffer number, since instances of Buffer can be used directly as UGen inputs or Synth args.</p>
64 <p class="p2"><br></p>
65 <p class="p3"><b>Multichannel Buffers</b></p>
66 <p class="p2"><br></p>
67 <p class="p1">Multichannel buffers interleave their data. Thus the actual number of available values when requesting or setting values by index using methods such as set, setn, get, getn, etc., is equal to numFrames * numChannels. Indices start at 0 and go up to (numFrames * numChannels) - 1. In a two channel buffer for instance, index 0 will be the first value of the first channel, index 1 will be the first value of the second channel, index 2 will be the second value of the first channel, and so on.</p>
68 <p class="p2"><br></p>
69 <p class="p1">In some cases it is simpler to use multiple single channel buffers instead of a single multichannel one.</p>
70 <p class="p2"><br></p>
71 <p class="p3"><b>Completion Messages and Action Functions</b></p>
72 <p class="p2"><br></p>
73 <p class="p1">Many buffer operations (such as reading and writing files) are asynchronous, meaning that they will take an arbitrary amount of time to complete. Asynchronous commands are passed to a background thread on the server so as not to steal CPU time from the audio synthesis thread. Since they can last an aribitrary amount of time it is convenient to be able to specify something else that can be done immediately on completion. The ability to do this is implemented in two ways in Buffer's various methods: completion messages and action functions.<span class="Apple-converted-space"> </span></p>
74 <p class="p2"><br></p>
75 <p class="p1">A completion message is a second OSC command which is included in the message which is sent to the server. (See <a href="NodeMessaging.html"><span class="s2">NodeMessaging</span></a> for a discussion of OSC messages.) The server will execute this immediately upon completing the first command. An action function is a <a href="../Core/Kernel/Function.html"><span class="s2">Function</span></a> which will be evaluated when the client receives the appropriate reply from the server, indicating that the previous command is done. Action functions are therefore inherently more flexible than completion messages, but slightly less efficient due to the small amount of added latency involved in message traffic. Action functions are passed the Buffer object as an argument when they are evaluated.</p>
76 <p class="p2"><br></p>
77 <p class="p1">With Buffer methods that take a completion message, it is also possible to pass in a function that returns an OSC message. As in action functions this will be passed the Buffer as an argument. It is important to understand however that this function will be evaluated after the Buffer object has been created (so that its bufnum and other details are accessible), but <i>before</i> the corresponding message is sent to the server.</p>
78 <p class="p2"><br></p>
79 <p class="p3"><b>Bundling</b></p>
80 <p class="p2"><br></p>
81 <p class="p1">Many of the methods below have two versions: a regular one which sends its corresponding message to the server immediately, and one which returns the message in an <a href="../Collections/Array.html"><span class="s2">Array</span></a> so that it can be added to a bundle. It is also possible to capture the messages generated by the regular methods using Server's automated bundling capabilities. See <a href="Server.html"><span class="s2">Server</span></a> and <a href="bundledCommands.html"><span class="s2">bundledCommands</span></a> for more details.</p>
82 <p class="p4"><br></p>
83 <p class="p3"><b>Accessing Instance Variables</b></p>
84 <p class="p2"><br></p>
85 <p class="p5">The following variables have getter methods.</p>
86 <p class="p6"><br></p>
87 <p class="p5"><span class="Apple-tab-span"> </span><b>server</b> - Returns the Buffer's <a href="Server.html"><span class="s2">Server</span></a> object.</p>
88 <p class="p6"><span class="Apple-tab-span"> </span></p>
89 <p class="p5"><span class="Apple-tab-span"> </span><b>bufnum</b> - Returns the buffer number of the corresponding server-side buffer. In normal use you should not need to access this value, since instances of Buffer can be used directly as UGen inputs or Synth args.</p>
90 <p class="p6"><br></p>
91 <p class="p5"><span class="Apple-tab-span"> </span><b>numFrames</b> - Returns the number of sample frames in the corresponding server-side buffer. Note that multichannel buffers interleave their samples, so when dealing with indices in methods like get and getn, the actual number of available values is numFrames * numChannels.</p>
92 <p class="p6"><span class="Apple-tab-span"> </span></p>
93 <p class="p5"><span class="Apple-tab-span"> </span><b>numChannels</b> - Returns the number of channels in the corresponding server-side buffer.<span class="Apple-converted-space"> </span></p>
94 <p class="p6"><span class="Apple-tab-span"> </span></p>
95 <p class="p5"><span class="Apple-tab-span"> </span><b>sampleRate</b> - Returns the sample rate of the corresponding server-side buffer.</p>
96 <p class="p6"><span class="Apple-tab-span"> </span></p>
97 <p class="p5"><span class="Apple-tab-span"> </span><b>path</b> - Returns a string containing the path of a soundfile that has been loaded into the corresponding server-side buffer.</p>
98 <p class="p2"><span class="Apple-tab-span"> </span></p>
99 <p class="p7"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>s.boot;</p>
100 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.alloc(s,44100 * 8.0,2);</p>
101 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.bufnum.postln;</p>
102 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.free;</p>
103 <p class="p8"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
104 <p class="p3"><b>Creation with Immediate Memory Allocation</b></p>
105 <p class="p8"><span class="Apple-tab-span"> </span></p>
106 <p class="p8"><br></p>
107 <p class="p5"><b><span class="Apple-tab-span"> </span>*alloc(server, numFrames, numChannels, completionMessage, bufnum)</b></p>
108 <p class="p9"><span class="Apple-tab-span"> </span></p>
109 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Create and return a Buffer and immediately allocate the required memory on the server. The buffer's values will be initialised to 0.0.</p>
110 <p class="p6"><span class="Apple-tab-span"> </span></p>
111 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>server<span class="Apple-converted-space"> </span></b> - The server on which to allocate the buffer. The default is the default <a href="Server.html"><span class="s2">Server</span></a>.</p>
112 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>numFrames </b>- The number of frames to allocate. Actual memory use will correspond to numFrames * numChannels.</p>
113 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>numChannels</b> - The number of channels for the Buffer. The default is 1.</p>
114 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>completionMessage </b>- A valid OSC message or a <a href="../Core/Kernel/Function.html"><span class="s2">Function</span></a> which will return one. A Function will be passed this Buffer as an argument when evaluated.</p>
115 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>bufnum</b> - An explicitly specified buffer number. Generally this is not needed.</p>
116 <p class="p12"><span class="Apple-tab-span"> </span></p>
117 <p class="p13"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// Allocate 8 second stereo buffer</p>
118 <p class="p14"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>s.boot;</p>
119 <p class="p14"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.alloc(s, s.sampleRate * 8.0, 2);</p>
120 <p class="p14"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.free;</p>
121 <p class="p9"><span class="Apple-tab-span"> </span></p>
122 <p class="p10"><span class="Apple-tab-span"> </span>*<b>allocConsecutive(numBufs, server, numFrames, numChannels, completionMessage, bufnum)<span class="Apple-converted-space"> </span></b></p>
123 <p class="p15"><br></p>
124 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Allocates a range of consecutively-numbered buffers, for use with UGens like <a href="../UGens/Oscillators/VOsc.html"><span class="s2">VOsc</span></a> and <a href="../UGens/Oscillators/VOsc3.html"><span class="s2">VOsc3</span></a><b> </b>that require a contiguous block of buffers, and returns an array of corresponding Buffer objects.</p>
125 <p class="p15"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
126 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>numBufs</b> - The number of consecutively indexed buffers to allocate.</p>
127 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>server<span class="Apple-converted-space"> </span></b> - The server on which to allocate the buffers. The default is the default <a href="Server.html"><span class="s2">Server</span></a>.</p>
128 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>numFrames </b>- The number of frames to allocate in each buffer. Actual memory use will correspond to numFrames * numChannels.</p>
129 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>numChannels</b> - The number of channels for each buffer. The default is 1.</p>
130 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>completionMessage </b>- A valid OSC message or a <a href="../Core/Kernel/Function.html"><span class="s2">Function</span></a> which will return one. A Function will be passed each Buffer and its index in the array as arguments when evaluated.</p>
131 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>bufnum</b> - An explicitly specified buffer number for the initial buffer. Generally this is not needed.</p>
132 <p class="p15"><br></p>
133 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>N.B.</b> You must treat the array of Buffers as a group. Freeing them individually or resuing them can result in allocation errors. You should free all Buffers in the array at the same time by iterating over it with <b>do</b>.</p>
134 <p class="p8"><br></p>
135 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>s.boot;</p>
136 <p class="p16"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// allocate an array of Buffers and fill them with different harmonics</p>
137 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
138 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.allocConsecutive(8, s, 4096, 1, { <span class="s2">|buf, i|</span></p>
139 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>buf.sine1Msg((1..((i+1)*6)).reciprocal) <span class="s6">// completion Messages</span></p>
140 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>});</p>
141 <p class="p8"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
142 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>a = { <span class="s2">VOsc</span>.ar(<span class="s2">SinOsc</span>.kr(0.5, 0).range(b.first.bufnum + 0.1, b.last.bufnum - 0.1),</p>
143 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>[440, 441], 0, 0.2) }.play;</p>
144 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
145 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>a.free;<span class="Apple-converted-space"> </span></p>
146 <p class="p8"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
147 <p class="p16"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// iterate over the array and free it</p>
148 <p class="p17"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>b.do(<span class="s2">_</span>.free);</p>
149 <p class="p15"><br></p>
150 <p class="p10"><span class="s7"><span class="Apple-tab-span"> </span></span><b>*read(server, path, startFrame, numFrames, action, bufnum)</b></p>
151 <p class="p6"><br></p>
152 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Allocate a buffer and immediately read a soundfile into it. This method sends a query message as a completion message so that the Buffer's instance variables will be updated automatically. <b>N.B.</b> You cannot rely on the buffer's instance variables being instantly updated, as there is a small amount of latency involved. <b>action</b> will be evaluated upon receipt of the reply to the query, so use this in cases where access to instance variables is needed.</p>
153 <p class="p12"><span class="Apple-tab-span"> </span></p>
154 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>server<span class="Apple-converted-space"> </span></b> - The server on which to allocate the buffer.</p>
155 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>path</b> - A <b>String</b> representing the path of the soundfile to be read.</p>
156 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>startFrame</b> - The first frame of the soundfile to read. The default is 0, which is the beginning of the file.</p>
157 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>numFrames </b>- The number of frames to read. The default is -1, which will read the whole file.</p>
158 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>action</b> - A <b>Function</b> to be evaluated once the file has been read and this Buffer's instance variables have been updated. The function will be passed this Buffer as an argument.</p>
159 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>bufnum</b> - An explicitly specified buffer number. Generally this is not needed.</p>
160 <p class="p18"><span class="Apple-tab-span"> </span></p>
161 <p class="p19"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// read a soundfile</p>
162 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>s.boot;</p>
163 <p class="p21"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = </span><span class="s2">Buffer</span><span class="s5">.read(s, </span>"sounds/a11wlk01.wav"<span class="s5">);</span></p>
164 <p class="p18"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
165 <p class="p19"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// now play it</p>
166 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
167 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x = <span class="s2">SynthDef</span>(<span class="s8">\help_Buffer</span>, { <span class="s2">arg</span> out = 0, bufnum;</p>
168 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">Out</span>.ar( out,</p>
169 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">PlayBuf</span>.ar(1, bufnum, <span class="s2">BufRateScale</span>.kr(bufnum))</p>
170 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
171 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>}).play(s,[<span class="s8">\bufnum</span>, b]);</p>
172 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
173 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.free; b.free;</p>
174 <p class="p18"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
175 <p class="p19"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// with an action function</p>
176 <p class="p19"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// note that the vars are not immediately up-to-date</p>
177 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
178 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.read(s, <span class="s9">"sounds/a11wlk01.wav"</span>, action: { <span class="s2">arg</span> buffer;<span class="Apple-converted-space"> </span></p>
179 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(<span class="s9">"After update:"</span> + buffer.numFrames).postln;</p>
180 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x = { <span class="s2">PlayBuf</span>.ar(1, buffer, <span class="s2">BufRateScale</span>.kr(buffer)) }.play;</p>
181 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>});</p>
182 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(<span class="s9">"Before update:"</span> + b.numFrames).postln;</p>
183 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
184 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.free; b.free;</p>
185 <p class="p18"><br></p>
186 <p class="p10"><span class="s7"><span class="Apple-tab-span"> </span></span><b>*readChannel(server, path, startFrame, numFrames, channels, action, bufnum)</b></p>
187 <p class="p6"><br></p>
188 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>As <b>*read</b> above, but takes an Array of channel indices to read in, allowing one to read only the selected channels.</p>
189 <p class="p12"><span class="Apple-tab-span"> </span></p>
190 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>server<span class="Apple-converted-space"> </span></b> - The server on which to allocate the buffer.</p>
191 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>path</b> - A <b>String</b> representing the path of the soundfile to be read.</p>
192 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>startFrame</b> - The first frame of the soundfile to read. The default is 0, which is the beginning of the file.</p>
193 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>numFrames </b>- The number of frames to read. The default is -1, which will read the whole file.</p>
194 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>channels</b> - An <b>Array</b> of channels to be read from the soundfile. Indices start from zero. These will be read in the order provided.</p>
195 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>action</b> - A <b>Function</b> to be evaluated once the file has been read and this Buffer's instance variables have been updated. The function will be passed this Buffer as an argument.</p>
196 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>bufnum</b> - An explicitly specified buffer number. Generally this is not needed.</p>
197 <p class="p18"><span class="Apple-tab-span"> </span></p>
198 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>s.boot;</p>
199 <p class="p19"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// first a standard read so we can see what's in the file</p>
200 <p class="p21"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = </span><span class="s2">Buffer</span><span class="s5">.read(s, </span>"sounds/SinedPink.aiff"<span class="s5">);</span></p>
201 <p class="p19"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// "sounds/SinedPink.aiff" contains SinOsc on left, PinkNoise on right</p>
202 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.plot;</p>
203 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.free;</p>
204 <p class="p18"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
205 <p class="p19"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// Now just the sine</p>
206 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.readChannel(s, <span class="s9">"sounds/SinedPink.aiff"</span>, channels: [0]);</p>
207 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.plot;</p>
208 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.free;</p>
209 <p class="p18"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
210 <p class="p19"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// Now just the pink noise</p>
211 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.readChannel(s, <span class="s9">"sounds/SinedPink.aiff"</span>, channels: [1]);</p>
212 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.plot;</p>
213 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.free;</p>
214 <p class="p18"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
215 <p class="p19"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// Now reverse channel order</p>
216 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.readChannel(s, <span class="s9">"sounds/SinedPink.aiff"</span>, channels: [1, 0]);</p>
217 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.plot;</p>
218 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.free;</p>
219 <p class="p18"><br></p>
220 <p class="p5"><span class="s7"><span class="Apple-tab-span"> </span></span><b>*readNoUpdate(server, path, startFrame, numFrames, completionMessage, bufnum)</b></p>
221 <p class="p6"><br></p>
222 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>As <b>*read</b> above, but without the automatic update of instance variables. Call <b>updateInfo </b>(see below) to update the vars.</p>
223 <p class="p12"><span class="Apple-tab-span"> </span></p>
224 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>server<span class="Apple-converted-space"> </span></b> - The server on which to allocate the buffer.</p>
225 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>path</b> - A <b>String</b> representing the path of the soundfile to be read.</p>
226 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>startFrame</b> - The first frame of the soundfile to read. The default is 0, which is the beginning of the file.</p>
227 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>numFrames </b>- The number of frames to read. The default is -1, which will read the whole file.</p>
228 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>completionMessage </b>- A valid OSC message or a <a href="../Core/Kernel/Function.html"><span class="s2">Function</span></a> which will return one. A Function will be passed this Buffer as an argument when evaluated.</p>
229 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>bufnum</b> - An explicitly specified buffer number. Generally this is not needed.</p>
230 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
231 <p class="p19"><span class="s10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// with a completion message<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
232 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>s.boot;</p>
233 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
234 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">SynthDef</span>(<span class="s8">\help_Buffer</span>,{ <span class="s2">arg</span> out=0, bufnum;</p>
235 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">Out</span>.ar( out,</p>
236 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">PlayBuf</span>.ar(1,bufnum,<span class="s2">BufRateScale</span>.kr(bufnum))</p>
237 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
238 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>}).add;</p>
239 <p class="p18"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
240 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>y = <span class="s2">Synth</span>.basicNew(<span class="s8">\help_Buffer</span>); <span class="s6">// not sent yet</span></p>
241 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.readNoUpdate(s,<span class="s9">"sounds/a11wlk01.wav"</span>,<span class="Apple-converted-space"> </span></p>
242 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>completionMessage: { <span class="s2">arg</span> buffer;</p>
243 <p class="p19"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// synth add its s_new msg to follow<span class="Apple-converted-space"> </span></p>
244 <p class="p19"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// after the buffer read completes</p>
245 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>y.newMsg(s,[<span class="s8">\bufnum</span>, buffer],<span class="s8">\addToTail</span>)</p>
246 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>});</p>
247 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
248 <p class="p19"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// note vars not accurate</p>
249 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.numFrames; <span class="s6">// nil</span></p>
250 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.updateInfo;</p>
251 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.numFrames; <span class="s6">// 188893</span></p>
252 <p class="p19"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// when done...</p>
253 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>y.free;</p>
254 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.free;<span class="Apple-tab-span"> </span></p>
255 <p class="p18"><span class="Apple-tab-span"> </span></p>
256 <p class="p11"><b><span class="Apple-tab-span"> </span>*cueSoundFile(server, path, startFrame, numChannels, bufferSize, completionMessage)</b></p>
257 <p class="p12"><span class="Apple-tab-span"> </span></p>
258 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Allocate a buffer and preload a soundfile for streaming in using <a href="../UGens/Playback and Recording/DiskIn.html"><span class="s2">DiskIn</span></a>.</p>
259 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
260 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>server<span class="Apple-converted-space"> </span></b> - The server on which to allocate the buffer.</p>
261 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>path</b> - A <b>String</b> representing the path of the soundfile to be read.</p>
262 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>startFrame</b> - The frame of the soundfile that <a href="../UGens/Playback and Recording/DiskIn.html"><span class="s2">DiskIn</span></a> will start playing at.</p>
263 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>numChannels</b> - The number of channels in the soundfile.</p>
264 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>bufferSize</b> - This must be a multiple of<span class="Apple-converted-space">  </span>(2 * the server's block size). 32768 is the default and is suitable for most cases.</p>
265 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>completionMessage </b>- A valid OSC message or a <a href="../Core/Kernel/Function.html"><span class="s2">Function</span></a> which will return one. A Function will be passed this Buffer as an argument when evaluated.</p>
266 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
267 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>s.boot;</p>
268 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
269 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">SynthDef</span>(<span class="s8">\help_Buffer_cue</span>,{ <span class="s2">arg</span> out=0,bufnum;</p>
270 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">Out</span>.ar(out,</p>
271 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">DiskIn</span>.ar( 1, bufnum )</p>
272 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
273 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>}).add;</p>
274 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
275 <p class="p18"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
276 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
277 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>s.makeBundle(<span class="s2">nil</span>, {</p>
278 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.cueSoundFile(s,<span class="s9">"sounds/a11wlk01-44_1.aiff"</span>, 0, 1);</p>
279 <p class="p22"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>y = </span><span class="s2">Synth</span><span class="s5">(</span>\help_Buffer_cue<span class="s5">, [</span>\bufnum<span class="s5">, b], s);</span></p>
280 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>});</p>
281 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
282 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.free; y.free;</p>
283 <p class="p18"><br></p>
284 <p class="p5"><span class="s7"><span class="Apple-tab-span"> </span></span><b>*loadCollection(server, collection, numChannels, action)</b></p>
285 <p class="p6"><br></p>
286 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Load a large collection into a buffer on the server. Returns a Buffer object. This is accomplished through writing the collection to a <a href="../Files/SoundFile.html"><span class="s2">SoundFile</span></a> and loading it from there. For this reason this method will only work with a server on your local machine. For a remote server use <b>*sendCollection</b>, below. The file is automatically deleted after loading. This allows for larger collections than <b>setn</b>, below, and is in general the safest way to get a large collection into a buffer. The sample rate of the buffer will be the sample rate of the server on which it is created.</p>
287 <p class="p12"><span class="Apple-tab-span"> </span></p>
288 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>server<span class="Apple-converted-space"> </span></b> - The server on which to create the buffer.</p>
289 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>collection</b> - A subclass of <a href="../Collections/Collection.html"><span class="s2">Collection</span></a> (i.e. an <a href="../Collections/Array.html"><span class="s2">Array</span></a>) containing <i>only</i> floats and integers. Multi-dimensional arrays will not work.</p>
290 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>numChannels </b>- The number of channels that the buffer should have. Note that buffers interleave multichannel data. You are responsible for providing an interleaved collection if needed. Multi-dimensional arrays will not work.</p>
291 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>action</b> - A <b>Function</b> to be evaluated once the file has been read and this Buffer's instance variables have been updated. The function will be passed this Buffer as an argument.</p>
292 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
293 <p class="p20"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>s.boot;</p>
294 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
295 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>a = <span class="s2">FloatArray</span>.fill(44100 * 5.0, {1.0.rand2}); <span class="s6">// 5 seconds of noise</span></p>
296 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.loadCollection(s, a);</p>
297 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
298 <p class="p8"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
299 <p class="p16"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// test it</p>
300 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.get(20000,{<span class="s2">|msg|</span> (msg == a[20000]).postln});</p>
301 <p class="p16"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// play it</p>
302 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x = { <span class="s2">PlayBuf</span>.ar(1, b, <span class="s2">BufRateScale</span>.kr(b), loop: 0) * 0.5 }.play;</p>
303 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.free; x.free;</p>
304 <p class="p8"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
305 <p class="p16"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// interleave a multi-dimensional array</p>
306 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
307 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>l = <span class="s2">Signal</span>.sineFill(16384, <span class="s2">Array</span>.fill(200, {0}).add(1));</p>
308 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>r = <span class="s2">Array</span>.fill(16384, {1.0.rand2});</p>
309 <p class="p16"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>m = [</span><span class="s2">Array</span><span class="s5">.newFrom(l), r]; </span>// a multi-dimensional array</p>
310 <p class="p16"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>m = m.lace(32768); </span>// interleave the two collections<span class="Apple-converted-space"> </span></p>
311 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.loadCollection(s, m, 2, {<span class="s2">|buf|</span></p>
312 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x = { <span class="s2">PlayBuf</span>.ar(2, buf, <span class="s2">BufRateScale</span>.kr(buf), loop: 1) * 0.5 }.play;</p>
313 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>});</p>
314 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
315 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.plot;</p>
316 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.free; b.free;</p>
317 <p class="p8"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
318 <p class="p5"><span class="s7"><span class="Apple-tab-span"> </span></span><b>*sendCollection(server, collection, numChannels, wait, action)</b></p>
319 <p class="p6"><br></p>
320 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Stream a large collection into a buffer on the server using multiple <b>setn</b> messages. Returns a Buffer object. This allows for larger collections than <b>setn</b>, below. This is not as safe as <b>*loadCollection</b>, above, but will work with servers on remote machines. The sample rate of the buffer will be the sample rate of the server on which it is created.</p>
321 <p class="p12"><span class="Apple-tab-span"> </span></p>
322 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>server<span class="Apple-converted-space"> </span></b> - The server on which to create the buffer.</p>
323 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>collection</b> - A subclass of <a href="../Collections/Collection.html"><span class="s2">Collection</span></a> (i.e. an <a href="../Collections/Array.html"><span class="s2">Array</span></a>) containing <i>only</i> floats and integers. Multi-dimensional arrays will not work.</p>
324 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>numChannels </b>- The number of channels that the buffer should have. Note that buffers interleave multichannel data. You are responsible for providing an interleaved collection if needed. Multi-dimensional arrays will not work. See the example in <b>*loadCollection</b>, above, to see how to do this.</p>
325 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>wait</b> - An optional wait time between sending <b>setn</b> messages. In a high traffic situation it may be safer to set this to something above zero, which is the default.</p>
326 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>action</b> - A <a href="../Core/Kernel/Function.html"><span class="s2">Function</span></a> to be evaluated once the file has been read and this Buffer's instance variables have been updated. The function will be passed this Buffer as an argument.</p>
327 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
328 <p class="p20"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>s.boot;</p>
329 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
330 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>a = <span class="s2">Array</span>.fill(2000000,{ rrand(0.0,1.0) }); <span class="s6">// a LARGE collection</span></p>
331 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.sendCollection(s, a, 1, 0, {<span class="s2">arg</span> buf; <span class="s9">"finished"</span>.postln;});</p>
332 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
333 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.get(1999999, {<span class="s2">|msg|</span> (msg == a[1999999]).postln});</p>
334 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.free;</p>
335 <p class="p8"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
336 <p class="p11"><span class="s7"><span class="Apple-tab-span"> </span></span><b>*loadDialog(server, startFrame, numFrames, action, bufnum)</b></p>
337 <p class="p6"><br></p>
338 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>As <b>*read</b> above, but gives you a load dialog window to browse for a file. Cocoa and SwingOSC compatible.</p>
339 <p class="p12"><span class="Apple-tab-span"> </span></p>
340 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>server<span class="Apple-converted-space"> </span></b> - The server on which to allocate the buffer.</p>
341 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>startFrame</b> - The first frame of the soundfile to read. The default is 0, which is the beginning of the file.</p>
342 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>numFrames </b>- The number of frames to read. The default is -1, which will read the whole file.</p>
343 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>action</b> - A <b>Function</b> to be evaluated once the file has been read and this Buffer's instance variables have been updated. The function will be passed this Buffer as an argument.</p>
344 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>bufnum</b> - An explicitly specified buffer number. Generally this is not needed.</p>
345 <p class="p12"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b></p>
346 <p class="p20"><span class="s4"><b><span class="Apple-tab-span"> </span></b></span><span class="Apple-tab-span"> </span>s.boot;</p>
347 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
348 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.loadDialog(s, action: { <span class="s2">arg</span> buffer;<span class="Apple-converted-space"> </span></p>
349 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x = { <span class="s2">PlayBuf</span>.ar(buffer.numChannels, buffer, <span class="s2">BufRateScale</span>.kr(buffer)) }.play;</p>
350 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>});</p>
351 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
352 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.free; b.free;</p>
353 <p class="p12"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b></p>
354 <p class="p3"><b>Creation without Immediate Memory Allocation</b></p>
355 <p class="p4"><br></p>
356 <p class="p11"><b><span class="Apple-tab-span"> </span>*new(server, numFrames, numChannels, bufnum)</b></p>
357 <p class="p18"><span class="Apple-tab-span"> </span></p>
358 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Create and return a new Buffer object, without immediately allocating the corresponding memory on the server. This combined with 'message' methods can be flexible with bundles.</p>
359 <p class="p12"><span class="Apple-tab-span"> </span></p>
360 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>server<span class="Apple-converted-space"> </span></b> - The server on which to allocate the buffer. The default is the default <a href="Server.html"><span class="s2">Server</span></a>.</p>
361 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>numFrames </b>- The number of frames to allocate. Actual memory use will correspond to numFrames * numChannels.</p>
362 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>numChannels</b> - The number of channels for the Buffer. The default is 1.</p>
363 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>bufnum</b> - An explicitly specified buffer number. Generally this is not needed.</p>
364 <p class="p18"><span class="Apple-tab-span"> </span></p>
365 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>s.boot;</p>
366 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.new(s, 44100 * 8.0, 2);</p>
367 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>c = <span class="s2">Buffer</span>.new(s, 44100 * 4.0, 2);</p>
368 <p class="p19"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.query; </span>// numFrames = 0</p>
369 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>s.sendBundle(<span class="s2">nil</span>, b.allocMsg, c.allocMsg); <span class="s6">// sent both at the same time</span></p>
370 <p class="p19"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.query; </span>// now it's right</p>
371 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>c.query;</p>
372 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.free; c.free;</p>
373 <p class="p2"><span class="Apple-tab-span"> </span></p>
374 <p class="p1"><span class="Apple-tab-span"> </span><b>alloc(completionMessage)</b></p>
375 <p class="p1"><b><span class="Apple-tab-span"> </span>allocMsg(completionMessage)</b></p>
376 <p class="p18"><span class="Apple-tab-span"> </span></p>
377 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Allocate the necessary memory on the server for a Buffer previously created with <b>*new</b>, above.</p>
378 <p class="p12"><span class="Apple-tab-span"> </span></p>
379 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>completionMessage </b>- A valid OSC message or a <a href="../Core/Kernel/Function.html"><span class="s2">Function</span></a> which will return one. A Function will be passed this Buffer as an argument when evaluated.</p>
380 <p class="p12"><span class="Apple-tab-span"> </span></p>
381 <p class="p20"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>s.boot;</p>
382 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.new(s, 44100 * 8.0, 2);</p>
383 <p class="p19"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.query; </span>// numFrames = 0</p>
384 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.alloc;</p>
385 <p class="p19"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.query; </span>// numFrames = 352800</p>
386 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.free;</p>
387 <p class="p12"><br></p>
388 <p class="p1"><span class="Apple-tab-span"> </span><b>allocRead(argpath, startFrame, numFrames, completionMessage)</b></p>
389 <p class="p1"><b><span class="Apple-tab-span"> </span>allocReadMsg(argpath, startFrame, numFrames, completionMessage)</b></p>
390 <p class="p18"><span class="Apple-tab-span"> </span></p>
391 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Read a soundfile into a buffer on the server for a Buffer previously created with <b>*new</b>, above. Note that this will not autoupdate instance variables. Call <b>updateInfo</b> in order to do this.</p>
392 <p class="p12"><br></p>
393 <p class="p11"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>argpath</b> - A <a href="../Collections/String.html"><span class="s2">String</span></a> representing the path of the soundfile to be read.</p>
394 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>startFrame</b> - The first frame of the soundfile to read. The default is 0, which is the beginning of the file.</p>
395 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>numFrames </b>- The number of frames to read. The default is -1, which will read the whole file.</p>
396 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>completionMessage </b>- A valid OSC message or a <a href="../Core/Kernel/Function.html"><span class="s2">Function</span></a> which will return one. A Function will be passed this Buffer as an argument when evaluated.</p>
397 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
398 <p class="p20"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>s.boot;</p>
399 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.new(s);</p>
400 <p class="p21"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.allocRead(</span>"sounds/a11wlk01.wav"<span class="s5">);</span></p>
401 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x = { <span class="s2">PlayBuf</span>.ar(1, b, <span class="s2">BufRateScale</span>.kr(b), loop: 1) * 0.5 }.play;</p>
402 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.free; b.free;</p>
403 <p class="p12"><br></p>
404 <p class="p1"><span class="Apple-tab-span"> </span><b>allocReadChannel(argpath, startFrame, numFrames, channels, completionMessage)</b></p>
405 <p class="p1"><b><span class="Apple-tab-span"> </span>allocReadChannelMsg(argpath, startFrame, numFrames, channels, completionMessage)</b></p>
406 <p class="p18"><span class="Apple-tab-span"> </span></p>
407 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>As <b>allocRead</b> above, but allows you to specify which channels to read.</p>
408 <p class="p12"><br></p>
409 <p class="p11"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>argpath</b> - A <a href="../Collections/String.html"><span class="s2">String</span></a> representing the path of the soundfile to be read.</p>
410 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>startFrame</b> - The first frame of the soundfile to read. The default is 0, which is the beginning of the file.</p>
411 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>numFrames </b>- The number of frames to read. The default is -1, which will read the whole file.</p>
412 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>channels</b> - An <a href="../Collections/Array.html"><span class="s2">Array</span></a> of channels to be read from the soundfile. Indices start from zero. These will be read in the order provided.</p>
413 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>completionMessage </b>- A valid OSC message or a <a href="../Core/Kernel/Function.html"><span class="s2">Function</span></a> which will return one. A Function will be passed this Buffer as an argument when evaluated.</p>
414 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
415 <p class="p20"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>s.boot;</p>
416 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.new(s);</p>
417 <p class="p19"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// read only the first channel (a Sine wave) of a stereo file</p>
418 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.allocReadChannel(<span class="s9">"sounds/SinedPink.aiff"</span>, channels: [0]);</p>
419 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x = { <span class="s2">PlayBuf</span>.ar(1, b, <span class="s2">BufRateScale</span>.kr(b), loop: 1) * 0.5 }.play;</p>
420 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.free; b.free;<span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span></p>
421 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
422 <p class="p3"><b>Instance Methods</b></p>
423 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
424 <p class="p11"><b><span class="Apple-tab-span"> </span>read(path, fileStartFrame, numFrames, bufStartFrame, leaveOpen, action);</b></p>
425 <p class="p11"><span class="Apple-tab-span"> </span><b>readMsg(path, fileStartFrame, numFrames, bufStartFrame, leaveOpen, completionMessage);</b></p>
426 <p class="p12"><br></p>
427 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Read a soundfile into an already allocated buffer. Note that if the number of frames in the file is greater than the number of frames in the buffer, it will be truncated. Note that <b>readMsg</b> will not auto-update instance variables. Call <b>updateInfo </b>in order to do this.</p>
428 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
429 <p class="p11"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>path</b> - A <a href="../Collections/String.html"><span class="s2">String</span></a> representing the path of the soundfile to be read.</p>
430 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>fileStartFrame</b> - The first frame of the soundfile to read. The default is 0, which is the beginning of the file.</p>
431 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>numFrames </b>- The number of frames to read. The default is -1, which will read the whole file.</p>
432 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>bufStartFrame</b> - The index of the frame in the buffer at which to start reading. The default is 0, which is the beginning of the buffer.</p>
433 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>leaveOpen</b> - A boolean indicating whether or not the Buffer should be left 'open'. For use with <a href="../UGens/Playback and Recording/DiskIn.html"><span class="s2">DiskIn</span></a> you will want this to be true, as the buffer will be used for streaming the soundfile in from disk. (For this the buffer must have been allocated with a multiple of (2 * synth block size).<span class="Apple-converted-space">  </span>A common number is 32768 frames. <b>cueSoundFile</b> below, provides a simpler way of doing this.) The default is false which is the correct value for all other cases.</p>
434 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>action</b> - A <b>Function</b> to be evaluated once the file has been read and this Buffer's instance variables have been updated. The function will be passed this Buffer as an argument.</p>
435 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>completionMessage </b>- A valid OSC message or a <a href="../Core/Kernel/Function.html"><span class="s2">Function</span></a> which will return one. A Function will be passed this Buffer as an argument when evaluated.</p>
436 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
437 <p class="p11"><b><span class="Apple-tab-span"> </span>readChannel(path, fileStartFrame, numFrames, bufStartFrame, leaveOpen, channels, action);</b></p>
438 <p class="p11"><span class="Apple-tab-span"> </span><b>readChannelMsg(path, fileStartFrame, numFrames, bufStartFrame, leaveOpen, channels, completionMessage);</b></p>
439 <p class="p12"><br></p>
440 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>As <b>read</b> above, but allows you to specify which channels to read.</p>
441 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
442 <p class="p11"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>path</b> - A <a href="../Collections/String.html"><span class="s2">String</span></a> representing the path of the soundfile to be read.</p>
443 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>fileStartFrame</b> - The first frame of the soundfile to read. The default is 0, which is the beginning of the file.</p>
444 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>numFrames </b>- The number of frames to read. The default is -1, which will read the whole file.</p>
445 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>bufStartFrame</b> - The index of the frame in the buffer at which to start reading. The default is 0, which is the beginning of the buffer.</p>
446 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>leaveOpen</b> - A boolean indicating whether or not the Buffer should be left 'open'. For use with <a href="../UGens/Playback and Recording/DiskIn.html"><span class="s2">DiskIn</span></a> you will want this to be true, as the buffer will be used for streaming the soundfile in from disk. (For this the buffer must have been allocated with a multiple of (2 * synth block size).<span class="Apple-converted-space">  </span>A common number is 32768 frames. <b>cueSoundFile</b> below, provides a simpler way of doing this.) The default is false which is the correct value for all other cases.</p>
447 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>channels</b> - An <a href="../Collections/Array.html"><span class="s2">Array</span></a> of channels to be read from the soundfile. Indices start from zero. These will be read in the order provided. The number of channels requested must match this Buffer's <b>numChannels</b>.</p>
448 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>action</b> - A <a href="../Core/Kernel/Function.html"><span class="s2">Function</span></a> to be evaluated once the file has been read and this Buffer's instance variables have been updated. The function will be passed this Buffer as an argument.</p>
449 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>completionMessage </b>- A valid OSC message or a <a href="../Core/Kernel/Function.html"><span class="s2">Function</span></a> which will return one. A Function will be passed this Buffer as an argument when evaluated.</p>
450 <p class="p12"><span class="Apple-tab-span"> </span><b><span class="Apple-tab-span"> </span></b></p>
451 <p class="p12"><br></p>
452 <p class="p11"><b><span class="Apple-tab-span"> </span>cueSoundFile(path, startFrame, completionMessage)</b></p>
453 <p class="p11"><span class="Apple-tab-span"> </span><b>cueSoundFileMsg(path, startFrame, completionMessage)</b></p>
454 <p class="p12"><br></p>
455 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>A convenience method to cue a soundfile into the buffer for use with a <a href="../UGens/Playback and Recording/DiskIn.html"><span class="s2">DiskIn</span></a>. The buffer must have been allocated with a multiple of (2 * the server's block size) frames.<span class="Apple-converted-space">  </span>A common size is 32768 frames.</p>
456 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
457 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>path</b> - A <a href="../Collections/String.html"><span class="s2">String</span></a> representing the path of the soundfile to be read.</p>
458 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>startFrame</b> - The first frame of the soundfile to read. The default is 0, which is the beginning of the file.</p>
459 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>completionMessage </b>- A valid OSC message or a <a href="../Core/Kernel/Function.html"><span class="s2">Function</span></a> which will return one. A Function will be passed this Buffer as an argument when evaluated.</p>
460 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
461 <p class="p20"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>s.boot;</p>
462 <p class="p19"><span class="s10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>//create with cueSoundFile class method</p>
463 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.cueSoundFile(s, <span class="s9">"sounds/a11wlk01-44_1.aiff"</span>, 0, 1);</p>
464 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x = { <span class="s2">DiskIn</span>.ar(1, b) }.play;<span class="Apple-tab-span"> </span></p>
465 <p class="p16"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.close;<span class="Apple-tab-span"> </span></span>// must call close in between cueing</p>
466 <p class="p16"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// now use like named instance method, but different arguments</p>
467 <p class="p23"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.cueSoundFile(</span>"sounds/a11wlk01-44_1.aiff"<span class="s5">);<span class="Apple-tab-span"> </span></span></p>
468 <p class="p16"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// have to do all this to clean up properly!<span class="Apple-tab-span"> </span></p>
469 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.free; b.close; b.free;<span class="Apple-tab-span"> </span></p>
470 <p class="p12"><span class="Apple-tab-span"> </span></p>
471 <p class="p11"><b><span class="Apple-tab-span"> </span>write(path, headerFormat, sampleFormat, numFrames, startFrame, leaveOpen, completionMessage)</b></p>
472 <p class="p11"><b><span class="Apple-tab-span"> </span>writeMsg(path, headerFormat, sampleFormat, numFrames, startFrame, leaveOpen, completionMessage)</b></p>
473 <p class="p12"><br></p>
474 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Write the contents of the buffer to a file. See <a href="../Files/SoundFile.html"><span class="s2">SoundFile</span></a> for information on valid values for <b>headerFormat</b> and <b>sampleFormat</b>.</p>
475 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
476 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>path</b> - A <b>String</b> representing the path of the soundfile to be written.</p>
477 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>If no path is given, Buffer writes into the default recording directory with a generic name.</p>
478 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>numFrames </b>- The number of frames to write. The default is -1, which will write the whole buffer.</p>
479 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>startFrame</b> - The index of the frame in the buffer from which to start writing. The default is 0, which is the beginning of the buffer.</p>
480 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>leaveOpen</b> - A boolean indicating whether or not the Buffer should be left 'open'. For use with <a href="../UGens/Playback and Recording/DiskOut.html"><span class="s2">DiskOut</span></a> you will want this to be true. The default is false which is the correct value for all other cases.</p>
481 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>completionMessage </b>- A valid OSC message or a <a href="../Core/Kernel/Function.html"><span class="s2">Function</span></a> which will return one. A Function will be passed this Buffer as an argument when evaluated.</p>
482 <p class="p12"><br></p>
483 <p class="p11"><b><span class="Apple-tab-span"> </span>free(completionMessage)</b></p>
484 <p class="p11"><b><span class="Apple-tab-span"> </span>freeMsg(completionMessage)</b></p>
485 <p class="p12"><span class="Apple-tab-span"> </span></p>
486 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Release the buffer's memory on the server and return the bufferID back to the server's buffer number allocator for future reuse.</p>
487 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
488 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>completionMessage </b>- A valid OSC message or a <a href="../Core/Kernel/Function.html"><span class="s2">Function</span></a> which will return one. A Function will be passed this Buffer as an argument when evaluated.</p>
489 <p class="p12"><br></p>
490 <p class="p11"><b><span class="Apple-tab-span"> </span>zero(completionMessage)</b></p>
491 <p class="p11"><span class="Apple-tab-span"> </span><b>zeroMsg(completionMessage)</b></p>
492 <p class="p12"><span class="Apple-tab-span"> </span></p>
493 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Sets all values in this buffer to 0.0.</p>
494 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
495 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>completionMessage </b>- A valid OSC message or a <a href="../Core/Kernel/Function.html"><span class="s2">Function</span></a> which will return one. A Function will be passed this Buffer as an argument when evaluated.</p>
496 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
497 <p class="p11"><b><span class="Apple-tab-span"> </span>set(index,float ... morePairs)</b></p>
498 <p class="p11"><b><span class="Apple-tab-span"> </span>setMsg(index,float ... morePairs)</b></p>
499 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
500 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Set the value in the buffer at <b>index</b> to be equal to <b>float</b>. Additional pairs of indices and floats may be included in the same message. Note that multichannel buffers interleave their sample data, therefore the actual number of available values is equal to numFrames * numChannels. Indices start at 0.</p>
501 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
502 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>s.boot;</p>
503 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.alloc(s, 4, 2);</p>
504 <p class="p19"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.set(0, 0.2, 1, 0.3, 7, 0.4); </span>// set the values at indices 0, 1, and 7.</p>
505 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.getn(0, 8, {<span class="s2">|msg|</span> msg.postln});</p>
506 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.free;<span class="Apple-tab-span"> </span></p>
507 <p class="p12"><br></p>
508 <p class="p11"><b><span class="Apple-tab-span"> </span>setn(startAt,values ... morePairs)</b></p>
509 <p class="p11"><b><span class="Apple-tab-span"> </span>setnMsg(startAt,values ... morePairs)</b></p>
510 <p class="p12"><span class="Apple-tab-span"> </span></p>
511 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Set a contiguous range of values in the buffer starting at the index <b>startAt</b> to be equal to the <a href="../Collections/Array.html"><span class="s2">Array</span></a> of floats or integers, <b>values</b>. The number of values set corresponds to the size of <b>values</b>. Additional pairs of starting indices and arrays of values may be included in the same message. Note that multichannel buffers interleave their sample data, therefore the actual number of available values is equal to numFrames * numChannels. You are responsible for interleaving the data in <b>values</b> if needed. Multi-dimensional arrays will not work. Indices start at 0.</p>
512 <p class="p15"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
513 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>N.B.</b> The maximum number of values that you can set with a single setn message is 1633 when the server is using UDP as its communication protocol. Use <b>loadCollection</b> and <b>sendCollection</b> to set larger ranges of values.</p>
514 <p class="p18"><br></p>
515 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>s.boot;</p>
516 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.alloc(s,16);</p>
517 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.setn(0, <span class="s2">Array</span>.fill(16, { rrand(0,1) }));</p>
518 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.getn(0, b.numFrames, {<span class="s2">|msg|</span> msg.postln});</p>
519 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.setn(0, [1, 2, 3], 4, [1, 2, 3]);</p>
520 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.getn(0, b.numFrames, {<span class="s2">|msg|</span> msg.postln});</p>
521 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.free;</p>
522 <p class="p9"><br></p>
523 <p class="p5"><span class="s7"><span class="Apple-tab-span"> </span></span><b>loadCollection(collection, startFrame, action)</b></p>
524 <p class="p6"><br></p>
525 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Load a large collection into this buffer. This is accomplished through writing the collection to a <a href="../Files/SoundFile.html"><span class="s2">SoundFile</span></a> and loading it from there. For this reason this method will only work with a server on your local machine. For a remote server use <b>sendCollection</b>, below. The file is automatically deleted after loading. This allows for larger collections than <b>setn</b>, above, and is in general the safest way to get a large collection into a buffer. The sample rate of the buffer will be the sample rate of the server on which it was created. The number of channels and frames will have been determined when the buffer was allocated. You are responsible for making sure that the size of <b>collection</b> is not greater than <b>numFrames</b>, and for interleaving any data if needed.<span class="Apple-converted-space"> </span></p>
526 <p class="p12"><span class="Apple-tab-span"> </span></p>
527 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>collection</b> - A subclass of <a href="../Collections/Collection.html"><span class="s2">Collection</span></a> (i.e. an <a href="../Collections/Array.html"><span class="s2">Array</span></a>) containing <i>only</i> floats and integers. Multi-dimensional arrays will not work.</p>
528 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>startFrame </b>- The index of the frame at which to start loading the collection. The default is 0, which is the start of the buffer.</p>
529 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>action</b> - A <b>Function</b> to be evaluated once the file has been read and this Buffer's instance variables have been updated. The function will be passed this Buffer as an argument.</p>
530 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
531 <p class="p20"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>s.boot;</p>
532 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
533 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>v = <span class="s2">Signal</span>.sineFill(128, 1.0/[1,2,3,4,5,6]);</p>
534 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.alloc(s, 128);</p>
535 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
536 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
537 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.loadCollection(v, action: {<span class="s2">|buf|</span><span class="Apple-converted-space"> </span></p>
538 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x = { <span class="s2">PlayBuf</span>.ar(buf.numChannels, buf, <span class="s2">BufRateScale</span>.kr(buf), loop: 1)<span class="Apple-converted-space"> </span></p>
539 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>* 0.2 }.play;</p>
540 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>});</p>
541 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
542 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.free; b.free;</p>
543 <p class="p8"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
544 <p class="p16"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// interleave a multi-dimensional array</p>
545 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
546 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>l = <span class="s2">Signal</span>.sineFill(16384, <span class="s2">Array</span>.fill(200, {0}).add(1));</p>
547 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>r = <span class="s2">Array</span>.fill(16384, {1.0.rand2});</p>
548 <p class="p16"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>m = [</span><span class="s2">Array</span><span class="s5">.newFrom(l), r]; </span>// a multi-dimensional array</p>
549 <p class="p16"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>m = m.lace(32768); </span>// interleave the two collections<span class="Apple-converted-space"> </span></p>
550 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.alloc(s, 16384, 2);</p>
551 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
552 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
553 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.loadCollection(m, 0, {<span class="s2">|buf|</span></p>
554 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x = { <span class="s2">PlayBuf</span>.ar(2, buf, <span class="s2">BufRateScale</span>.kr(buf), loop: 1) * 0.5 }.play;</p>
555 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>});</p>
556 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
557 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.plot;</p>
558 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.free; b.free;</p>
559 <p class="p8"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
560 <p class="p5"><span class="s7"><span class="Apple-tab-span"> </span></span><b>sendCollection(collection, startFrame, wait, action)</b></p>
561 <p class="p6"><br></p>
562 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Stream a large collection into this buffer using multiple <b>setn</b> messages. This allows for larger collections than <b>setn</b>. This is not as safe as <b>loadCollection</b>, above, but will work with servers on remote machines. The sample rate of the buffer will be the sample rate of the server on which it is created.</p>
563 <p class="p12"><span class="Apple-tab-span"> </span></p>
564 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>collection</b> - A subclass of <a href="../Collections/Collection.html"><span class="s2">Collection</span></a> (i.e. an <a href="../Collections/Array.html"><span class="s2">Array</span></a>) containing <i>only</i> floats and integers. Multi-dimensional arrays will not work.</p>
565 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>startFrame </b>- The index of the frame at which to start streaming in the collection. The default is 0, which is the start of the buffer.</p>
566 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>wait</b> - An optional wait time between sending <b>setn</b> messages. In a high traffic situation it may be safer to set this to something above zero, which is the default.</p>
567 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>action</b> - A <a href="../Core/Kernel/Function.html"><span class="s2">Function</span></a> to be evaluated once the file has been read and this Buffer's instance variables have been updated. The function will be passed this Buffer as an argument.</p>
568 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
569 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>s.boot;</p>
570 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
571 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>a = <span class="s2">Array</span>.fill(2000000,{ rrand(0.0,1.0) });</p>
572 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.alloc(s, 2000000);</p>
573 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
574 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = b.sendCollection(a, action: {<span class="s2">arg</span> buf; <span class="s9">"finished"</span>.postln;});</p>
575 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.get(1999999, {<span class="s2">|msg|</span> (msg == a[1999999]).postln});</p>
576 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.free;</p>
577 <p class="p8"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
578 <p class="p11"><b><span class="Apple-tab-span"> </span>get(index, action)</b></p>
579 <p class="p11"><b><span class="Apple-tab-span"> </span>getMsg(index)</b></p>
580 <p class="p12"><br></p>
581 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Send a message requesting the value in the buffer at <b>index</b>. <b>action</b> is a <a href="../Core/Kernel/Function.html"><span class="s2">Function</span></a> which will be passed the value as an argument and evaluated when a reply is received.</p>
582 <p class="p15"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
583 <p class="p17"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>s.boot;</p>
584 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.alloc(s,16);</p>
585 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.setn(0, <span class="s2">Array</span>.fill(16, { rrand(0.0, 1.0) }));</p>
586 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.get(0, {<span class="s2">|msg|</span> msg.postln});</p>
587 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.free;</p>
588 <p class="p12"><br></p>
589 <p class="p11"><b><span class="Apple-tab-span"> </span>getn(index, count, action)</b></p>
590 <p class="p11"><b><span class="Apple-tab-span"> </span>getMsg(index, count)</b></p>
591 <p class="p12"><br></p>
592 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Send a message requesting the a contiguous range of values of size <b>count</b> starting from <b>index</b>. <b>action</b> is a <a href="../Core/Kernel/Function.html"><span class="s2">Function</span></a> which will be passed the values in an <b>Array</b> as an argument and evaluated when a reply is received. See <b>setn</b> above for an example.<span class="Apple-converted-space"> </span></p>
593 <p class="p15"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
594 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>N.B.</b> The maximum number of values that you can get with a single getn message is 1633 when the server is using UDP as its communication protocol. Use <b>loadToFloatArray</b> and <b>getToFloatArray</b> to get larger ranges of values.</p>
595 <p class="p15"><span class="Apple-tab-span"> </span></p>
596 <p class="p10"><span class="Apple-tab-span"> </span><b>loadToFloatArray(index, count, action)</b></p>
597 <p class="p12"><br></p>
598 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Write the buffer to a file and then load it into a <a href="../Collections/FloatArray.html"><span class="s2">FloatArray</span></a>. This is safer than <b>getToFloatArray</b> but only works with a server on your local machine. In general this is the safest way to get a large range of values from a server buffer into the client app.</p>
599 <p class="p15"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
600 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>index</b> - The index in the buffer to begin writing from. The default is 0.</p>
601 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>count</b> - The number of values to write. The default is -1, which writes from index until the end of the<span class="Apple-converted-space">  </span>buffer.</p>
602 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>action</b> - A <b>Function</b> which will be passed the resulting <a href="../Collections/FloatArray.html"><span class="s2">FloatArray</span></a> as an argument and evaluated when loading is finished.</p>
603 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
604 <p class="p20"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>s.boot;</p>
605 <p class="p23"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = </span><span class="s2">Buffer</span><span class="s5">.read(s,</span>"sounds/a11wlk01.wav"<span class="s5">);</span></p>
606 <p class="p16"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// same as Buffer.plot</p>
607 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.loadToFloatArray(action: { <span class="s2">arg</span> array; a = array; {a.plot;}.defer; <span class="s9">"done"</span>.postln;});</p>
608 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.free;</p>
609 <p class="p15"><br></p>
610 <p class="p10"><span class="Apple-tab-span"> </span><b>getToFloatArray(index, count, wait, timeout, action)</b></p>
611 <p class="p12"><br></p>
612 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Stream the buffer to the client using a series of <b>getn</b> messages and put the results into a <a href="../Collections/FloatArray.html"><span class="s2">FloatArray</span></a>. This is more risky than <b>loadToFloatArray</b> but does works with servers on remote machines. In high traffic situations it is possible for data to be lost. If this method has not received all its replies by <b>timeout</b> it will post a warning saying that the method has failed. In general use <b>loadToFloatArray</b> instead wherever possible.</p>
613 <p class="p15"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
614 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>index</b> - The index in the buffer to begin writing from. The default is 0.</p>
615 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>count</b> - The number of values to write. The default is -1, which writes from index until the end of the<span class="Apple-converted-space">  </span>buffer.</p>
616 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>wait</b> - The amount of time in seconds to wait between sending getn messages. Longer times are safer. The default is 0.01 seconds which seems reliable under normal circumstances. A setting of 0 is <i>not</i><b> </b>recommended.</p>
617 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>timeout</b> - The amount of time in seconds after which to post a warning if all replies have not yet been received. the default is 3.</p>
618 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>action</b> - A <a href="../Core/Kernel/Function.html"><span class="s2">Function</span></a> which will be passed the resulting <a href="../Collections/FloatArray.html"><span class="s2">FloatArray</span></a> as an argument and evaluated when all replies have been received.</p>
619 <p class="p12"><br></p>
620 <p class="p20"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>s.boot;</p>
621 <p class="p23"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = </span><span class="s2">Buffer</span><span class="s5">.read(s,</span>"sounds/a11wlk01.wav"<span class="s5">);</span></p>
622 <p class="p16"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// like Buffer.plot</p>
623 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.getToFloatArray(wait:0.01,action:{<span class="s2">arg</span> array; a = array; {a.plot;}.defer;<span class="s9">"done"</span>.postln;});</p>
624 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.free;</p>
625 <p class="p2"><span class="s7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b><span class="Apple-tab-span"> </span></b><span class="Apple-tab-span"> </span><b><span class="Apple-tab-span"> </span></b></p>
626 <p class="p11"><b><span class="Apple-tab-span"> </span>normalize(newmax, asWavetable)</b></p>
627 <p class="p11"><b><span class="Apple-tab-span"> </span>normalizeMsg(newmax, asWavetable)</b></p>
628 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
629 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Normalizes the buffer so that the peak absolute value is <b>newmax</b> (which defaults to 1). If your buffer is in <a href="../Collections/Wavetable.html"><span class="s2">Wavetable</span></a> format then set the <b>asWavetable</b> argument to true.</p>
630 <p class="p12"><span class="Apple-tab-span"> </span></p>
631 <p class="p11"><b><span class="Apple-tab-span"> </span>fill(startAt, numFrames, value ... more)</b></p>
632 <p class="p11"><b><span class="Apple-tab-span"> </span>fillMsg(startAt, numFrames, value ... more)</b></p>
633 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
634 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Starting at the index <b>startAt</b>, set the next <b>numFrames</b> to value. Additional ranges may be included in the same message.</p>
635 <p class="p12"><span class="Apple-tab-span"> </span></p>
636 <p class="p11"><b><span class="Apple-tab-span"> </span>copyData(buf, dstStartAt, srcStartAt, numSamples)</b></p>
637 <p class="p11"><b><span class="Apple-tab-span"> </span>copyMsg(buf, dstStartAt, srcStartAt, numSamples)</b></p>
638 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
639 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Starting at the index <b>srcSamplePos</b>, copy <b>numSamples</b> samples from this to the destination buffer <b>buf</b> starting at <b>dstSamplePos</b>. If numSamples is negative, the maximum number of samples possible is copied. The default is start from 0 in the source and copy the maximum number possible starting at 0 in the destination.</p>
640 <p class="p15"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
641 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>Note:</b> This method used to be called <b>copy</b>, but this conflicts with the method for object-copying. Therefore Buffer:copy is now intended to create a copy of the client-side Buffer object. Its use for copying buffer data on the server is deprecated. If you see a deprecation warning, the data will still be copied on the server and your code will still work, but you should update your code for the new method name.</p>
642 <p class="p12"><br></p>
643 <p class="p20"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>s.boot;</p>
644 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
645 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">SynthDef</span>(<span class="s8">\help_Buffer_copy</span>, { <span class="s2">arg</span> out=0, buf;</p>
646 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">Line</span>.ar(0, 0, dur: <span class="s2">BufDur</span>.kr(buf), doneAction: 2); <span class="s6">// frees itself</span></p>
647 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">Out</span>.ar(out, <span class="s2">PlayBuf</span>.ar(1, buf));</p>
648 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>}).add;</p>
649 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
650 <p class="p18"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
651 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
652 <p class="p21"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = </span><span class="s2">Buffer</span><span class="s5">.read(s, </span>"sounds/a11wlk01.wav"<span class="s5">);</span></p>
653 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>c = <span class="s2">Buffer</span>.alloc(s, 120000);</p>
654 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
655 <p class="p18"><br></p>
656 <p class="p22"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s2">Synth</span><span class="s5">(</span>\help_Buffer_copy<span class="s5">, [</span>\buf<span class="s5">, b]);<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span></p>
657 <p class="p18"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
658 <p class="p19"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// copy the whole buffer</p>
659 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.copyData(c);</p>
660 <p class="p22"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s2">Synth</span><span class="s5">(</span>\help_Buffer_copy<span class="s5">, [</span>\buf<span class="s5">, c]);</span></p>
661 <p class="p18"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
662 <p class="p19"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// copy some samples</p>
663 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>c.zero;<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
664 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.copyData(c, numSamples: 4410);</p>
665 <p class="p22"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s2">Synth</span><span class="s5">(</span>\help_Buffer_copy<span class="s5">, [</span>\buf<span class="s5">, c]);</span></p>
666 <p class="p18"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
667 <p class="p19"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// buffer "compositing"</p>
668 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>c.zero;<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
669 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.copyData(c, numSamples: 4410);</p>
670 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.copyData(c, dstStartAt: 4410, numSamples: 15500);</p>
671 <p class="p22"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s2">Synth</span><span class="s5">(</span>\help_Buffer_copy<span class="s5">, [</span>\buf<span class="s5">, c]);</span></p>
672 <p class="p12"><br></p>
673 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.free;</p>
674 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>c.free;</p>
675 <p class="p12"><br></p>
676 <p class="p11"><b><span class="Apple-tab-span"> </span>close(completionMessage)</b></p>
677 <p class="p11"><b><span class="Apple-tab-span"> </span>closeMsg(completionMessage)</b></p>
678 <p class="p12"><b><span class="Apple-tab-span"> </span></b></p>
679 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>After using a Buffer with a <a href="../UGens/Playback and Recording/DiskOut.html"><span class="s2">DiskOut</span></a> or <a href="../UGens/Playback and Recording/DiskIn.html"><span class="s2">DiskIn</span></a>, it is necessary to close the soundfile. Failure to do so can cause problems.</p>
680 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
681 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>completionMessage </b>- A valid OSC message or a <a href="../Core/Kernel/Function.html"><span class="s2">Function</span></a> which will return one. A Function will be passed this Buffer as an argument when evaluated.</p>
682 <p class="p12"><span class="Apple-tab-span"> </span></p>
683 <p class="p11"><b><span class="Apple-tab-span"> </span>plot(name, bounds, minval = -1.0, maxval = 1.0, parent)</b></p>
684 <p class="p12"><b><span class="Apple-tab-span"> </span></b></p>
685 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Plot the contents of the Buffer in a GUI window. OSX only.</p>
686 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
687 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>name </b>- The name of the resulting window.</p>
688 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>bounds</b> - An instance of <a href="../Geometry/Rect.html"><span class="s2">Rect</span></a> determining the size of the resulting view.</p>
689 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>minval</b> - the minimum value in the plot</p>
690 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>maxval</b> - the maximum value in the plot</p>
691 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>parent</b> - a window to place the plot in. If nil, one will be created for you</p>
692 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
693 <p class="p20"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>s.boot;</p>
694 <p class="p23"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = </span><span class="s2">Buffer</span><span class="s5">.read(s,</span>"sounds/a11wlk01.wav"<span class="s5">);</span></p>
695 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.plot;</p>
696 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.free;</p>
697 <p class="p8"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
698 <p class="p11"><b><span class="Apple-tab-span"> </span>play(loop, mul)</b></p>
699 <p class="p12"><b><span class="Apple-tab-span"> </span></b></p>
700 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Plays the contents of the buffer on the server and returns a corresponding <a href="Synth.html"><span class="s2">Synth</span></a>.</p>
701 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
702 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>loop </b>- A Boolean indicating whether or not to loop playback. If false the synth will automatically be freed when done. The default is false.</p>
703 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>mul</b> - A value by which to scale the output. The default is 1.</p>
704 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
705 <p class="p20"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>s.boot;</p>
706 <p class="p23"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = </span><span class="s2">Buffer</span><span class="s5">.read(s,</span>"sounds/a11wlk01.wav"<span class="s5">);</span></p>
707 <p class="p16"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.play; </span>// frees itself</p>
708 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x = b.play(<span class="s2">true</span>);</p>
709 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.free; b.free;</p>
710 <p class="p8"><br></p>
711 <p class="p11"><b><span class="Apple-tab-span"> </span>query</b></p>
712 <p class="p12"><b><span class="Apple-tab-span"> </span></b></p>
713 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Sends a b_query message to the server, asking for a description of this buffer. The results are posted to the post window. Does not update instance vars.</p>
714 <p class="p15"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
715 <p class="p10"><span class="Apple-tab-span"> </span><b>updateInfo(action)</b></p>
716 <p class="p12"><b><span class="Apple-tab-span"> </span></b></p>
717 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Sends a b_query message to the server, asking for a description of this buffer. Upon reply this Buffer's instance variables are automatically updated.</p>
718 <p class="p15"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
719 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>action</b> - A <a href="../Core/Kernel/Function.html"><span class="s2">Function</span></a> to be evaluated once the file has been read and this Buffer's instance variables have been updated. The function will be passed this Buffer as an argument.</p>
720 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
721 <p class="p20"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>s.boot;</p>
722 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.readNoUpdate(s, <span class="s9">"sounds/a11wlk01.wav"</span>);</p>
723 <p class="p19"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.numFrames; </span>// incorrect, shows nil</p>
724 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.updateInfo({<span class="s2">|buf|</span> buf.numFrames.postln; }); <span class="s6">// now it's right</span></p>
725 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.free;</p>
726 <p class="p18"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
727 <p class="p3"><b>Buffer Fill Commands</b></p>
728 <p class="p18"><br></p>
729 <p class="p1">These correspond to the various b_gen OSC Commands, which fill the buffer with values for use. See <a href="Server-Command-Reference.html"><span class="s2">Server-Command-Reference</span></a> for more details.</p>
730 <p class="p18"><br></p>
731 <p class="p11"><b><span class="Apple-tab-span"> </span>gen(genCommand, genArgs, normalize, asWavetable, clearFirst)</b></p>
732 <p class="p11"><b><span class="Apple-tab-span"> </span>genMsg(genCommand, genArgs, normalize, asWavetable, clearFirst)</b></p>
733 <p class="p12"><b><span class="Apple-tab-span"> </span></b></p>
734 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>This is a generalized version of the commands below.</p>
735 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
736 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>genCommand </b>- A <a href="../Collections/String.html"><span class="s2">String</span></a> indicating the name of the command to use. See <a href="Server-Command-Reference.html"><span class="s2">Server-Command-Reference</span></a> for a list of valid command names.</p>
737 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>genArgs</b> - An <a href="../Collections/Array.html"><span class="s2">Array</span></a> containing the corresponding arguments to the command.</p>
738 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>normalize</b> - A <a href="../Core/Boolean.html"><span class="s2">Boolean</span></a> indicating whether or not to normalize the buffer to a peak value of 1.0. The default is true.</p>
739 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>asWavetable</b> - A <a href="../Core/Boolean.html"><span class="s2">Boolean</span></a> indicating whether or not to write to the buffer in wavetable format so that it can be read by interpolating oscillators. The default is true.</p>
740 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>clearFirst</b> - A <a href="../Core/Boolean.html"><span class="s2">Boolean</span></a> indicating whether or not to clear the buffer before writing. The default is true.</p>
741 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
742 <p class="p11"><b><span class="Apple-tab-span"> </span>sine1(amps, normalize, asWavetable, clearFirst)</b></p>
743 <p class="p11"><b><span class="Apple-tab-span"> </span>sine1Msg(amps, normalize, asWavetable, clearFirst)</b></p>
744 <p class="p12"><b><span class="Apple-tab-span"> </span></b></p>
745 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Fill this buffer with a series of sine wave harmonics using specified amplitudes.</p>
746 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
747 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>amps</b> - An <a href="../Collections/Array.html"><span class="s2">Array</span></a><b> </b>containing amplitudes for the harmonics. The first float value specifies the amplitude of the first partial, the second float value specifies the amplitude of the second partial, and so on.</p>
748 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>normalize</b> - A <a href="../Core/Boolean.html"><span class="s2">Boolean</span></a> indicating whether or not to normalize the buffer to a peak value of 1.0. The default is true.</p>
749 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>asWavetable</b> - A <a href="../Core/Boolean.html"><span class="s2">Boolean</span></a> indicating whether or not to write to the buffer in wavetable format so that it can be read by interpolating oscillators. The default is true.</p>
750 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>clearFirst</b> - A <a href="../Core/Boolean.html"><span class="s2">Boolean</span></a> indicating whether or not to clear the buffer before writing. The default is true.</p>
751 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
752 <p class="p20"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>s.boot;</p>
753 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
754 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.alloc(s, 512, 1);</p>
755 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.sine1(1.0 / [1, 2, 3, 4], <span class="s2">true</span>, <span class="s2">true</span>, <span class="s2">true</span>);</p>
756 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x = { <span class="s2">Osc</span>.ar(b, 200, 0, 0.5) }.play;</p>
757 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
758 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.free; b.free;</p>
759 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-converted-space"> </span></p>
760 <p class="p11"><b><span class="Apple-tab-span"> </span>sine2(freqs, amps, normalize, asWavetable, clearFirst)</b></p>
761 <p class="p11"><b><span class="Apple-tab-span"> </span>sine2Msg(freqs, amps, normalize, asWavetable, clearFirst)</b></p>
762 <p class="p12"><b><span class="Apple-tab-span"> </span></b></p>
763 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Fill this buffer with a series of sine wave partials using specified frequencies and amplitudes.</p>
764 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
765 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>freqs</b> - An <a href="../Collections/Array.html"><span class="s2">Array</span></a><b> </b>containing frequencies (in cycles per buffer) for the partials.</p>
766 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>amps</b> - An <a href="../Collections/Array.html"><span class="s2">Array</span></a><b> </b>containing amplitudes for the partials. This should contain the same number of items as freqs.</p>
767 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>normalize</b> - A <a href="../Core/Boolean.html"><span class="s2">Boolean</span></a> indicating whether or not to normalize the buffer to a peak value of 1.0. The default is true.</p>
768 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>asWavetable</b> - A <a href="../Core/Boolean.html"><span class="s2">Boolean</span></a> indicating whether or not to write to the buffer in wavetable format so that it can be read by interpolating oscillators. The default is true.</p>
769 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>clearFirst</b> - A <a href="../Core/Boolean.html"><span class="s2">Boolean</span></a> indicating whether or not to clear the buffer before writing. The default is true.</p>
770 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
771 <p class="p20"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>s.boot;</p>
772 <p class="p20"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
773 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.alloc(s, 512, 1);</p>
774 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.sine2([1.0, 3], [1, 0.5]);</p>
775 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x = { <span class="s2">Osc</span>.ar(b, 200, 0, 0.5) }.play;</p>
776 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
777 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.free; b.free;</p>
778 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
779 <p class="p11"><b><span class="Apple-tab-span"> </span>sine3(freqs, amps, phases, normalize, asWavetable, clearFirst)</b></p>
780 <p class="p11"><b><span class="Apple-tab-span"> </span>sine3Msg(freqs, amps, phases, normalize, asWavetable, clearFirst)</b></p>
781 <p class="p12"><b><span class="Apple-tab-span"> </span></b></p>
782 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Fill this buffer with a series of sine wave partials using specified frequencies, amplitudes, and initial phases.</p>
783 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
784 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>freqs</b> - An <a href="../Collections/Array.html"><span class="s2">Array</span></a><b> </b>containing frequencies (in cycles per buffer) for the partials.</p>
785 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>amps</b> - An <a href="../Collections/Array.html"><span class="s2">Array</span></a><b> </b>containing amplitudes for the partials. This should contain the same number of items as freqs.</p>
786 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>phases</b> - An <a href="../Collections/Array.html"><span class="s2">Array</span></a><b> </b>containing initial phase for the partials (in radians). This should contain the same number of items as freqs.</p>
787 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>normalize</b> - A <a href="../Core/Boolean.html"><span class="s2">Boolean</span></a> indicating whether or not to normalize the buffer to a peak value of 1.0. The default is true.</p>
788 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>asWavetable</b> - A <a href="../Core/Boolean.html"><span class="s2">Boolean</span></a> indicating whether or not to write to the buffer in wavetable format so that it can be read by interpolating oscillators. The default is true.</p>
789 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>clearFirst</b> - A <a href="../Core/Boolean.html"><span class="s2">Boolean</span></a> indicating whether or not to clear the buffer before writing. The default is true.</p>
790 <p class="p18"><br></p>
791 <p class="p18"><br></p>
792 <p class="p11"><b><span class="Apple-tab-span"> </span>cheby(amplitudes, normalize, asWavetable, clearFirst)</b></p>
793 <p class="p11"><b><span class="Apple-tab-span"> </span>chebyMsg(amplitudes, normalize, asWavetable, clearFirst)</b></p>
794 <p class="p12"><b><span class="Apple-tab-span"> </span></b></p>
795 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Fill this buffer with a series of chebyshev polynomials, which can be defined as: cheby(n) = amplitude<span class="Apple-converted-space">  </span>* cos(n * acos(x)). To eliminate a DC offset when used as a waveshaper, the wavetable is offset so that the center value is zero.<span class="Apple-converted-space"> </span></p>
796 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
797 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>amplitudes</b> - An <a href="../Collections/Array.html"><span class="s2">Array</span></a><b> </b>containing amplitudes for the harmonics. The first float value specifies the amplitude for n = 1, the second float value specifies the amplitude for n = 2, and so on.</p>
798 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>normalize</b> - A <a href="../Core/Boolean.html"><span class="s2">Boolean</span></a> indicating whether or not to normalize the buffer to a peak value of 1.0. The default is true.</p>
799 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>asWavetable</b> - A <a href="../Core/Boolean.html"><span class="s2">Boolean</span></a> indicating whether or not to write to the buffer in wavetable format so that it can be read by interpolating oscillators. The default is true.</p>
800 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>clearFirst</b> - A <a href="../Core/Boolean.html"><span class="s2">Boolean</span></a> indicating whether or not to clear the buffer before writing. The default is true.</p>
801 <p class="p12"><br></p>
802 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>s.boot;</p>
803 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s2">Buffer</span>.alloc(s, 512, 1, {<span class="s2">arg</span> buf; buf.chebyMsg([1,0,1,1,0,1])});</p>
804 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
805 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x = {<span class="Apple-converted-space"> </span></p>
806 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">Shaper</span>.ar(</p>
807 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b,<span class="Apple-converted-space"> </span></p>
808 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">SinOsc</span>.ar(300, 0, <span class="s2">Line</span>.kr(0,1,6)),</p>
809 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>0.5</p>
810 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)<span class="Apple-converted-space"> </span></p>
811 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>}.play;</p>
812 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
813 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.free; b.free;<span class="s4"><span class="Apple-tab-span"> </span></span></p>
814 <p class="p8"><br></p>
815 <p class="p3"><b>Cached Buffers</b></p>
816 <p class="p8"><br></p>
817 <p class="p1">To assist with automatic updates of buffer information (see <b>updateInfo</b> and <b>*read</b>), buffer objects are cached in a collection associated with the Server object hosting the buffers. Freeing a buffer removes it from the cache; quitting the server clears all the cached buffers. (This also occurs if the server crashes unexpectedly.)</p>
818 <p class="p2"><br></p>
819 <p class="p1">You may access cached buffers using the following methods.</p>
820 <p class="p2"><br></p>
821 <p class="p1"><b>*cachedBufferAt(server, bufnum)</b></p>
822 <p class="p2"><br></p>
823 <p class="p1">Access a buffer by its number.</p>
824 <p class="p2"><br></p>
825 <p class="p1"><b>*cachedBuffersDo(server, func)</b></p>
826 <p class="p2"><br></p>
827 <p class="p1">Iterate over all cached buffers. The iteration is not in any order, but will touch all buffers.</p>
828 <p class="p2"><br></p>
829 <p class="p2"><br></p>
830 <p class="p1">It may be simpler to access them through the server object:</p>
831 <p class="p2"><br></p>
832 <p class="p1"><b>myServer.cachedBufferAt(bufnum)</b></p>
833 <p class="p1"><b>myServer.cachedBuffersDo(func)</b></p>
834 <p class="p2"><br></p>
835 <p class="p2"><br></p>
836 <p class="p7">b = <span class="s2">Buffer</span>.alloc(s, 2048, 1);</p>
837 <p class="p16"><span class="s2">Buffer</span><span class="s5">.cachedBufferAt(s, 0);<span class="Apple-tab-span"> </span></span>// assuming b has bufnum 0</p>
838 <p class="p7">s.cachedBufferAt(0);<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s6">// same result</span></p>
839 <p class="p7">s.cachedBuffersDo({ <span class="s2">|buf|</span> buf.postln });</p>
840 </body>
841 </html>