Difference between revisions of "ChucK"

From IPRE Wiki
Jump to: navigation, search
m (More instruments)
(More instruments)
Line 89: Line 89:
 
  >>> m.connect()
 
  >>> 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 need to pluck it:
+
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)
 
  >>> m.pluck(0.2)
Line 109: Line 109:
  
 
Try this also with other values in place of 0.8 and 0.2.
 
Try this also with other values in place of 0.8 and 0.2.
 +
 +
To summarize, here is a list of operations that work for any instrument.
 +
 +
It is followed by a list of available instruments with specific operations they allow ''in addition to'' the six operations listed below.
 +
 +
=== Operations for all instruments ===
 +
 +
* '''connect()''': connect to sound output device
 +
* '''disconnect()''': disconnect from sound output device
 +
* '''noteOn(velocity)''': start playing a note / making sound (0.0 <= ''velocity'' <= 1.0)
 +
* '''noteOff(velocity)''': stop playing a note / making sound (0.0 <= ''velocity'' <= 1.0)
 +
* '''setGain(gain)''': set gain to the given value (''gain'' >= 0.0)
 +
* '''setFrequency(freq)''': set frequency to the given value (''freq'' is in Hertz)
 +
 +
=== 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
 +
 +
==== Mandolin ====
 +
A mandolin
 +
 +
* '''pluck(strength)''': pluck the mandolin (0.0 <= ''strength'' <= 1.0)
 +
 +
==== FMVoices ====
 +
A voice synthesizer
 +
 +
* '''setVowel(vowel)''': set the vowel given a numerical value (0.0 <= ''vowel'' <= 1.0)
 +
* '''setSpectralTilt(spectralTilt)''': set spectral tilt (related to loudness) (0.0 <= ''spectralTilt'' <= 1.0)
 +
* '''setAdsrTarget(target)''': set ADSR targets (related to how the sound changes over time) (0.0 <= ''target'' <= 1.0)
 +
 +
==== Voice ====
 +
Another voice synthesizer (''VoicForm'' in ChucK)
 +
 +
* '''setPhoneme(phoneme)''': set the phoneme to the given string value (''phoneme'' in ["eee", "ihh", "ehh", "aaa", "ahh", "aww", "ohh", "uhh", "uuu", "ooo", "rrr", "lll", "mmm", "nnn", "nng", "ngg", "fff", "sss", "thh", "shh", "xxx", "hee", "hoo", "hah", "bbb", "ddd", "jjj", "ggg"])
 +
* '''setPhonemeNumber(number)''': set the phoneme given a number value (0 <= ''number <= 128)
 +
* '''sing(floatValue)''': re-start singing (0.0 <= ''floatValue'' <= 1.0)
 +
* '''quiet(floatValue)''': stop singing (0.0 <= ''floatValue'' <= 1.0)
 +
* '''setVoiced(mix)''': set mix for voiced component of the sound (0.0 <= ''mix'' <= 1.0)
 +
* '''setUnvoiced(mix)''': set mix for unvoiced component of the sound (0.0 <= ''mix'' <= 1.0)
 +
* '''setVoiceMix(mix)''': set voiced/unvoiced mix together (0.0 <= ''mix'' <= 1.0)
 +
* '''setPitchSweepRate(rate)''': set pitch sweep (0.0 <= ''rate'' <= 1.0)
 +
* '''setVibrato(freq, gain)''': set frequency and gain of vibrato (''frequency'' in Hertz, 0.0 <= ''gain'' <= 1.0)
 +
* '''setLoudness(loudness)''': set the perceived loudness (0.0 <= ''loudness'' <= 1.0)
 +
 +
==== PluckedString ====
 +
A Karplus-Strong plucked string model (''StifKarp'' in ChucK)
 +
 +
* '''setPickupPosition(position)''': set pickup position (0.0 <= ''position'' <= 1.0)
 +
* '''setSustain(sustain)''': set the string's sustain (0.0 <= ''sustain'' <= 1.0)
 +
* '''setStretch(stretch)''': set the string's stretch (0.0 <= ''stretch'' <= 1.0)
 +
* '''pluck(strength)''': pluck the string (0.0 <= ''strength'' <= 1.0)
 +
* '''setBaseLoopGain(gain)''': set "base loop gain" (0.0 <= ''gain'' <= 1.0)
 +
 +
==== Sitar ====
 +
A sitar
 +
 +
* '''pluck(strength)''': pluck the string (0.0 <= ''strength'' <= 1.0)
 +
 +
==== Shakers ====
 +
Collisions of multiple independent sound-producing objects
 +
 +
* '''setEnergy(shakeEnergy)''': set shake energy (0.0 <= ''shakeEnergy'' <= 1.0)
 +
* '''setDecay(decay)''': set system decay (0.0 <= ''decay'' <= 1.0)
 +
* '''setObjects(numObjects)''': set number of objects (0 <= ''numObjects'' <= 128)
 +
* '''preset(number)''': change the settings to a preset instrument by number (0 <= ''number'' <= 22). Below is a list of preset instruments and what number to use for each:
 +
** Maraca = 0
 +
