[chuck-users] 2 works 1.5 kills chuck

Rustom Mody rustompmody at gmail.com
Thu Jul 21 09:54:06 EDT 2011


On Thu, Jul 21, 2011 at 12:36 PM, <tempjayren at gmail.com> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> what did i break now?
> i snipped the code from the message, though when i ran it it said
> something about an undefined variable.
> i wanted to see what was going on.
>
>
Thanks for looking. The full code is below.
It works as given ie it starts as a 2 vs 3 polyrhythm.
You can speed it up by pressing D until the polyrhythm becomes 2 notes
However if I want to speed up by less than factor of 2 then it breaks.

About 11 lines from the end: the line
2 *=> Voice.multiplier;
if changed to
1.5 *=> Voice.multiplier;

Then it dies after a D and cpu shows 100%
This is debian linux.

There are one or two other enhancements also I would like
Can I make the clicks sound a little different from each other?

Note the full context is on the other thread: Subject: From 4Hz to 400 Hz
---------------------------
class Voice
{
    1.0 => static float multiplier;
    1.0 => static float spread;
    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 void cycle()
    {
        float targetFreq;
        dur targetBeat;
        imp => p => dac;
        while(true)
        {
            freq * multiplier => targetFreq;
            1::second / targetFreq => targetBeat;
            targetBeat - (now % targetBeat) => now;
            pan * spread => p.pan;
            1.0 => imp.next;
        }
    }
}

fun void keyboardListener()
{
    KBHit hi;
    int c;
    int tt;
    while(true)
    {
        hi => now;
        while(hi.more())
        {
        hi.getchar() => c;
            {
                if(c == 68) // D
                    2 *=> Voice.multiplier;
                else if(c == 72) // H
                    2 /=> Voice.multiplier;
            }
        }
    }
}

Voice.Voice(3.0, -1);
Voice.Voice(2.0, 1);
spork ~ keyboardListener();
while(true) { 100::ms => now; }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20110721/99862ce3/attachment.html>


More information about the chuck-users mailing list