-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlaying_an_audio_file.tex
31 lines (24 loc) · 1.64 KB
/
Playing_an_audio_file.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
\section{Playing an audio file}
First, you have to load the sound file into a buffer. The second argument to \texttt{Buffer.read} is the path of your sound file between double quotes. You will need to change that accordingly so that it points to a WAV or AIFF file on your computer. After buffers are loaded, simply use the \texttt{PlayBuf} UGen to play them back in various ways.
\bigskip
\todo[inline, color=green!40]{ TIP: A quick way to get the correct path of a sound file saved on your computer is drag the file onto a blank SuperCollider document. SC will give you the full path automatically, already in double quotes! }
\bigskip
\begin{lstlisting}[style=SuperCollider-IDE, basicstyle=\scttfamily\footnotesize]
// Load files into buffers:
~buf1 = Buffer.read(s, "/home/Music/wheels-mono.wav"); // one sound file
~buf2 = Buffer.read(s, "/home/Music/mussorgsky.wav"); // another sound file
// Playback:
{PlayBuf.ar(1, ~buf1)}.play; // number of channels and buffer
{PlayBuf.ar(1, ~buf2)}.play;
// Get some info about the files:
[~buf1.bufnum, ~buf1.numChannels, ~buf1.path, ~buf1.numFrames];
[~buf2.bufnum, ~buf2.numChannels, ~buf2.path, ~buf2.numFrames];
// Changing playback speed with 'rate'
{PlayBuf.ar(numChannels: 1, bufnum: ~buf1, rate: 2, loop: 1)}.play;
{PlayBuf.ar(1, ~buf1, 0.5, loop: 1)}.play; // play at half the speed
{PlayBuf.ar(1, ~buf1, Line.kr(0.5, 2, 10), loop: 1)}.play; // speeding up
{PlayBuf.ar(1, ~buf1, MouseY.kr(0.5, 3), loop: 1)}.play; // mouse control
// Changing direction (reverse)
{PlayBuf.ar(1, ~buf2, -1, loop: 1)}.play; // reverse sound
{PlayBuf.ar(1, ~buf2, -0.5, loop: 1)}.play; // play at half the speed AND reversed
\end{lstlisting}