[chuck-users] From 4Hz to 400Hz

Jordan Orelli jordanorelli at gmail.com
Sun Jul 17 10:33:42 EDT 2011


Yup, you can do that sort of thing.  Here's an exceptionally naive implementation of what you've asked for using Impulses.  This should get you started.  The Voice.Voice function will create new voices, so you can add them as you see fit.  The supplied example usage gives a 3/2 polyrhythm that is initially panning separately.  Press "d" on the keyboard to double their rates, "h" to halve them, "i" to pan "inside" (that is, reduce how much they are panning so that they are brought "closer" to one another), and "o" to pan "outside" (i.e., increase their separation).

this isn't a particularly good solution (e.g. mashing "d" a bunch of times will crash this) or an example of a great way to write ChucK, it's just food for thought.  There's more efficient ways to do similar things, but this should provide a general overview of a few common techniques like working with static data, writing concurrent code, syncing beats to global time, taking keyboard input, and using ChucK in an object-oriented fashion.  Tested in MiniAudicle with ChucK version on OS X 10.6.7.




class Voice
    1.0 => static float multiplier;
    1.0 => static float spread;
    int invertPan;
    float freq;
    float pan;
    Impulse imp;
    Pan2 p;

    fun static Voice Voice(float freq, float pan)
        Voice v;
        freq => v.freq;
        pan => v.pan;
        spork ~ v.cycle();
        return v;

    fun static void increaseSpread()
        Math.min(1.0, spread + 0.05) => spread;

    fun static void decreaseSpread()
        Math.max(0.0, spread - 0.05) => spread;

    fun void cycle()
        float targetFreq;
        dur targetBeat;
        imp => p => dac;
            freq * multiplier => targetFreq;
            1::second / targetFreq => targetBeat;
            targetBeat - (now % targetBeat) => now;
            pan * spread => p.pan;
            1.0 => imp.next;

fun void keyboardListener()
    Hid hi;
    HidMsg msg;
    0 => int device; // the device number for the keyboard.
                     // It's generally either 0 or 1.  For me it's 0.
    if(!hi.openKeyboard(device)) me.exit();
    <<< "keyboard '" + hi.name() + "' ready", "" >>>;
        hi => now;
                if(msg.ascii == 68) // d
                    2 *=> Voice.multiplier;
                else if(msg.ascii == 72) // h
                    2 /=> Voice.multiplier;
                else if(msg.ascii == 73) // i
                else if(msg.ascii == 79) // o

Voice.Voice(3.0, -1);
Voice.Voice(2.0, 1);
spork ~ keyboardListener();
while(true) { 100::ms => now; }

On Jul 17, 2011, at 3:02 PM, Rustom Mody wrote:

> Just compiled chuck -- its power seems quite exciting!
> Why I am looking at chuck:
> I am preparing to give a talk on the wider ramifications of music.
> One of the things I wish to demonstrate is that things that look different are often merely analogs but at different scales.
> eg if something vibrates at 400Hz we hear a sound of A-flat. If it 'vibrates' at 4 Hz we hear a beat.
> In the same analogy a 2 vs 3 poly-rhythm (should?) change to a do-so chord. And so on.
> Or stated in reverse:
> Say I have a rhythm in 4/4 time -- 4 even quarter notes, bar repeating every second played by say a click. [What kind of click I am not very sure; sharp with few harmonics would be best I expect]
> Now if there were some (realtime) way of sliding the tempo from 1 sec to millisec I expect the separate clicks would vanish into a hum at some stage.
> This (and other such experiments) is what I want to demo.
> Can I do this with chuck/miniaudicle?
> PS. I have some issues with my setup which I will post separately.
> But first I need to know whether I am using the right tool.
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users

More information about the chuck-users mailing list