Section II: Digital Synthesis 

9 -Sound, Writing Audio to a File 

When discussing visual arts we use terms such as color, shape, texture, and brightness. There are similar terms for describing sounds. They are frequency, amplitude, and timbre. Phase rarely changes the character of a single sound, but it is important in describing how several sounds interact. 

Frequency 

Type the code below into and open SC window and run it (after starting the server). The scope message uses the function containing the SinOsc and plays the graph it generates. It also shows a graphic representation of the sound in a new window13. The peaks represent the speaker moving out and the valleys are when the speaker is moving in. The graph you see in the scope is an actual representation of how the speakers move. As the speakers move they compress and rarify the air, creating sound waves. 

9.1. SinOsc 

{SinOsc.ar([500, 500], 0, 0.4, 0)}.scope(2)

The first argument for SinOsc.ar is freq, set to [500, 500], an array with two values meaning the SinOsc will generate a tone at 500 Hz in both left and right channels. When an array is used as an argument in a patch the first value is for the left channel and the second for the right. If you change the frequency of one or the other to 1000 you should see more waves in that channel in the scope. You will also hear a higher pitch. 

The musical term for frequency is pitch. Frequency is what makes a C4 different from a G6. More waves in the scope mean a higher frequency. 

Try changing the frequency (first argument) to values between 10 and 20000. How does the sound change? What range of frequencies, low and high, can you hear? 

What happens if you try values below 10? You may not hear a frequency, but you might be able to see the speaker cones move back and forth. This is called low frequency. Frequencies below 10 Hz are often used in patches as controls. We will discuss that later. 

