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.

Patterns Lab

Please get started by creating a new blank file in the SuperCollider IDE.

Instruments

In this lab we will be using two instruments to work with patterns:

(
SynthDef(\ping, {
      arg outBus = 0, freq = 440, amp = 0.1, atk = 0.01, 
      sus = 0.1, rel = 0.1, pos = 0;
      var sig, env, numSines = 8;

      sig = SinOsc.ar(freq, mul: amp);

      env = EnvGen.kr(Env.linen(atk, sus, rel), doneAction: 2);

      sig = sig * env;
      sig = Pan2.ar(sig, pos);

      Out.ar(outBus, sig);
}).add;

SynthDef(\pulse, {
      arg outBus = 0, freq = 440, width = 0.5, amp = 0.1, atk = 0.01, dec = 0.1, 
      sLevel = 0.9, rel = 0.1, gate = 1, pos = 0, cutoff = 3000;
      var sig, env;

      sig = Pulse.ar(freq, width, amp);
      sig = MoogFF.ar(sig, cutoff);
      env = EnvGen.kr(Env.adsr(atk, dec, sLevel, rel), gate, doneAction: 2);

      sig = sig * env;
      sig = Pan2.ar(sig, pos);
  
      Out.ar(outBus, sig);
}).add;
)

Please spend a moment examining what each instrument does. To start, copy and paste these instruments into your file. Then test each one of them by creating a Synth to hear how they sound. Note that for the \pulse instrument it uses a sustain gate (.adsr) so you should store the Synth in a variable so you can set its gate to 0 when ready to release.

Simple Patterns

These next few exercises involve just the \ping instrument.

  1. Write a Pbind that plays the following notes in terms of MIDI number: 69, 71 and 72 (corresponds to A, B, and C). Each note should last a half second and have an amplitude of 0.3.

  2. Write a Pbind that plays the following MIDI notes: 71, 73, 74, 76, 78 (corresponds to B, C#, D, E, F#). The notes should cycle through a rhythmic duration of 1, 0.25, 0.5, and 0.25 seconds. Note that the length of these two sequences is asymmetrical. This will create a more complex and interesting melody. Create key-values in the Pbind for the other parameters. Try using randomness with Pwhite to provide an element of unpredictability.

  3. Write a Pbindef that plays the same pattern as the one you wrote in number two. Play this Pbindef on a tempo clock with a beats per minute of 66. Now try updating the pattern in realtime:

    1. Drop all the notes by an octave by setting the key \ctranspose to -12.
    2. Change the rhythmic values to 3 sixteenths, one eighth, and one sixteenth.
    3. Change the notes to the following sequence: 69, 73, 74, 76, 78, 80.
    4. Change the notes back to the original sequence: 71, 73, 74, 76, 78

Patterns with Sustain-Time Envelopes

If you look closely you will notice that the instrument \pulse uses a sustain-time envelope. If you recall, that instrument’s release portion of its amplitude envelope is triggered through its gate. When you use Pbind with an instrument that has a sustain-time envelope, the Pbind will automatically send a gate of 0 to the instrument when the duration is up. Moreover, you can control exactly when that gate release message is sent by using the \sustain key.

Consider the simple pattern below:

(
Pbind(
      \instrument, \pulse,
      \freq, 440,
      \dur, 1,
).play;
)

In this example, a pulse wave is played every second because \dur is set to 1. If you listen to this you will notice that the envelope is released and each synth is freed from the server (check with s.plotTree). You will also notice though that the pulse wave does not last a full second. Why? That is because the \sustain key has a default value of 0.8 which expresses a ratio for how long the envelope should sustain relative to its duration. If we want to hear our notes last the full second then set the sustain to be 1.

(
Pbind(
      \instrument, \pulse,
      \freq, 440,
      \dur, 1,
      \sustain, 1
).play;
)

These next set of exercises use the \pulse instrument:

  1. Write a Pbind that cycles through the midinotes 60, 63, 65. Make them each last a full second and choose reasonable values for the remaining arguments. Randomize the pan position of the sound using Pwhite.

  2. Write three Pbindefs that play the following patterns:

    • Pattern 1: cycles through the MIDI notes 60, 63, 65, 66, 65, 58 with the rhythm eighth note, eighth note, sixteenth note, dotted eighth tied to a quarter, and quarter note.

    • Pattern 2: cycles through the MIDI notes 48, 51 with the rhythm dotted quarter and eighth tied to a half note.

    • Pattern 3: cycles through the MIDI notes 72, 75, 77 all of which are sixteenth notes.

    Each of the three patterns should be quantized to the start of a 4/4 measure. Set the tempo to be 120 bpm. Bring in each pattern one at a time as well.

    Use Pbindefs to update these patterns in real time. Change the amplitude, the envelope shape, width and other aspects of the sound. Specifically for the second pattern which is acting as our bass note change the notes to 53 and 56 at some point and bring them back to 48 and 51. This will give a sense of harmonic motion by changing the underlying chord.

Bach C Major Prelude

In 1968, Wendy Carlos released an album of Bach’s music played through a Moog synthesizer. In one of the stranger turns of events, the album skyrocketed to #10 on the Billboard album charts in US and was one of the main reasons for the growth of synthesized music in popular music. The album was called “Switched-On Bach” and was done using a Moog synthesizer. Check out the Wikipedia page if you are curious.

Here we will try to write our own synthesized Bach. Write a series of Pbinds to loop the first eight measures of Bach’s C Major Prelude. Here is the score for the piece. You will want to create three patterns: one for the half notes, one for sixteenth rest followed by the dotted eighth tied to the quarter, and then one for the six sixteenth notes. Use the \pulse instrument for the first two and the \ping instrument for the six sixteenth notes. Ensure that all the patterns are synchronized. You should also declare a tempo for the piece and set the patterns for the tempo clock. This score has the tempo as 112 bpm which I personally think is way too fast. But it is your artistic choice! Finally send the output of each pattern to a reverb synth. Here is a SynthDef you can use for the reverb.

(
SynthDef(\reverb, {
    arg outBus = 0, inBus, mix = 0.4;
    var dry, wet, sig, numFilters = 8;

    dry = In.ar(inBus, 2);

    wet = dry;
    numFilters.do({
      wet = AllpassN.ar(
        in: wet,
        maxdelaytime: 0.2,
        delaytime: {Rand(0.05, 0.15)} ! 2,
        decaytime: {Rand(1, 2)} ! 2
      );
    });

    wet = LPF.ar(wet, 3500);
    sig = dry.blend(wet, mix);

    Out.ar(outBus, sig);
}).add;
) 

You should think carefully about how to patternize this piece. Where do you see repetitions in both the pitches and the rhythms/rests? Design efficient and simple patterns and use repetition to help you. You should not have one long Pseq that has a list of every midinote number in order. Remember you can embed patterns within each other. For example \Pseq([Pseq([100, 200], 2), Pseq([300, 400], 1)) generates a stream of 100, 200, 100, 200, 300, 400, nil. You also might want to consider looking up the documentation for Pstutter which can help repeat values though it is not required. When you are done, try changing the cutoff frequency of the \pulse instruments using Pseg to give a changing harmonic spectrum.

The specific MIDI notes of each pitch can be found using this chart.

Below is my rendition. Experiment with changing other parameters other than the ones I specifically requested!

Solutions

Solutions to the lab will be posted after the lab is over.

lab_patterns_solns.scd