** Cabasa = 1
 +
** Sekere = 2
 +
** Guiro = 3
 +
** Water Drops = 4
 +
** Bamboo Chimes = 5
 +
** Tambourine = 6
 +
** Sleigh Bells = 7
 +
** Sticks = 8
 +
** Crunch = 9
 +
** Wrench = 10
 +
** Sand Paper = 11
 +
** Coke Can = 12
 +
** Next Mug = 13
 +
** Penny + Mug = 14
 +
** Nickle + Mug = 15
 +
** Dime + Mug = 16
 +
** Quarter + Mug = 17
 +
** Franc + Mug = 18
 +
** Peso + Mug = 19
 +
** Big Rocks = 20
 +
** Little Rocks = 21
 +
** Tuned Bamboo Chimes = 22
 +
 +
==== Saxophone ====
 +
A saxophone or similar wind instrument (''Saxofony'' in ChucK)
 +
 +
* '''setStiffness(stiffness)''': set reed stiffness (0.0 <= ''stiffness'' <= 1.0)
 +
* '''setAperture(aperture)''': set reed aperture (0.0 <= ''aperture'' <= 1.0)
 +
* '''setPressure(pressure)''': set pressure / volume (0.0 <= ''pressure'' <= 1.0)
 +
* '''setVibrato(vibratoFreq, vibratoGain, noiseGain)''': set frequency and gain of vibrato, and gain of noise component (''vibratoFreq'' in Hertz, 0.0 <= ''vibratoGain'' <= 1.0, 0.0 <= ''noiseGain'' <= 1.0)
 +
* '''setBlowPosition(position)''': set blow position / lip stiffness (0.0 <= ''position'' <= 1.0)
 +
* '''startBlowing(strength)''': start blowing (0.0 <= ''strength'' <= 1.0)
 +
* '''stopBlowing(strength)''': stop blowing (0.0 <= ''strength'' <= 1.0)
 +