This window can be moved and resized. It also becomes the "focus" or front window. To quickly switch back to the code window press command-`. 

Amplitude 

We can use the same example to examine amplitude. The musical term for amplitude is volume, or dynamics. Frequency was evident in the scope by the number of waves. 
Amplitude will be seen as the height or size of the wave. A larger wave means the speakers will move farther forward and back, compressing the air more, which translates into greater volume. 

Look at the help file again for SinOsc. It shows that the arguments are: freq, phase, mul, add. We used the freq argument to change frequency. The mul argument scales or multiplies the output making the wave move higher and lower. The default value for mul is 1.0. This means the sound wave will be 1 at its highest point and -1 at its lowest point. The range of 1 to –1 is the maximum amplitude the system can manage. Before you start this example you might want to turn the audio on the computer down, or remove the headsets. 

9.2. mul, or amplitude 

{SinOsc.ar(500, 0, 1.0)}.scope(1)

Stop the sound (command-period) and try changing the mul to values between 0.1 and 0.9 and run it again. The size of the wave will change, and the amplitude will correspond. What happens if you exceed 1.0? 

Values greater than 1 are too high and inappropriate for volume. Below is an illustration of output saturation, clipping (the tops of the waves are clipped), or distortion. Distortion is not necessarily bad. Rock and Roll was built on distorted guitars. Distortion originated from driving amplifiers beyond their capacity in an attempt to meet the demands of large halls and the power of rock. Eventually it became a signature sound and components were built to electronically imitate what engineers had previously avoided. Wave distortion is a category 
of synthesis. It's just often not what you intend. 

9.3. distortion 

{SinOsc.ar(500, 0, 2.0)}.scope(1)

If you want a distorted sound there are better ways than using excessive values for amplitude. In analog studios you might damage equipment. In digital realms it is not as dangerous, (you won't damage the program), but you compromise the sound. More importantly you give away your lack of experience. A clipped signal is telling. 

Periods, Shapes and Timbre 

The example below shows a sound source that we do not perceive as pitch. 

9.4. noise 

{WhiteNoise.ar(0.7)}.scope(1)

The reason we do not hear a pitch is that there is no pattern (at least that we can perceive) to the sound. With the sine wave you probably noticed that it moved smoothly from 0, to 1, 0, 1, 0 then repeated that shape. A sound that has any type of repeated pattern is periodic. Each revolution through the pattern is called a period, wave or cycle. A sound with no pattern is aperiodic. Periodic waves have pitch. 

The shape of the SinOsc was a smooth motion up and down (like a circle stretched out over time). But a periodic wave with any shape will be heard as a pitch, as illustrated in a previous chapter. 

Frequency is pitch, size of the wave or amplitude is volume, and wave shape is timbre. We will discuss timbre later, but for now understand that different shapes of waves generate different timbres. In general, waves with sharp changes in direction are brighter timbres. Here are some examples. Use the mouse (top to bottom) to hear a different wave. You can resize the scope. The wave you hear is on top. The others are playing back on different busses, or channels (covered later). 

9.5. wave shapes 

(
{Out.ar(0, In.ar(MouseY.kr(3, 12).div(1), 1)*0.8)}.play;
{Out.ar(4, [SinOsc.ar, Saw.ar, Pulse.ar, 
	LFTri.ar, LFNoise0.ar, Dust.ar(100), 
	PinkNoise.ar, WhiteNoise.ar])}.scope(12)
)

NB The above does not seem to work correctly.

Phase 

In most cases the quality of sound is not affected by changes in phase, but it's an important concept in understanding how timbre, phase cancellation, and constructive or destructive interference work. Not many oscillators in SC have a phase argument, but SinOsc does. Here is the line we started with. 

9.6. phase 

{SinOsc.ar(500, 0, 0.7)}.scope(1)

The second argument (0) is phase. The first window (these examples are from and SC2 file, but still illustrate the concept) below shows a phase of 0. The second window shows a wave that is 180 degrees out of phase. 

If this argument is changed to values between 0 and 3.14 (pi) the wave will begin at the corresponding point of its cycle, but it will not have any affect on sound. Phase is most evident when using a wave as a control (describe later) or when two waves interact, moving in and out of phase. 

Recording (Writing to a File) 

The first half of this text focuses on synthesis, using SC as a slave for experiments. SC can organize and orchestrate collections of patches or MIDI events into entire works. It does this by sending commands to the servers. In fact these tools are revolutionary and will change (imho) the way we compose electronic music. But for now we will take a classic approach to composition where sounds created on analog synthesizers were recorded then used as raw material, a palette for compositional collage. The formal composition took place on the recording equipment. So our goal for the first section is to generate interesting sounds with patches, record them, then import them into a digital editor such as ProTools, and organize the sounds there. 

We could connect the output of one computer to another and record in ProTools, but there is a simpler method. On each of the servers there is a button that toggles prepare rec, rec, and stop. This records or writes audio to a file using default settings. The defaults are 44.1k, 32 bit, stereo, with a unique auto-generated name in the recordings folder in the SC folder. That file can be imported into ProTools and used for compositions. 

If you want to change the depth, number of channels or file name I suggest you use command lines, shown below, rather than the record button as this seems to override your file names. If you just enter a file name with no path it will be saved in the SC folder. NB: files are overwritten without warning. If you want to save it in other locations you use a pathname. Folders included in a pathname must already exist. 

9.7. Record bit depth, channels, filename 

s.recSampleFormat = "int16";
s.recChannels = 1;

// saves file in the SC folder, will be overwritten if repeated
s.prepareForRecord("audio1"); 

// or saved in recordings folder of SC folder
s.prepareForRecord("recordings/audio1") 

// or saved in Music folder (replace students with your user name)
s.prepareForRecord("/Users/students/Music/audio1");

// Then to record, don't use the button, but this:
// Before running these lines go back and run a previous example
// so you have something to record.

s.record

// Then
s.stopRecording

Practice 

Electronic music has always been fun for me. I hope this text will be informative and enjoyable. At the end of each chapter is an example of practical application. The code will be more complicated, maybe out of reach, but my intention is not pedagogical. You can ignore the parts we haven't discussed or look up the help file. Hopefully they are more of what digital synthesis should be; discovering new sounds. Just have fun. 

The patch below uses three ugens to generate sound: an LFNoise1,a SinOsc and an LFSaw. They are linked in a rather complicated way. You can experiment as you like, changing the values for each argument, but the range of sweep should be greater than the range of overall wandering. The max delay should always be greater than the actual delay. The decay time is how long the echo resonates. Have fun. 

9.8. Practice (CombN, SinOsc, abs, LFNoise1, LFSaw, array) 

(
   // Double click the parenthesis above to quickly select 
	// the entire patch 
	// Or use com-shift-b
{
i = SinOsc.ar( //Sine wave osc
		abs( //This protects against negative values
			LFNoise1.kr(
				0.5, //frequency overall wandering 
				2000, //range of overall wandering
				LFSaw.kr(
					[1.5, 1.91], //left and right channel
							//speed of the individual sweeps 
					mul: 50, //depth of sweep 
					add: 500 //range of sweep 
				)
			)
		), 
		0, 
		0.1 //volume, stay below 0.2
	);
	//delay
	CombN.ar(i, 
		3.0, //max delay 
		1.35, //actual delay, stay below max delay
		6, //delay decay
		add: i
	)
}.play

)

9. Exercises 
9.1. What are the three dimensions of sound? 
9.2. Of these two waves, which will have a higher pitch? which will be louder? which will have a brighter sound? 
9.3. What is the lowest frequency a human can hear? 
9.4. Of these two waves, which is periodic? Which will be heard as a pitch? 
9.5. How is a signal affected when amplitudes exceed 1.0? 
9.6. The shape of a wave correlates with which quality of sound?