Difference between revisions of "StereoChordEGG.ck"

From CSWiki
Jump to: navigation, search
Line 1: Line 1:
    // In the late '60s or early 70's Paia electronics came out with a circuit kit called the
+
// In the late '60s or early 70's Paia electronics came out with a circuit kit called the
    // Stereo Chord EGG (Electronic Gratification Generator).  It was a top-octave generator
+
// Stereo Chord EGG (Electronic Gratification Generator).  It was a top-octave generator
    // along with a resistor network to mix up the I,IV and V chords into the left and right channels.
+
// along with a resistor network to mix up the I,IV and V chords into the left and right channels.
    //  
+
//  
    //  This little chuck proggy is an attempt to re-create "the wisdom of the ancients"  and let you
+
//  This little chuck proggy is an attempt to re-create "the wisdom of the ancients"  and let you
    // hear what this little guy sounded like -- as best as my 35 year old, admittedly alcohol
+
// hear what this little guy sounded like -- as best as my 35 year old, admittedly alcohol
    // addled memories will permit.
+
// addled memories will permit.
    class Chord  
+
    {
+
        string myName;  // a name for us to show the user during debug prints.  BTW: what's with <<<>>> ??!?!
+
class Chord  
        //Paia's circuit used a top-octave generator to make a square wave train that they somehow filtered.
+
{
        // I can't remember how that happened so I used banded wave guides, since it sounded right.
+
string myName;  // a name for us to show the user during debug prints.  BTW: what's with <<<>>> ??!?!
        // Paia used three note chords, so that's good enough for us.
+
        BandedWG tonic => gain g;
+
        BandedWG two => g;
+
//Paia's circuit used a top-octave generator to make a square wave train that they somehow filtered.
        BandedWG third => g;
+
// I can't remember how that happened so I used banded wave guides, since it sounded right.
        // the banded wave guides will be playing all the time, so the only control is that
+
        // we will be ramping the gain of the mixer from current vol to wanted vol.
+
// Paia used three note chords, so that's good enough for us.
        float currvol;
+
BandedWG tonic => gain g;
        float wantedvol;
+
BandedWG two => g;
        g => dac;
+
BandedWG third => g;
        // set some defaults for the banded wave guide generators.  I don't know or care too much
+
        //  what these all mean.  It is enough that someone out in internet land knows.
+
// the banded wave guides will be playing all the time, so the only control is that
        //  "The internet is the ultimate irreferance":  Jim Hinds. and you can quote me on that.
+
// we will be ramping the gain of the mixer from current vol to wanted vol.
        public void  setBand ( BandedWG b, float loudness, int note ) {
+
float currvol;
            loudness=> b.gain;
+
float wantedvol;
            1=> b.preset;
+
g => dac;
            // comp-XXX salesman: "hey Arnie!  He doesn't know what std.mtof does!". Spock: "read the source, luke".
+
            std.mtof(21+note) => b.freq;
+
// set some defaults for the banded wave guide generators.  I don't know or care too much
            // we love rand functions to set important parameters so that the wool is firmly over our eyes.
+
//  what these all mean.  It is enough that someone out in internet land knows.
            //  As the Church of the Subgenius sez: "Praise Bob!"
+
//  "The internet is the ultimate irreferance":  Jim Hinds. and you can quote me on that.
            std.rand2f( 0.1, 0.9 ) => b.bowRate;
+
public void  setBand ( BandedWG b, float loudness, int note ) {
            std.rand2f( 0.2, 0.35 ) => b.bowPressure;
+
    loudness=> b.gain;
            std.rand2f( 0.6, 0.8 ) => b.startBowing;
+
    1=> b.preset;
        }
+
        // adjust the gain up or down as needed without going passed the desired limit
+
// comp-XXX salesman: "hey Arnie!  He doesn't know what std.mtof does!". Spock: "read the source, luke".
        // note that the direction of the adjustment MUST be in agreement with the desired
+
    std.mtof(21+note) => b.freq;
        // direction.  This method doesnt know about that.  That's one reason it is private.
+
        private void gainTo ( float v, float wanted ) {
+
// we love rand functions to set important parameters so that the wool is firmly over our eyes.
            currvol + v => float adjust;
+
//  As the Church of the Subgenius sez: "Praise Bob!"
            if ( wanted > currvol && adjust > wanted ) wanted => adjust;
+
    std.rand2f( 0.1, 0.9 ) => b.bowRate;
            if ( wanted < currvol && adjust < wanted ) wanted => adjust;
+
    std.rand2f( 0.2, 0.35 ) => b.bowPressure;
            adjust=>currvol;
+
    std.rand2f( 0.6, 0.8 ) => b.startBowing;
            adjust=>g.gain;
+
}
        }
+
        // set some reasonable values for this object.  Normally we would do this in a constructor. (where
+
        // are the constructors?  I must have missed something...
+
// adjust the gain up or down as needed without going passed the desired limit
        //
+
// note that the direction of the adjustment MUST be in agreement with the desired
        public void  setChord ( int tonicValue, int twoValue, int thirdValue,string n) {
+
// direction.  This method doesnt know about that.  That's one reason it is private.
            n => myName;
+
private void gainTo ( float v, float wanted ) {
            setBand (tonic, .80, tonicValue);
+
    currvol + v => float adjust;
            setBand (two, .85, twoValue);
+
    if ( wanted > currvol && adjust > wanted ) wanted => adjust;
            setBand (third, .9, thirdValue);
+
    if ( wanted < currvol && adjust < wanted ) wanted => adjust;
            0 => wantedvol;
+
    adjust=>currvol;
            0 => currvol;
+
    adjust=>g.gain;
            0=> g.gain;
+
}
        }
+
        //ramp the volume on this object incrementally till we hit the wanted volume
+
// set some reasonable values for this object.  Normally we would do this in a constructor. (where
        public void rampgain ( ) {
+
// are the constructors?  I must have missed something...
            float adjust;
+
//
            while ( 1 ) {
+
public void  setChord ( int tonicValue, int twoValue, int thirdValue,string n) {
                175::ms => now;
+
    n => myName;
                if ( currvol > wantedvol ) {
+
    setBand (tonic, .80, tonicValue);
                    gainTo(-.2, wantedvol);
+
    setBand (two, .85, twoValue);
                }
+
    setBand (third, .9, thirdValue);
                if ( currvol < wantedvol ) {
+
    0 => wantedvol;
                    gainTo(.1, wantedvol);
+
    0 => currvol;
                }
+
    0=> g.gain;
                // <<<myName, currvol,wantedvol>>>;
+
    }
            }
+
        }
+
//ramp the volume on this object incrementally till we hit the wanted volume
    }
+
public void rampgain ( ) {
    //  a function for "syntactic cod-liver-oil" since we can't spork c.rampgain directly
+
    float adjust;
    fun void runChord (Chord c) {
+
    while ( 1 ) {
        c.rampgain();
+
        175::ms => now;
    }
+
        if ( currvol > wantedvol ) {
    //set up the I, IV and V chords and start them sounding at amplitude zero
+
            gainTo(-.2, wantedvol);
    Chord I;
+
        }
    I.setChord ( 1,3,5,"I");
+
        if ( currvol < wantedvol ) {
    spork ~ runChord(I);
+
            gainTo(.1, wantedvol);
    Chord IV;
+
        }
    IV.setChord ( 4,6,1,"IV");
+
    // <<<myName, currvol,wantedvol>>>;
    spork ~ runChord(IV);
+
        }
    Chord V;
+
    }
    V.setChord ( 5,7,2,"V");
+
    spork ~ runChord(V);
+
}
    //since machines like to use numbers to access the chords, rather than names like I,IV,V
