Chuck Audio Programming

March 15, 2012
by admin

    As one of my elective classes I am taking a class Digital Sound Synthesis.  The class covers the theory of sound synthesis and has been using the c++ program CHUCK.  The first couple practice problems have been basic sin oscillators and creating any melody we like.  Lately we have been working on filters and physical modeling. Using a TwoPole filter with an impulse train I recreated (at least tried to) flicking a wine glass.  I modeled around 20 frequencies with their impulse and decay rates to try and recreate the sound.  The code is at the bottom and you can hear the recording and my synthesis below.

    Recorded Wine Glass

    Synthesized Wine Glass

    Chuck Code:

    Impulse i1 => TwoPole m1 => dac;
    Impulse i2 => TwoPole m2 => dac;
    Impulse i3 => TwoPole m3 => dac;
    Impulse i4 => TwoPole m4 => dac;
    Impulse i5 => TwoPole m5 => dac;
    Impulse i6 => TwoPole m6 => dac;
    Impulse i7 => TwoPole m7 => dac;
    Impulse i8 => TwoPole m8 => dac;
    Impulse i9 => TwoPole m9 => dac;
    Impulse i10 => TwoPole m10 => dac;
    Impulse i11 => TwoPole m11 => dac;
    Impulse i12 => TwoPole m12 => dac;
    Impulse i13 => TwoPole m13 => dac;
    Impulse i14 => TwoPole m14 => dac;
    800=>m14.freq;
    0.99997=>m14.radius;
    Impulse i15 => TwoPole m15 => dac;
    2000=>m15.freq;
    0.9999=>m15.radius;
    .05 => i15.next;
    Impulse i19 => TwoPole m19 => dac;
    2000=>m19.freq;
    0.9999=>m19.radius;
    .05 => i19.next;
    Impulse i20 => TwoPole m20=>dac;
    2000=>m20.freq;
    0.9999=>m20.radius;
    .05 => i20.next;
    Impulse i16 => TwoPole m16 => dac;
    Impulse i17 => TwoPole m17 => dac;
    Impulse i18 => TwoPole m18 => dac;
    15000 => m16.freq;
    16000 => m17.freq;
    17000=>m18.freq;
    .9985 => m16.radius;
    .9985 => m17.radius;
    .9985 => m18.radius;
    .05 => i16.next;
    .05 => i17.next;
    .05 => i18.next;
    600 => m1.freq;
    0.99997 => m1.radius;
    1750 => m2.freq;
    0.99993 => m2.radius;
    3100 => m3.freq;
    0.99983 => m3.radius;
    4700 => m4.freq;
    0.9995 => m4.radius;
    6200 => m5.freq;
    0.9991 => m5.radius;
    7100 => m6.freq;
    0.999 => m6.radius;
    8200 => m7.freq;
    0.999 => m7.radius;
    9000 => m8.freq;
    0.99899 => m8.radius;
    11000 => m9.freq;
    0.9989 => m9.radius;
    12000 => m10.freq;
    0.9989 => m10.radius;
    13000 => m11.freq;
    0.9985 => m11.freq;
    15000 => m12.freq;
    0.9985 => m12.radius;
    1800 => m13.freq;
    0.9995 => m13.radius;

    .08 => i1.next;
    .08 => i2.next;
    .08 => i3.next;
    .05 => i4.next;
    .05 => i5.next;
    .05 => i6.next;
    .05 => i7.next;
    .05 => i8.next;
    .05 => i9.next;
    .05 => i10.next;
    .05 => i11.next;
    .05 => i12.next;
    .07=> i14.next;
    Gain g=>dac;
    SinOsc s=> g;
    .3 => g.gain;
    1800=>s.freq;
    200=>int t0;
    0=>int counter;
    1 =>float k;
    0=> float c1;
    .09=> float c2;
    0=> float c3;

    while(true)
    {
    1::ms=>now;
    (3.141592653589793*counter)/t0=>c1;
    Math.pow(counter,-2)=>c3;
    c3*Math.sin(c1)=>k;
    1*k=>g.gain;
    counter+1=>counter;
    }

    Leave a Comment