Computer Music Synthesis Chapter 7 Based on “Excerpt from Designing Sound” by Andy Farnell Slides by Denny Lin Copyright © 2011 by Denny Lin 1 Pure Data essentials • The following is a collection of patches that implement essential concepts used for mixing, reading and writing files, and sequencing – 7.1 Channel strip – 7.2 Audio file tools – 7.3 Events and sequencing – 7.4 Effects Copyright © 2011 by Denny Lin 2 7.1 Channel strip • These patches consist of various mixer controls: – – – – – – Signal switch Simple level control Log law fader MIDI fader Mute button Panning • Linear, square root, cosine, and MIDI panner – Cross fader – De-multiplexer Copyright © 2011 by Denny Lin 3 Signal switch and direct level control • Both of these patches control audio levels by multiplying the audio signal input • These controls are prone to clicks and zipper noise, which is caused by sudden level value changes on an audio block boundary Copyright © 2011 by Denny Lin 4 Log Law Fader • Sliders are linear (“lin”) by default. Can be changed to logarithmic (“log”) in the slider’s properties • Half of the slider’s output range is compressed into the final ten percent of the movement range Copyright © 2011 by Denny Lin 5 MIDI data scaling • MIDI controller messages are generally linear signals in the range of 0 to 127 • Can be normalized by dividing by 127, or multiplying by 0.0078745 • Normalized output may be: – scaled to a log curve – multiplied by 100, and converted to decibel scale via the dbtorms object (see fig. 7.6) Copyright © 2011 by Denny Lin 6 MIDI Fader • The ctlin object connects the MIDI fader patch to an external MIDI device • Only volume messages from channel 1 can control the spigot • MIDI message is normalized (between 0 and 1), and transformed to an audio signal • 2Hz low-pass filter used to smooth out fader Copyright © 2011 by Denny Lin 7 Mute Button and Smooth Fades • Slider value (0 to 100) is in decibel scale • Fader value is stored in cold inlet of * object • Left inlet of * object gets inverted value of toggle switch • Message data is transformed to audio signal and low-pass filtered to smooth the fader Copyright © 2011 by Denny Lin 8 Panning • The purpose of pan control is to place a monophonic sound source within a listening panorama • Different from balance, which places a stereo sound source fig. 7.10: Linear, square root, sine/cosine panning laws Copyright © 2011 by Denny Lin 9 Linear Panner • Consists of two volume controls, one for each channel (signal source is monophonic) • Fader smoothing achieved by converting messages to audio signal, and low-pass filtering • Cold inlet control directly alters left channel output • Right channel is controlled by the complement of the left channel control value • Problem: When a signal amplitude level of 1 is sent, the perceived loudness at each channel is halved Copyright © 2011 by Denny Lin 10 Square Root Panner • Similar to linear panner • Takes the square root of control signals to produce panning that follows an equal power law • Has a 3dB amplitude increase at the center position • Problem: The square root curve is perpendicular to the xaxis when x is close to 0 and 1. The sound in one of the channels suddenly disappears at the slider’s extreme ends Copyright © 2011 by Denny Lin 11 Cosine Panner • The curve makes a 45 degree angle approach at the edges • Cosine and sine are easier to compute than square root • Tends to mimic placement of sound source on a circle • Problem: The response around center position not as desirable as square root panner Copyright © 2011 by Denny Lin 12 MIDI Panner • Combines the MIDI fader (see fig. 7.5) with a cosine panner • Pan information is sent to MIDI controller number 10 (64 is center position). • Patch only responds to pan information on channel one Copyright © 2011 by Denny Lin 13 Cross Fader • Used to smoothly transfer from one sound source to another by mixing them to a common output • Two inlets are used for signal sources • Third inlet controls the ratio of the mixture • Can be used to control proportion of reverb effect, or to cross fade between two tunes • Constant power fading versions using sine and square root functions are sometimes better Copyright © 2011 by Denny Lin 14 De-multiplexer • Signal source selector to pick one out of several inputs to be routed to the outlet • A number at the inlet selects and bangs the corresponding Boolean message list to the unpack object • The signal~ and 80Hz low-pass filter objects are used to remove clicks Copyright © 2011 by Denny Lin 15 7.2 Audio file tools • The following example patches can be used to record and playback .WAV or .AIFF files: – Monophonic sampler – File recorder – Loop player Copyright © 2011 by Denny Lin 16 Monophonic Sampler • • • • • • • Abstraction used to record and play a few seconds of audio Sounds are recorded into a table that stores 88200 samples (2 seconds, given 44100 samples per second) First inlet gets signal Second inlet controls the gain (clicks are removed with signal and low-pass filter) A bang on the third inlet records the signal into the table A bang on the fourth inlet plays back the recording to the outlet Sampler can be used by connecting an adc~ input object, a gain slider, bang buttons to control record and playback, and a dac~ output object Copyright © 2011 by Denny Lin 17 File Recorder • • • • • Fixed length file recorder abstraction Takes the recording length as first argument (sent to $1), and directory housing the file as second argument (sent to $2) Uses the writesf~ object which takes the signal, and three commands: start recording, stop recording (after delay of $1 ms), and name of file to write A counter tracks the number of times the file recorder was run, and appends the number to the filename via the %d A bang message is sent to the done outlet when the recording has ended. Recording is stopped by the delay object Copyright © 2011 by Denny Lin 18 Loop Player • • • • • • Use this abstraction to play a .WAV or .AIFF file endlessly The openpanel object provides a file dialogue to select a file to play The pack object takes the filename and the $0-a symbol as $1 and $2 items in the read message The soundfiler reads the sound file into the $0-a table. When complete, the number of bytes read is used to trigger a bang message to the tabplay~ object When done playing, the right outlet of tabplay~ sends a bang that is routed via spigot to trigger the tabplay~ object to repeat A zero received on the right inlet stops the spigot object from re-triggering the tabplay~; a one received on the right inlet triggers a bang to play the sound file Copyright © 2011 by Denny Lin 19 7.3 Events and sequencing • The following example patches create time, event, and sequence triggers: – – – – – – – Time base Select sequencer Partitioning time Dividing time Event synchronized Low Frequency Oscillator (LFO) List sequencer Text file control Copyright © 2011 by Denny Lin 20 Time base • This time base abstraction accepts beats per minute • The control inlet activates the metro object, and resets the internal counter whenever the time base is stopped • The second inlet takes beats per minute • The third inlet takes the number of beats per measure (2, 3, 4, 6, etc) • The fourth inlet takes the swing percentage, multiplied by the number of beats per measure, sent to the delay object before the counter increments fig 7.19: A more useful musical time base abstraction with BPM and swing Copyright © 2011 by Denny Lin 21 Select Sequencer • This patch demonstrates that repetitive patterns can be generated with a time base, mod and select objects • Uses the time base abstraction • The mod object wraps the time base counter output to 8 beats, so events within the 0 to 7 range can be triggered • A separate event at time=1024 can be triggered with the select object using the same time base • Instead of bang boxes, note and frequency related objects can be triggered to generate repeating sequences Copyright © 2011 by Denny Lin 22 Partitioning Time • • • • • • Specific events at musical measure numbers can be triggered. This patch ignores events from time 0 to 127 using a chain of moses objects Given time at 208, the first moses object routes the time value to the second moses object Time value is shifted down, treating this section as if this were the beginning of the piece mod 64 creates 2 measures of 64 beats each, in the range 128 - 256 Event at time 208 is beat 80, which would be the second measure of the partitioned timeframe Each of these 64 beat measures can be further subdivided into 4 measures that each contain 16 beats. Each bang box marks the downbeat of the first of 4 measures Copyright © 2011 by Denny Lin 23 Dividing Time • Output from the timebase can be divided to tell which measure the music is at • The time base number is divided by the beats per measure value (2 or 4) • Uses the int object to get whole measure numbers • Uses the change object to remove repeating measure numbers Copyright © 2011 by Denny Lin 24 Event Synchronized LFO • If the time base is to be used as a control signal, dividing the time base using change and int objects could result in several consecutive equal values • Output from the Low Frequency Oscillators (LFOs) becomes choppy • Using higher mod and / values fixes the problem fig. 7.23: Synchronous message LFOs Copyright © 2011 by Denny Lin 25 List Sequencer • • • • • • This list sequencer does not rely on a time base Uses relative time from a message list, so the list {61 0 60 500 59 500} means play note 61 at time 0, then note 60 at time 0 + 500, and note 59 at time 0 + 500 + 500 The list split 2 object processes two items at a time; the remainder of the list is sent to the cold inlet of the list append object First item (note number) is sent to the cold inlet of float object Second item (time value) is sent to a delay object that bangs the note number at the end of the delay time, sending output to the synthesizer The list append object is banged, sending the remainder of the list to the list split 2 object, which processes the next two items. Continues until list is empty fig. 7.24: An asynchronous list sequencer Copyright © 2011 by Denny Lin 26 Synthesizer Part • The patch on the right half of fig. 7.24 is a monophonic synthesizer that accepts MIDI note numbers • The phasor~ output is modified with a 400ms curved envelope fig. 7.24b: Monophonic Synthesizer Copyright © 2011 by Denny Lin 27 Text file control • Text files can be used to store MIDI data. File contains note number and note duration data • The notein object gets MIDI note numbers, and the stripnote removes 0 velocity notes. Note data is sent to the pack object’s hot inlet (first item) • The timer object measures the time the note was pressed, and sends its output to the pack object’s cold inlet (second item) • When the user clicks on start-record, the timer object is reset, the list accumulator is loaded with a bang, and the textfile writer is cleared using a clear message • After the user has finished playing, the write button is banged so that the textfile object writes the performance data from the list append and list prepend set data into the text file using the textfile object. The name of the text file is specified by the write message object • The load-playback button rewinds the textfile to the beginning, and sends it to the monophonic synthesizer Copyright © 2011 by Denny Lin 28 Fig. 7.25: MIDI Sequencer that uses text files to store and play data Copyright © 2011 by Denny Lin 29 7.4 Effects • Two simple effects are introduced: – Stereo chorus and flanger effect – Simple reverberation • Use these effects sparingly • External mixers or plugins may already have better implementations of these effects Copyright © 2011 by Denny Lin 30 Stereo Chorus/Flanger • Produces multitude of sound sources by doubling up several copies of sound using delays • LFOs are always 1Hz apart, and vary between 1Hz and 5Hz • Fig. 7.27 uses the stereo chorus sub-patch and passes the feedback, rate, and depth fig. 7.26: A chorus type effect fig. 7.27: Testing the chorus Copyright © 2011 by Denny Lin 31 Simple Reverberation • Designed to mimic reverberating sounds on 4 surfaces • Minimum delay should be at least a quarter of the reverb time • To avoid phase cancellation and reinforcement between echoes: – Delay times in the delread~ objects should be prime numbers – Amplitude for each buffer output is scaled at different levels • rev1~, rev2~, rev3~ are reverb abstractions fig. 7.28: A re-circulating Schroeder reverb effect Copyright © 2011 by Denny Lin 32