rsc3/doc-schelp/Help-3.12.2/Classes/DiskIn.html

133 lines
7.2 KiB
HTML
Raw Normal View History

2022-08-24 13:53:18 +00:00
<!doctype html><html lang='en'><head><title>DiskIn | SuperCollider 3.9.3 Help</title>
<link rel='stylesheet' href='./../scdoc.css' type='text/css' />
<link rel='stylesheet' href='./../frontend.css' type='text/css' />
<link rel='stylesheet' href='./../custom.css' type='text/css' />
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<script>
var helpRoot = './..';
var scdoc_title = 'DiskIn';
var scdoc_sc_version = '3.9.3';
</script>
<script src='./../scdoc.js' type='text/javascript'></script>
<script src='./../docmap.js' type='text/javascript'></script>
<script src='./../prettify.js' type='text/javascript'></script>
<script src='./../lang-sc.js' type='text/javascript'></script>
</head>
<body onload='fixTOC();prettyPrint()'>
<div id='toc'>
<div id='toctitle'>DiskIn:</div>
<span class='toc_search'>Filter: <input id='toc_search'></span><ul class='toc'><li class='toc1'><a href='#description'>Description</a></li>
<ul class='toc'></ul><li class='toc1'><a href='#classmethods'>Class methods</a></li>
<ul class='toc'><li class='toc3'><a href='#*ar'>ar</a> </li>
<li class='toc2'><a href='#Inherited%20class%20methods'>Inherited class methods</a></li>
</ul><li class='toc1'><a href='#instancemethods'>Instance methods</a></li>
<ul class='toc'><li class='toc2'><a href='#Inherited%20instance%20methods'>Inherited instance methods</a></li>
</ul><li class='toc1'><a href='#examples'>Examples</a></li>
<ul class='toc'><li class='toc2'><a href='#Normal%20usage%20(with%20Buffer;%20"Object%20Style")'>Normal usage (with Buffer; "Object Style")</a></li>
<ul class='toc'></ul><li class='toc2'><a href='#OSC%20Messaging%20Style'>OSC Messaging Style</a></li>
<ul class='toc'></ul></ul></ul></div><div class='contents'>
<div id='menubar'></div>
<div class='header'>
<div id='label'>
<span id='folder'>Classes</span>
| <span id='categories'><a href='./../Browse.html#UGens'>UGens</a>&#8201;&gt;&#8201;<a href='./../Browse.html#UGens>InOut'>InOut</a> | <a href='./../Browse.html#UGens'>UGens</a>&#8201;&gt;&#8201;<a href='./../Browse.html#UGens>Buffer'>Buffer</a></span>
</div><h1>DiskIn<span id='superclasses'> : <a href="../Classes/MultiOutUGen.html">MultiOutUGen</a> : <a href="../Classes/UGen.html">UGen</a> : <a href="../Classes/AbstractFunction.html">AbstractFunction</a> : <a href="../Classes/Object.html">Object</a></span>
</h1>
<div id='summary'>Stream in audio from a file.</div>
</div>
<div class='subheader'>
<div id='filename'>Source: <a href='file:///Applications/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/Audio/DiskIO.sc' title='/Applications/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/Audio/DiskIO.sc'>DiskIO.sc</a></div><div id='related'>See also: <a href="./../Classes/PlayBuf.html">PlayBuf</a>, <a href="./../Classes/DiskOut.html">DiskOut</a></div>
</div>
<h2><a class='anchor' name='description'>Description</a></h2>
<p>Continuously play a longer soundfile from disk. This requires a buffer to be preloaded with one buffer size of sound.<h2><a class='anchor' name='classmethods'>Class Methods</a></h2>
<h3 class='method-code'><span class='method-prefix'>DiskIn.</span><a class='method-name' name='*ar' href='./../Overviews/Methods.html#ar'>ar</a>(<span class='argstr'>numChannels</span>, <span class='argstr'>bufnum</span>, <span class='argstr'>loop: 0</span>)</h3>
<div class='method'>
<p><h4>Arguments:</h4>
<table class='arguments'>
<tr><td class='argumentname'>numChannels<td class='argumentdesc'>
<p>Number of channels. This must match the number of channels in the buffer.<tr><td class='argumentname'>bufnum<td class='argumentdesc'>
<p>Buffer number<div class='note'><span class='notelabel'>NOTE:</span> The Buffer's numFrames must be a power of two and is recommended to be at least 65536 -- preferably 131072 or 262144. Smaller buffer sizes mean more frequent disk access, which can cause glitches.</div><tr><td class='argumentname'>loop<td class='argumentdesc'>
<p>If set to 1, the soundfile will loop.<div class='note'><span class='notelabel'>NOTE:</span> If the buffer has a larger number of frames than the sound file there will be a noticeable gap between the first and the following loop iterations. In that case chose a smaller buffer size or use <a href="./../Classes/PlayBuf.html">PlayBuf</a> instead</div></table><h4>Discussion:</h4>
<p>This UGen will set the <a href="./../Classes/Done.html">'done' flag</a> when finished playing.</div><h3><a class='anchor' name='Inherited%20class%20methods'>Inherited class methods</a></h3>
<div id='inheritedclassmets'></div><h2><a class='anchor' name='instancemethods'>Instance Methods</a></h2>
<h3><a class='anchor' name='Inherited%20instance%20methods'>Inherited instance methods</a></h3>
<div id='inheritedinstmets'></div><h2><a class='anchor' name='examples'>Examples</a></h2>
<pre class='code prettyprint lang-sc'>s.boot; // start the server
// examples below will use this synthdef
(
SynthDef("help-Diskin", { |out, bufnum = 0|
Out.ar(out, DiskIn.ar(1, bufnum));
}).add
)</pre>
<h3><a class='anchor' name='Normal%20usage%20(with%20Buffer;%20"Object%20Style")'>Normal usage (with Buffer; "Object Style")</a></h3>
<pre class='code prettyprint lang-sc'>b = Buffer.cueSoundFile(s, Platform.resourceDir +/+ "sounds/a11wlk01-44_1.aiff", 0, 1);
x = { DiskIn.ar(1, b.bufnum) }.play;
b.close;
// again
// note the like named instance method, but different arguments
b.cueSoundFile(Platform.resourceDir +/+ "sounds/a11wlk01-44_1.aiff", 0);
x.free; b.close; b.free;
// loop it (for better looping use PlayBuf!)
(
p = Platform.resourceDir +/+ "sounds/a11wlk01-44_1.aiff";
a = SoundFile.new;
a.openRead(p);
d = a.numFrames/s.sampleRate; // get the duration
a.close; // don't forget
b = Buffer.cueSoundFile(s, p, 0, 1);
f = { DiskIn.ar(1, b.bufnum) };
x = f.play;
r = Routine({
loop({ d.wait; x.free; x = f.play; b.close( b.cueSoundFileMsg(p, 0)) });
}).play; )
r.stop; x.free; b.close; b.free; // you need to do all these to properly cleanup
// cue and play right away
(
SynthDef("help-Diskin", { |out, bufnum = 0|
Out.ar(out, DiskIn.ar(1, bufnum));
}).add;
)
(
x = Synth.basicNew("help-Diskin");
m = { arg buf; x.addToHeadMsg(nil, [\bufnum, buf.bufnum])};
b = Buffer.cueSoundFile(s,Platform.resourceDir +/+ "sounds/a11wlk01-44_1.aiff", 0, 1, completionMessage: m);
)</pre>
<h3><a class='anchor' name='OSC%20Messaging%20Style'>OSC Messaging Style</a></h3>
<pre class='code prettyprint lang-sc'>// allocate a disk i/o buffer
s.sendMsg("/b_alloc", 0, 65536, 1);
// open an input file for this buffer, leave it open
s.sendMsg("/b_read", 0, Platform.resourceDir +/+ "sounds/a11wlk01-44_1.aiff", 0, 65536, 0, 1);
// create a diskin node
s.sendMsg("/s_new", "help-Diskin", x = s.nextNodeID, 1, 1);
s.sendMsg("/b_close", 0); // close the file (very important!)
// again
// don't need to reallocate and Synth is still reading
s.sendMsg("/b_read", 0, Platform.resourceDir +/+ "sounds/a11wlk01-44_1.aiff", 0, 0, 0, 1);
s.sendMsg("/n_free", x); // stop reading
s.sendMsg("/b_close", 0); // close the file.
s.sendMsg("/b_free", 0); // frees the buffer</pre>
<div class='doclink'>helpfile source: <a href='file:///Applications/SuperCollider.app/Contents/Resources/HelpSource/Classes/DiskIn.schelp'>/Applications/SuperCollider.app/Contents/Resources/HelpSource/Classes/DiskIn.schelp</a><br>link::Classes/DiskIn::<br></div></div></body></html>