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!
0 Comments
In Learning Modular Synthesis: Part 1, I presented a block diagram illustrating the signal flow of several elements. We looked at representations of that block diagram in 3 different applications simulating a Eurorack modular synthesizer. While each application has a particular workflow, knowledge of modular signal flow is applicable to all 3. This same knowledge is useful if we are to write Patch 1 as text-based 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/).
If you're not familiar with the ChucK music programming language, no worries! I'll walk you through this program, line by line. But before I do, you might ask, "how is this code related to the Patch 1 block diagram?" The block diagram from Patch 1 illustrates a higher level of abstraction, in which the blocks and the interconnectivity between them show a general overview of the system. The block diagram doesn't contain details about each step of the sequence. The code above, however, illustrates each stage of the MIDI sequence, representing a lower level of abstraction.
This program requires setup, which I start on line 4. On this line I create an object called sine, from the unit generator (UGen) class in ChucK called SinOsc, and connect it directly (via the ChucK operator =>) to the dac. Next, I declare and initialize an array called cMajorScale[] on line 6, which contains the MIDI notes for the C Major scale. Lines 8-13 is a loop and will repeat the number of times there are notes in the array, so 8 times. Lines 9-12 run with each iteration of the loop. On line 9, I'm printing to the console each iteration number and the corresponding MIDI note number. You can see the console output below:
On line 10, I call the mtof() function from the Std class to convert the MIDI notes to frequency. I chuck this to the sine oscillator (sine.freq). On line 11, I control the amplitude of each note played by chucking an amount of 1.0 (full amplitude) to the sine oscillator (sine.gain). Finally, I chuck a note duration of 1.0 second to now, meaning that upon run, each note will play for a duration of 1 second. This also means that each iteration of the loop lasts for 1 second. This result is a sequenced performance of the C Major Scale.
The ChucK operator (=>) and the idea of "chucking" are similar to patching. However here, instead of chucking to the next element in the signal chain, we're chucking control values to an object, the sine oscillator, to modify its connection to the dac. |
WELCOME TO
|