+
    //we put the chord object (references) into an array
+
//  a function for "syntactic cod-liver-oil" since we can't spork c.rampgain directly
    [I,IV,V] @=> Chord @ s[ ] ;
+
fun void runChord (Chord c) {
    //changeto will bring up the volume on one of the chords and leave it like for a specified duration
+
c.rampgain();
    fun void changeto (float amplitude,int index,dur t )
+
}
    {
+
        for ( 0 =>int i; i <3 ; i++ ) {
+
//set up the I, IV and V chords and start them sounding at amplitude zero
            0 => float v;
+
Chord I;
            if (i == index ) amplitude => v;
+
I.setChord ( 1,3,5,"I");
            v=> s [i].wantedvol;
+
spork ~ runChord(I);
        }
+
Chord IV;
        t => now ;
+
IV.setChord ( 4,6,1,"IV");
    }
+
spork ~ runChord(IV);
    //select a chord at random, bring it up to a random level and hold for some reasonable time
+
Chord V;
    while (1) {
+
V.setChord ( 5,7,2,"V");
        changeto (std.rand2f(.5,.9),  std.rand2(0,2), std.rand2f(1.5,4)::second );
+
spork ~ runChord(V);
    }
+
 +
//since machines like to use numbers to access the chords, rather than names like I,IV,V
 +
//we put the chord object (references) into an array
 +
[I,IV,V] @=> Chord @ s[ ] ;
 +
 +
//changeto will bring up the volume on one of the chords and leave it like for a specified duration
 +
fun void changeto (float amplitude,int index,dur t )
 +
{
 +
for ( 0 =>int i; i <3 ; i++ ) {
 +
    0 => float v;
 +
    if (i == index ) amplitude => v;
 +
    v=> s [i].wantedvol;
 +
}
 +
t => now ;
 +
}
 +
 +
