Lab Goals and Policies
Labs are an opportunity to work together with a partner on exercises to reinforce concepts from lecture and to prepare for problems on the problem sets. A successful lab experience requires each member to contribute equally. In pair programming, one student is the "driver", who controls the keyboard and mouse. The other is the "navigator", who observes, asks questions, suggest solutions, and thinks about slightly longer-term strategies. The two programmers switch roles about every 20 minutes. If you believe your partner is not participating appropriately in pair programming please first address your concerns to your partner, and try to agree on what should be done to make the pair programming more successful. If that approach is not successful, explain the issues to one of your instructors, who will work with you and your partner to improve the situation.
Envelopes
Start a new .scd file and copy the following SynthDef to the top of the file:
(
SynthDef(\bass, {
arg out = 0, freq = 100, amp = 0.2;
var sig, numWaves = 6;
sig = 0;
numWaves.do({
sig = sig + VarSaw.ar(
freq: Rand(freq * 0.995, freq * 1.005),
iphase: Rand(0, 1),
width: Rand(0.1, 0.2),
mul: amp/numWaves
);
});
Out.ar(out, sig ! 2);
}).add;
)
We will be adding some envelopes to this SynthDef to shape the sound but also other
parameters as well. The above SynthDef makes a nice fuzzy bass sound by
summing six VarSaw
together. The width
argument to VarSaw
controls how much
the waveform looks like a triangle wave vs. a sawtooth wave. Each element of the
VarSaw
wave has randomness added to it so that each of the six are unique. The
UGen Rand
selects a random value between some low point and some high point.
As a first step, just write a line of code that create a Synth to playback \bass
.
Set it to different frequencies to hear how it sounds in different parts of the
frequency range.
Step 1: Write an Amplitude Envelope
First copy the original SynthDef \bass
and rename it to be \bassEnv
. Add
an amplitude envelope to the sound that ramps up to full volume over five seconds,
sustains for one seconds, and releases over five seconds. Have the envelope
free the synth when it is done.
For fun create several synths each with different frequencies, for example like 100Hz, 150Hz, or 200Hz. You can create nice, rich chords.
Step 2: Modulate the Width
Next copy your solution to \bassEnv
and rename it to be \bassEnvWidth
. Here
add an envelope generator to the width
argument of VarSaw
. Envelopes do not
always need to be used to control the amplitude of a sound. We can shape
other parameters as well! Here have the envelope ramp from 0.9 to 0.1 over
five seconds, sustain at 0.1 for one second and return to 0.9 over the last
five seconds. Notice here that the width will change in conjunction with the
amplitude. This is a really nice quality to have in a synthesizer. Changing
the width will affect the harmonics of the sound over time. In real instruments,
the harmonics of a sound tend to change with volume as well.
Step 3: Write a Gated Amplitude Envelope
Copy your solutions to the original \bass
SynthDef, not the one from
\bassEnvWidth
, and rename it to \bassADSR
. Try working this time with a
sustain envelope where a gate is used to trigger the onset and to trigger
the release. Use the Env
class method .adsr
to create an ADSR envelope
to the sound. Add arguments to the SynthDef so the user can supply arguments
to control the envelope and, of course, the gate.
Try playing around with different values for ADSR. What does it sound like when the attack is really short, like 0.001 seconds? Can you create a forte-piano attack with a loud attack followed by a soft sustain?
Playing Audio
Download this zip folder that has two songs in it: Missy Elliot’s “Work It” and Heart’s “Barracuda”. Unzip the file. On Macs, you can simply double click on the file. For PC users, you must explicitly unzip the file. Highlight the folder in Windows Explorer and click Extract All. I suggest dragging this unzipped folder into the same folder as your lab files.
Step 1: Load buffers
Write some code to load both sounds into audio buffers on the server. Note that both of these audio files are stereo.
Step 2: Write a SynthDef to Playback A Stereo Buffer
Write a SynthDef called \play
that will playback an audio buffer using PlayBuf
.
Remember that this SynthDef should be playing back stereo audio files. Then, create
a synth to playback each song. I suggest storing the result in a variable because
you will likely want to free it before it is done playing. Note that each audio file
contains the full song. Finally, have PlayBuf free the synth when it is done
playing.
Step 3: Create a Fadein
Next copy your SynthDef for \play
and rename it as \fadeIn
. Here write an
amplitude envelope that will fade in a song over a certain amount of time. Create
an argument for fade-in time so that the user can control how long the fade in
will be. For the fade-in have the audio start at an amplitude of 0.01 and slowly
ramp up 1 across whatever the fade time is specified by the user. Set the curve
here to be exponential. Why exponential? Our perception of volume, like musical
intervals, is roughly logarithmic. Here I recommend testing this with Barracuda
as it is a better candidate for a long fade in.
Step 4: Create a Fadeout
Next copy your SynthDef for \fadeIn
and rename it to \fadeInOut
. Add another
amplitude envelope that can be triggered at any time through a gate to fade out
the song to silence. The fade out should have the same fade time as the fade in.
When the fade out is done, no matter where the song is, the synth should be freed.
Step 5: Create a Record Scratch
A record scratch is a term used by DJ’s that refers to dramatically modulating the playback rate of a song. On a record player, a record rotates around as a needle registers the audio signal stored on the record. DJs would often use their hands to change the rotation speed wildly creating exaggerated percussive noises. These effects can be heard all over the place in Missy Elliot’s “Work It”, especially at the beginning. Also notice the glided sine wave lead playing once the verse starts!
We can simulate this effect quite easily in the digital world. Start by copying your
SynthDef for \play
, not the ones for fading in and fading out, and rename it
\recordScratch
. PlayBuf has an
argument for rate
. Here we will use an envelope to modulate the playback
rate. To create a scratch effect have the envelope quickly ramp down from 1 to 0
and then back up to 1. This envelope should be triggered by the user on request.
You will need a gate to be able to do this. Initially the gate should be 0 but once
the user is ready to trigger the scratch, the gate should be set to 1. To retrigger
the scratch, the user will need to set the gate to be 0 again. Try this with the
Missy Elliot song and add some scratches dynamically as it is being played.
Solutions
Solutions to the lab will be posted after the lab is over.
lab_env_play_solns.scd