ChucK

ChucK is a new (and developing) audio programming language for real-time synthesis, composition, performance, and now, analysis - fully supported on MacOS X, Windows, and Linux. ChucK presents a new time-based, interface that's highly precise and expressive, as well as dynamic control rates, and the ability to add and modify code on-the-fly. It's fun and easy to learn, and offers composers, researchers, and performers a powerful programming tool for building and experimenting with complex audio synthesis/analysis programs, and real-time interactive control.

Ananya Misra has developed an experimental interface to ChucK from Python. You can use this independently of Myro. This page describes the Python-ChucK interface.

ChucK is a specialized audio programming language, to which the sound synthesis part is "outsourced".

Getting started

First, import the Myro and ChucK modules:

>>> from myro import *
>>> from myro.chuck import *

Next, set up the communication and synthesis framework with this initialization function:

>>> initChucK()

If it works, a command window is created (on windows). This is running a ChucK program that will synthesize sound on demand. You may get a pop-up window asking if the system should keep blocking the program; in that case, select "Unblock"! Now test the set-up by writing some sound-generating code in the Python shell:

>>> s = SineWave()
>>> s.connect()

The first line above creates a SineWave generator and assigns it to the variable s.

The second line connects s to your computer's sound output device (speakers or headphones).

NOTE: under Windows, a window may ask you for permission to connect. You only need to select unblock once.

As a result of making the connection, you hear a sine tone playing on and on. It sounds a little like the Myro beep(), except that it keeps going until you make it stop. How do you make it stop? By disconnecting it from your sound output device.

>>> s.disconnect()

Besides connecting and disconnecting the SineWave generator, you can also modify it in some ways. For example, try:

The setGain() function changes the sound's gain, which is closely related to its loudness. A higher gain results in a louder sound. A lower gain results in a softer sound. A 0.0 gain results in silence even though s has not been disconnected -- it has been muted.

Another way to modify the sound is to change its frequency... while the sound is playing!

Listen to the result of this while loop and think of ways to modify it. How can you make it change the frequency more often? By greater amounts? Write some code that randomly changes the frequency of the SineWave 10 times per second (i.e. once every 0.1 seconds).

More instruments

Because the SineWave generates sound, we think of it as a type of instrument. But we have many other instruments too. Each of them lets you setFrequency() and setGain(), but many allow further changes more suitable to the specific instrument. For example, a mandolin can be plucked, or a saxophone can be blown into. Try this:

>>> m = Mandolin()
>>> m.connect()

This creates a virtual mandolin, assigns it to the variable m, and connects it to the sound output device. But unlike with the SineWave, at this point you still don't hear anything. This is because a mandolin won't make sound until you do something to it -- specifically, you can pluck it:

>>> m.pluck(0.2)
>>> wait(1)
>>> m.pluck(1.0)

The pluck() function works for mandolins or other pluckable instruments. It takes a value between 0.0 and 1.0, which represents how hard you are plucking the string.

Because many instruments don't make sound until you do something to them, we have two more functions that work for all instruments:

noteOn(): start playing a note

noteOff(): stop playing a note

Each of these takes an argument between 0.0 and 1.0, representing the strength or velocity of the noteOn or noteOff operation. For example, try:

setFrequency(freq): set frequency to the given value (freq is in Hertz)

These are enough to get you started on any of the available instruments. (Currently available: SineWave, Mandolin, FMVoices, Voice, PluckedString, Sitar, Shakers, Saxophone, MoogSynthesizer, StruckBar, BlowBottle, BlowHole, and Bowed.)

But in case you want even more control on how the result sounds, many instruments allow more specific operations in addition to the six operations listed above. The additional operations for each instrument are included in the list below.

List of instruments + more specific operations

These are the instruments currently available, and the additional operations they allow.

Note that some parameters are best understood by trying them out with different values and listening to the result. They are fun to play with, even without having a clear theoretical idea of what they mean. So, have fun!

SineWave

A sinusoidal oscillator or sine-wave generator (SinOsc in ChucK)

No additional operations

Example:

>>> sw = SineWave()
>>> sw.connect()

Mandolin

A mandolin

pluck(strength): pluck the mandolin (0.0 <= strength <= 1.0)

Example:

>>> m = Mandolin()
>>> m.connect()
>>> m.pluck(1)

FMVoices

A voice synthesizer

setVowel(vowel): set the vowel given a numerical value (0.0 <= vowel <= 1.0)

Orchestrating

After you get familiar with a single instrument, then you might want to try putting together instruments. To make this easier, you can make individual functions, each responsible for a single instrument.