//select a chord at random, bring it up to a random level and hold for some reasonable time
 +
while (1) {
 +
changeto (std.rand2f(.5,.9),  std.rand2(0,2), std.rand2f(1.5,4)::second );
 +
}

Revision as of 18:05, 21 February 2006

// In the late '60s or early 70's Paia electronics came out with a circuit kit called the
// Stereo Chord EGG (Electronic Gratification Generator).  It was a top-octave generator
// along with a resistor network to mix up the I,IV and V chords into the left and right channels.
// 
//  This little chuck proggy is an attempt to re-create "the wisdom of the ancients"  and let you
// hear what this little guy sounded like -- as best as my 35 year old, admittedly alcohol
// addled memories will permit.


class Chord 
{
string myName;  // a name for us to show the user during debug prints.  BTW: what's with <<<>>> ??!?!


//Paia's circuit used a top-octave generator to make a square wave train that they somehow filtered.
// I can't remember how that happened so I used banded wave guides, since it sounded right.

// Paia used three note chords, so that's good enough for us.
BandedWG tonic => gain g;
BandedWG two => g;
BandedWG third => g;

// the banded wave guides will be playing all the time, so the only control is that
// we will be ramping the gain of the mixer from current vol to wanted vol.
float currvol;
float wantedvol;
g => dac;

// set some defaults for the banded wave guide generators.  I don't know or care too much
//  what these all mean.  It is enough that someone out in internet land knows.
//  "The internet is the ultimate irreferance":  Jim Hinds. and you can quote me on that.
public void  setBand ( BandedWG b, float loudness, int note ) {
    loudness=> b.gain;
    1=> b.preset;

// comp-XXX salesman: "hey Arnie!  He doesn't know what std.mtof does!". Spock: "read the source, luke".
    std.mtof(21+note) => b.freq;

// we love rand functions to set important parameters so that the wool is firmly over our eyes.
//  As the Church of the Subgenius sez: "Praise Bob!"
    std.rand2f( 0.1, 0.9 ) => b.bowRate;
    std.rand2f( 0.2, 0.35 ) => b.bowPressure;
    std.rand2f( 0.6, 0.8 ) => b.startBowing;
}


// adjust the gain up or down as needed without going passed the desired limit
// note that the direction of the adjustment MUST be in agreement with the desired
// direction.  This method doesnt know about that.  That's one reason it is private.
private void gainTo ( float v, float wanted ) {
    currvol + v => float adjust;
    if ( wanted > currvol && adjust > wanted ) wanted => adjust;
    if ( wanted < currvol && adjust < wanted ) wanted => adjust;
    adjust=>currvol;
    adjust=>g.gain;
}

// set some reasonable values for this object.  Normally we would do this in a constructor. (where
// are the constructors?  I must have missed something...
//
public void  setChord ( int tonicValue, int twoValue, int thirdValue,string n) {
    n => myName;
    setBand (tonic, .80, tonicValue);
    setBand (two, .85, twoValue);
    setBand (third, .9, thirdValue);
    0 => wantedvol;
    0 => currvol;
    0=> g.gain;
    }

//ramp the volume on this object incrementally till we hit the wanted volume
public void rampgain ( ) {
    float adjust;
    while ( 1 ) {
        175::ms => now;
        if ( currvol > wantedvol ) {
            gainTo(-.2, wantedvol);
        }
        if ( currvol < wantedvol ) {
            gainTo(.1, wantedvol);
        }
    //	<<<myName, currvol,wantedvol>>>;
        }
    }

}

//  a function for "syntactic cod-liver-oil" since we can't spork c.rampgain directly
fun void runChord (Chord c) {
c.rampgain();
}

//set up the I, IV and V chords and start them sounding at amplitude zero
Chord I;
I.setChord ( 1,3,5,"I");
spork ~ runChord(I);
Chord IV;
IV.setChord ( 4,6,1,"IV");
spork ~ runChord(IV);
Chord V;
V.setChord ( 5,7,2,"V");
spork ~ runChord(V);

//since machines like to use numbers to access the chords, rather than names like I,IV,V
//we put the chord object (references) into an array
[I,IV,V] @=> Chord @ s[ ] ;

//changeto will bring up the volume on one of the chords and leave it like for a specified duration
fun void changeto (float amplitude,int index,dur t )
{
for ( 0 =>int i; i <3 ; i++ ) {
    0 => float v;
    if (i == index ) amplitude => v;
    v=> s [i].wantedvol;
}
t => now ;
}

//select a chord at random, bring it up to a random level and hold for some reasonable time
while (1) {
changeto (std.rand2f(.5,.9),  std.rand2(0,2), std.rand2f(1.5,4)::second );
}