Bruno Ruviaro added UGens.tex  almost 10 years ago

Commit id: b89fc51d7d0bfd1d30387fb26388d4607191cf35

deletions | additions      

         

\section{UGens}  You have already seen a few Unit Generators (UGens) in action in sections \ref{sec:first-sine} and \ref{sec:nesting}. What is a UGen? A unit generator is an object that generates sound signals or control signals. There are many classes of unit generators, all of which derive from the class UGen. \texttt{SinOsc} and \texttt{LFNoise0} are examples of UGens. For more details, look at the Help files called ``Unit Generators and Synths,'' and ``Tour of UGens.''   The default piano-like synth used by Pbinds you wrote up to know is made of a combination of unit generators.\footnote{Since you used \texttt{Pbind}s to make sound in SuperCollider so far, you may be tempted to think: \textit{``I see, so the \texttt{Pbind} is a Unit Generator!''} That's not the case. \texttt{Pbind} is not a Unit Generator---it is just a recipe for making musical events (score). \textit{``So the \texttt{EventStreamPlayer}, the thing that results when I call \texttt{play} on a \texttt{Pbind}, THAT must be a UGen!''} The answer is still no. The \texttt{EventStreamPlayer} is just the player, like a pianist, and the pianist does not generate sound. But the piano---the \emph{instrument}---does. So in keeping with our metaphor, the \emph{instrument piano} is the thing that actually vibrates and generates sound, and that is a more apt analogy for a UGen. When you made music with \texttt{Pbind}s earlier, SC would create an \texttt{EventStreamPlayer} to play your score with a built-in piano synth. You didn't have to worry about creating the piano or any of that---SuperCollider did all the work under the hood for you. That hidden piano synth is made of a combination of a few Unit Generators.} You will learn how to combine unit generators to create all sorts of electronic instruments with synthetic and processed sounds. The next example builds up from your first sine wave to create an electronic instrument that you can perform live with the mouse.  \subsection{Mouse control: instant Theremin}  Here's a simple synth that you can perform live---it is a simulation of the Theremin, one of the oldest electronic music instruments:  \begin{lstlisting}[style=SuperCollider-IDE, basicstyle=\scttfamily\footnotesize]  {SinOsc.ar(freq: MouseX.kr(300, 2500), mul: MouseY.kr(0, 1)}.play;  \end{lstlisting}  If you don't know what a Theremin is, please stop everything right now and search for ``Clara Rockmore Theremin'' ou YouTube. Then come back here and try to play the Swan song with your SC Theremin.  \texttt{SinOsc}, \texttt{MouseX}, and \texttt{MouseY} are UGens. \texttt{SinOsc} is generating the sine wave tone. The other two are capturing the motion of your cursor on the screen (X for horizontal motion, Y for vertical motion), and using the numbers to feed frequency and amplitude values to the sine wave. Very simple, and a lot of fun.  \subsection{Saw and Pulse; plot and scope}  The theremin above used a sine oscillator. There are other waveforms you could use to make the sound. Run the lines the below---using the convenient \texttt{plot} method---to look at the shape of \texttt{SinOsc}, and compare it to \texttt{Saw} and \texttt{Pulse}. Then rewrite your theremin line replacing \texttt{SinOsc} with \texttt{Saw}, then \texttt{Pulse}. Listen how different they sound.   \begin{lstlisting}[style=SuperCollider-IDE, basicstyle=\scttfamily\footnotesize]  { SinOsc.ar }.plot; // sine wave  { Saw.ar }.plot; // sawtooth wave  { Pulse.ar }.plot; // square wave  \end{lstlisting}  The lines above won't make sound---they just let you visualize a snapshot of the waveform. Now try \texttt{.scope} instead of \texttt{.play} in your theremin code, and you will watch a representation of the waveform in real time (a ``Stethoscope'' window will pop up).