* '''setAttackRate(seconds)''': set rate of attack (sound's beginning) in seconds
 +
 +
==== Moog ====
 +
A Moog synthesizer
 +
 +
* '''setFilterQ(floatValue)''': set filter's Q value (0.0 <= ''floatValue'' <= 1.0)
 +
* '''setFilterSweepRate(rate)''': set filter sweep rate (0.0 <= ''rate'' <= 1.0)
 +
* '''setVibrato(freq, gain)''': set frequency and gain of vibrato (''freq'' in Hertz, 0.0 <= ''gain'' <= 1.0)
 +
* '''setAfterTouch(afterTouch)''': set aftertouch (0.0 <= ''afterTouch'' <= 1.0)
 +
 +
 +
 +
'

Revision as of 18:37, 3 November 2008

Setting up ChucK with Myro

ChucK:

  • Download ChucK.
    • On Windows:
      • Get the Windows executable (first link in windows section)
      • Put bin\chuck.exe in c:\windows\system32\ (despite the system's hesitation)
      • You should now be able to run chuck from the command line (e.g. enter "chuck --help")
    • On other platforms:
    • ChucK is a specialized audio programming language, to which the sound synthesis part is "outsourced".


Myro:

  • Upgrade Myro.


SimpleOSC: should come with the upgrade, so these steps are probably not required:

  • Download SimpleOSC library for Python (the very last link on the page)
    • On Windows:
      • Install by typing python setup.py install in the command line, or by copying the osc folder into c:\python2.x\lib\site-packages\
    • On other platforms:
      • Enter python setup.py install in the terminal
    • Open Sound Control (OSC) provides a way to communicate between Python and ChucK.


Getting started

First, import the Myro ChucK module:

>>> 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. The best way to test it is to go ahead and write 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).

As a result, 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:

>>> s.connect() # connect it again first, to hear it
>>> s.setGain(1.0)
>>> wait(0.5)
>>> s.setGain(0.0)
>>> wait(0.5)
>>> s.setGain(0.5)

What would you do expect this to do? What does it do?

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!

>>> s.setFrequency(200)
>>> wait(1.0)
>>> s.setFrequency(400)
>>> wait(1.0)
>>> s.setFrequency(444.5)

The setFrequency() function takes a frequency in Hertz and modifies s to have that frequency. This leads to plenty of fun. For example, what does this code do?

>>> freq = 100.0
>>> while timeRemaining(30):
        s.setFrequency(freq)
        wait(0.2)
        freq = freq * 1.01

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:

>>> x = Saxophone()
>>> x.connect()
>>> x.noteOn(0.8)
>>> wait(1.0)
>>> x.noteOff(0.2)

Try this also with other values in place of 0.8 and 0.2.

To summarize, here is a list of operations that work for any instrument.

It is followed by a list of available instruments with specific operations they allow in addition to the six operations listed below.

Operations for all instruments

  • connect(): connect to sound output device
  • disconnect(): disconnect from sound output device
  • noteOn(velocity): start playing a note / making sound (0.0 <= velocity <= 1.0)
  • noteOff(velocity): stop playing a note / making sound (0.0 <= velocity <= 1.0)
  • setGain(gain): set gain to the given value (gain >= 0.0)
  • setFrequency(freq): set frequency to the given value (freq is in Hertz)

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

Mandolin

A mandolin

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

FMVoices

A voice synthesizer

  • setVowel(vowel): set the vowel given a numerical value (0.0 <= vowel <= 1.0)
  • setSpectralTilt(spectralTilt): set spectral tilt (related to loudness) (0.0 <= spectralTilt <= 1.0)
  • setAdsrTarget(target): set ADSR targets (related to how the sound changes over time) (0.0 <= target <= 1.0)

Voice

Another voice synthesizer (VoicForm in ChucK)

  • setPhoneme(phoneme): set the phoneme to the given string value (phoneme in ["eee", "ihh", "ehh", "aaa", "ahh", "aww", "ohh", "uhh", "uuu", "ooo", "rrr", "lll", "mmm", "nnn", "nng", "ngg", "fff", "sss", "thh", "shh", "xxx", "hee", "hoo", "hah", "bbb", "ddd", "jjj", "ggg"])
  • setPhonemeNumber(number): set the phoneme given a number value (0 <= number <= 128)
  • sing(floatValue): re-start singing (0.0 <= floatValue <= 1.0)
  • quiet(floatValue): stop singing (0.0 <= floatValue <= 1.0)
  • setVoiced(mix): set mix for voiced component of the sound (0.0 <= mix <= 1.0)
  • setUnvoiced(mix): set mix for unvoiced component of the sound (0.0 <= mix <= 1.0)
  • setVoiceMix(mix): set voiced/unvoiced mix together (0.0 <= mix <= 1.0)
  • setPitchSweepRate(rate): set pitch sweep (0.0 <= rate <= 1.0)
  • setVibrato(freq, gain): set frequency and gain of vibrato (frequency in Hertz, 0.0 <= gain <= 1.0)
  • setLoudness(loudness): set the perceived loudness (0.0 <= loudness <= 1.0)

PluckedString

A Karplus-Strong plucked string model (StifKarp in ChucK)

  • setPickupPosition(position): set pickup position (0.0 <= position <= 1.0)
  • setSustain(sustain): set the string's sustain (0.0 <= sustain <= 1.0)
  • setStretch(stretch): set the string's stretch (0.0 <= stretch <= 1.0)
  • pluck(strength): pluck the string (0.0 <= strength <= 1.0)
  • setBaseLoopGain(gain): set "base loop gain" (0.0 <= gain <= 1.0)

Sitar

A sitar

  • pluck(strength): pluck the string (0.0 <= strength <= 1.0)

Shakers

Collisions of multiple independent sound-producing objects

  • setEnergy(shakeEnergy): set shake energy (0.0 <= shakeEnergy <= 1.0)
  • setDecay(decay): set system decay (0.0 <= decay <= 1.0)
  • setObjects(numObjects): set number of objects (0 <= numObjects <= 128)
  • preset(number): change the settings to a preset instrument by number (0 <= number <= 22). Below is a list of preset instruments and what number to use for each:
    • Maraca = 0
    • Cabasa = 1
    • Sekere = 2
    • Guiro = 3
    • Water Drops = 4
    • Bamboo Chimes = 5
    • Tambourine = 6
    • Sleigh Bells = 7
    • Sticks = 8
    • Crunch = 9
    • Wrench = 10
    • Sand Paper = 11
    • Coke Can = 12
    • Next Mug = 13
    • Penny + Mug = 14
    • Nickle + Mug = 15
    • Dime + Mug = 16
    • Quarter + Mug = 17
    • Franc + Mug = 18
    • Peso + Mug = 19
    • Big Rocks = 20
    • Little Rocks = 21
    • Tuned Bamboo Chimes = 22

Saxophone

A saxophone or similar wind instrument (Saxofony in ChucK)

  • setStiffness(stiffness): set reed stiffness (0.0 <= stiffness <= 1.0)
  • setAperture(aperture): set reed aperture (0.0 <= aperture <= 1.0)
  • setPressure(pressure): set pressure / volume (0.0 <= pressure <= 1.0)
  • setVibrato(vibratoFreq, vibratoGain, noiseGain): set frequency and gain of vibrato, and gain of noise component (vibratoFreq in Hertz, 0.0 <= vibratoGain <= 1.0, 0.0 <= noiseGain <= 1.0)
  • setBlowPosition(position): set blow position / lip stiffness (0.0 <= position <= 1.0)
  • startBlowing(strength): start blowing (0.0 <= strength <= 1.0)
  • stopBlowing(strength): stop blowing (0.0 <= strength <= 1.0)
  • setAttackRate(seconds): set rate of attack (sound's beginning) in seconds

Moog

A Moog synthesizer

  • setFilterQ(floatValue): set filter's Q value (0.0 <= floatValue <= 1.0)
  • setFilterSweepRate(rate): set filter sweep rate (0.0 <= rate <= 1.0)
  • setVibrato(freq, gain): set frequency and gain of vibrato (freq in Hertz, 0.0 <= gain <= 1.0)
  • setAfterTouch(afterTouch): set aftertouch (0.0 <= afterTouch <= 1.0)


'