In Learning Modular Synthesis: Part 2, I presented a block diagram illustrating the signal flow of several elements, notably a filter. We looked at representations of that block diagram in 3 different applications simulating a Eurorack modular synthesizer. Even though each application has unique aspects to its workflow, we can patch in all 3 environments with our developing knowledge of modular signal flow. Lets see how we can apply this knowledge to code!
Below (view content in browser to see code example) is an example utilizing the elements in the block diagram, programmed in ChucK (https://chuck.cs.princeton.edu/).
To better accentuate the effects of the filter, I chose to use a square wave for this example rather than a sine wave. On line 5, I create UGen objects for the square-wave oscillator (sqr), low-pass filter (lpf), and digital-to-analog converter (dac). The ChucK operator (=>) resembles a patch cable between the UGens! If you're coming from an analog/hardware modular background (or even guitar with a pedal board), this is a welcome sight! A word of caution though, the ChucK operator isn't intended to explicitly represent voltage signals, which is why we see multiple uses of the ChucK operator.
On lines 6 and 7 I set the parameters for the lpf. The .freq method sets the cutoff frequency. The same method is used in other UGen filters to target frequencies, like the HPF (high-pass filter) and BPF (band-pass filter). The .Q method is also used in other filter types. The .Q sets the resonance amplitude. Q or "quality" has broad applications in audio. It is used in parametric equalizers to set the width of a frequency band. That's not the use here, so don't confuse them.
I declare and initialize an array called cMajorScale on line 10, which contains the MIDI notes for the C Major scale. Lines 12-17 is a for loop and will repeat the number of times there are notes in the array, so 8 times. On line 13, I'm printing each iteration number and the corresponding MIDI note number to the console. On lines 14 and 15, I've used the .freq and .gain methods to map the frequencies and set the amplitude respectively to the sqr oscillator. Finally, I've chucked 1 second to now for the duration of each note.
Thanks for reading and stay tuned for Learning Modular Synthesis: Part 3!
This is a simple Python program for a BBC micro:bit microcontroller that selects random notes from a list to create a I chord when button A is pushed and a V chord when button B is pushed in the key of CM (view content in browser to see code example). All you need for this program is a micro:bit and a power source. The program makes use of the music and random micro:bit libraries. Flash it to your micro:bit and give it a try!