// Sonify Class

public class Sonify




{   
    // Global Variables
    0.7 => static float gain;
    1.0 => static float rate;
    0 => static int check;
    
    fun void word ( string x )
    {
        0 => check;
        
        // Word Sound Chain 
        SndBuf s => PitShift p => Chorus c => Echo k => dac;
        gain => s.gain;
        rate => s.rate;
        0.0 => p.mix;
        0.0 => c.mix;
        0.0 => k.mix;
        
        // Slowly Restore Gain as Needed
        if (gain < 0.7)
        { 
            gain+0.05=>gain;
        }
        if (gain > 0.7)
        { 
            gain-0.05=>gain;
        }
        
        // Slowly Restore Rate as Needed
        if (rate < 1.0)
        { 
            rate+0.05=>rate;
        }
        if (gain > 1.0)
        { 
            rate-0.05=>rate;
        }
        
        
        
        // LIBRARY OF WORD SOUNDS
        
        // A
        if ((x == "ANGER") || (x == "ANGRY") || (x == "MAD") || (x == "CROWD"))
        {   
            me.dir(-1) + "/words/anger.wav" => s.read;
        }
        if (x == "APPLAUSE") 
        {   
            me.dir(-1) + "/words/applause.wav" => s.read;
        }
        
        // B
        if ((x == "BEYOND") || (x == "HEAVEN") || (x == "GOD")  || (x == "ANGELS")  || (x == "ANGEL")  || (x == "ANGELIC")  || (x == "HEAVENLY") || (x == "GODLY") || (x == "DEIFY") || (x == "DEITY") || (x == "DEITIES")) 
        {   
            me.dir(-1) + "/words/beyond.wav" => s.read;
        }
        if ((x == "BIRD") || (x == "BIRDS")) 
        {   
            if (Math.random2(0,1)==1)
            {
                me.dir(-1) + "/words/bird1.wav" => s.read;
            }
            else
            {
                me.dir(-1) + "/words/bird2.wav" => s.read;
            }
        }
        if ((x == "BOY")||(x=="SON")||(x == "CHILD"))
        {   
            me.dir(-1) + "/words/man.wav" => s.read;
            1.05 => p.shift;
            0.7 => p.mix;
        }
        if ((x == "BOYS")||(x=="SONS"))
        {   
            me.dir(-1) + "/words/man.wav" => s.read;
            1.05 => p.shift;
            0.7 => p.mix;
            0.5 => c.modDepth;
            0.5 => c.mix;
            0.5 => c.modFreq;
            550::ms => k.max;
            550::ms => k.delay;
            0.5 => k.mix;
        }
        if (x == "BUSY") 
        {   
            me.dir(-1) + "/words/busy.wav" => s.read;
        }
        
        // C
        if ((x == "CAR") || (x == "RACE") || (x == "CARS") || (x == "RACES"))
        {   
            me.dir(-1) + "/words/car.wav" => s.read;
            (gain*0.5) => s.gain;
        }
        if (x == "CAMERA")
        {   
            me.dir(-1) + "/words/camera.wav" => s.read;
        }
        if ((x == "CHILDREN")||(x=="KIDS")||(x=="PLAY")||(x=="PLAYING")||(x=="PLAYS")||(x=="PLAYED")||(x=="PLAYGROUND"))
        {   
            me.dir(-1) + "/words/children.wav" => s.read;
        }
        if (x == "CLAP")
        {   
            me.dir(-1) + "/words/clap.wav" => s.read;
        }
        if ((x == "COMFORTABLE")||(x=="COMFORT")||(x=="PILLOW")||(x=="COMFORTING")||(x=="COMFORTED")||(x=="COMFORTER")||(x=="BLANKET")||(x=="BED")||(x=="COUCH"))
        {   
            me.dir(-1) + "/words/comfortable.wav" => s.read;
        }
        if ((x == "COMPUTERS") || (x == "COMPUTER") || (x == "TECHNOLOGY") || (x == "PROGRESS") || (x == "BIT") || (x == "MEGABYTE") || (x == "GIGABYTE") || (x == "MODEM")  || (x == "INTERNET")  || (x == "CONNECTION"))
        {   
            me.dir(-1) + "/words/computer.wav" => s.read;
        }
        if ((x == "COOK")||(x == "COOKING")||(x == "COOKED")||(x == "COOKER")||(x == "COOKS")||(x == "FRY")||(x == "FRYING")||(x == "FRIED")||(x == "FRIER")||(x == "STOVE")||(x == "PAN"))
        {   
            me.dir(-1) + "/words/cook.wav" => s.read;
        }
        if ((x == "CRICKET") || (x == "CRICKETS") || (x == "NIGHT") || (x == "NIGHTTIME"))
        {   
            me.dir(-1) + "/words/crickets.wav" => s.read;
        }
        
        // D
        if ((x == "DEATH") || (x == "DIE") || (x == "DIED") || (x == "DEAD") || (x == "DYING") || (x == "DIES"))
        {   
            me.dir(-1) + "/words/death.wav" => s.read;
        }
        if ((x == "DEFY") || (x == "DEFIES") || (x == "DEFIED") || (x == "DEFYING") || (x == "DEFIER"))
        {   
            me.dir(-1) + "/words/defy.wav" => s.read;
        }
        if ((x == "DIAL") || (x == "DIALS") || (x == "DIALED") || (x == "DIALING"))
        {   
            me.dir(-1) + "/words/dial.wav" => s.read;
        }
        if ((x == "DISEASE") || (x == "SICK") || (x == "COUGH") || (x == "FLU") || (x == "COUGHING") || (x == "DYING") || (x == "COUGHED")) 
        {   
            me.dir(-1) + "/words/disease.wav" => s.read;
        }
        if ((x == "DOCK") || (x == "OCEAN") || (x == "PIER") || (x == "HARBOR") || (x == "SEA"))
        {   
            me.dir(-1) + "/words/dock.wav" => s.read;
        }
        if ((x == "DOG") || (x == "DOGS") || (x == "PUPPY") || (x == "PUPPIES"))
        {   
            if (Math.random2(0,1)==1)
            {
                me.dir(-1) + "/words/dog1.wav" => s.read;
            }
            else
            {
                me.dir(-1) + "/words/dog2.wav" => s.read;
            }
        }
        if (x == "DOOR")
        {   
            me.dir(-1) + "/words/door.wav" => s.read;
        }
        
        // E
        if ((x == "ELECTRICITY")||(x == "POWER")||(x == "ELECTRIC")||(x == "ELECTRONS")||(x == "SHOCK")||(x == "SHOCKING")||(x == "TASER")||(x == "BUZZ"))
        {   
            me.dir(-1) + "/words/electricity.wav" => s.read;
        }
        
        
        // F
        if ((x == "FAST")||(x == "QUICKLY")||(x == "QUICK"))
        {   
            2.0 => rate;
        }
        if ((x == "FEAR")||(x=="SCARY")||(x=="AFRAID")||(x=="SCARED")||(x=="FRIGHTENED")||(x=="HORROR")||(x=="HORRIFIED"))
        {   
            me.dir(-1) + "/words/fear.wav" => s.read;
        } 
        if (x == "FIRE")
        {   
            me.dir(-1) + "/words/fire.wav" => s.read;
        }
        if ((x == "FOGHORN")||(x == "SHIP")||(x == "BOAT")||(x == "FOGHORNS")||(x == "SHIPS")||(x == "BOATS")) 
        {   
            me.dir(-1) + "/words/foghorn.wav" => s.read;
        }
        if ((x == "FRANCE")||(x == "ACCORDION")||(x == "ACCORDIONS"))
        {   
            me.dir(-1) + "/words/france.wav" => s.read;
        }
        
        
        // G
        if ((x == "GLASS")||(x == "GLASSES")||(x == "LENS")||(x == "LENSES")||(x == "CRYSTAL")||(x == "MUG")||(x == "MUGS"))
        {   
            me.dir(-1) + "/words/glass.wav" => s.read;
        }
        if ((x == "GUN")||(x == "GUNS")||(x == "RIFFLE")||(x == "RIFFLES"))
        {   
            me.dir(-1) + "/words/gun.wav" => s.read;
        }
        if ((x == "GIRL")||(x=="DAUGHTER"))
        {   
            me.dir(-1) + "/words/man.wav" => s.read;
            1.35 => p.shift;
            1.0 => p.mix;
        }
        if ((x == "GIRLS")||(x=="DAUGHTERS"))
        {   
            me.dir(-1) + "/words/man.wav" => s.read;
            1.35 => p.shift;
            1.0 => p.mix;
            0.5 => c.modDepth;
            0.5 => c.mix;
            0.5 => c.modFreq;
            550::ms => k.max;
            550::ms => k.delay;
            0.5 => k.mix;
        }
        
        // K
        if ((x == "KNIFE")||(x == "KNIVES")||(x == "BLADE")||(x == "BLADES")||(x == "SWORD")||(x == "SWORDS")||(x == "RAZORBLADES")||(x == "RAZORS")||(x == "RAZORBLADE")||(x == "RAZOR")||(x == "KNIGHT")||(x == "KNIGHTS"))
        {   
            me.dir(-1) + "/words/knife.wav" => s.read;
        }
        
        // L
        if ((x == "LOUD")||(x == "BIG")||(x == "LARGE")||(x == "BIGNESS"))
        {   
            1.0 => gain;
        }
        
        // M
        if ((x == "MONSTER")||(x=="CREATURE")||(x == "MONSTERS")||(x=="CREATURES")||(x == "DRAGON")||(x=="DRAGONS"))
        {   
            me.dir(-1) + "/words/monster.wav" => s.read;
        }
        if ((x == "MAN")||(x=="HUMAN")||(x=="FLESH")||(x=="MALE")||(x=="GENTLEMAN")||(x == "PERSON")||(x=="BREATH")||(x == "BREATHE")||(x=="BREATHING")||(x=="LIFE"))
        {   
            me.dir(-1) + "/words/man.wav" => s.read;
        }
        if ((x == "MEN")||(x=="MALES")||(x=="GENTLEMEN"))
        {   
            me.dir(-1) + "/words/man.wav" => s.read;
            0.5 => c.modDepth;
            0.5 => c.mix;
            0.5 => c.modFreq;
            550::ms => k.max;
            550::ms => k.delay;
            0.5 => k.mix;
        }
        if ((x == "MORNING")||(x=="DAY")||(x=="DAYTIME")||(x=="MORNINGTIME"))
        {   
            me.dir(-1) + "/words/morning.wav" => s.read;
        }
        
        // N
        if ((x == "NO")||(x=="NOT")||(x == "NEVER")||(x=="NEGATIVE"))
        {   
            me.dir(-1) + "/words/not.wav" => s.read;
        }
        
        // O
        if ((x == "ONCE")||(x=="MAGIC")||(x=="STAR")||(x=="STARS")||(x=="MAGICAL")||(x=="MYSTICAL"))
        {   
            me.dir(-1) + "/words/once.wav" => s.read;
        }
        if ((x == "ORGAN")||(x=="CHURCH"))
        {   
            me.dir(-1) + "/words/organ.wav" => s.read;
        }
        
        // P
        if (x == "PAPER")
        {   
            me.dir(-1) + "/words/paper.wav" => s.read;
        }
        if (x == "PHONE")
        {   
            me.dir(-1) + "/words/phone.wav" => s.read;
        }
        if ((x == "PEOPLE")||(x=="MANKIND")||(x == "HUMANS")||(x == "LIVES"))
        {   
            me.dir(-1) + "/words/man.wav" => s.read;
            1.2 => p.shift;
            0.5 => p.mix;
            0.5 => c.modDepth;
            0.5 => c.mix;
            0.5 => c.modFreq;
            550::ms => k.max;
            550::ms => k.delay;
            0.5 => k.mix;
        }
        if ((x == "PIN")||(x == "YES")||(x=="ALWAYS")||(x == "POSITIVE")||(x=="SMILE"))
        {   
            me.dir(-1) + "/words/pin.wav" => s.read;
        }
        
        // Q
        if ((x == "QUIET")||(x == "SMALL")||(x == "LITTLE")||(x == "LITTLENESS"))
        {   
            0.2 => gain;
        }
        
        // R
        if ((x == "RAIN") || (x == "RAINY"))
        {   
            me.dir(-1) + "/words/rain.wav" => s.read;
        }
        if ((x == "ROCK") || (x == "ROCKS") || (x == "RUMBLE") || (x == "RUMBLES") || (x == "RUMBLING")  || (x == "RUMBLER") || (x == "ROCKY")  || (x == "MOUNTAIN") || (x == "MOUNTAINS") || (x == "MOUNTAINSIDE") || (x == "MOUNTAINOUS") || (x == "MOUNTAINRANGE"))
        {   
            me.dir(-1) + "/words/rock.wav" => s.read;
        }
        if ((x == "ROYAL") || (x == "ROYALY") || (x == "KING") || (x == "QUEEN") || (x == "PRINCE")  || (x == "PRINCESS") || (x == "ROYALTIES")  || (x == "ROYALTY"))
        {   
            me.dir(-1) + "/words/royal.wav" => s.read;
        }
        
        // S 
        if ((x == "SAD") || (x == "PITY") || (x == "CRIES") || (x == "CRY") || (x == "CRYING") || (x == "CRIED") || (x == "CRIER") || (x == "PITYING"))
        {   
            me.dir(-1) + "/words/sad.wav" => s.read;
        }  
        if ((x == "SAFE") || (x == "SAFELY") || (x == "SAFETY") || (x == "PROTECT") || (x == "PROTECTION") || (x == "PROTECTS") || (x == "PROTECTOR") || (x == "PROTECTING"))
        {   
            me.dir(-1) + "/words/safe.wav" => s.read;
        }  
        if (x == "SCHOOL")
        {   
            me.dir(-1) + "/words/school.wav" => s.read;
        }     
        if ((x == "SHOVEL") || (x == "DIG") || (x == "SHOVELS") || (x == "DIGS") || (x == "SHOVELED") || (x == "DUG"))
        {   
            if (Math.random2(0,1)==1)
            {
                me.dir(-1) + "/words/shovel1.wav" => s.read;
            }
            else
            {
                if (Math.random2(0,1)==1)
                {
                    me.dir(-1) + "/words/shovel2.wav" => s.read;
                }
                else
                {
                    me.dir(-1) + "/words/shovel3.wav" => s.read;
                }
            }       
        }
        if ((x == "SLOW")||(x == "SLOWLY"))
        {   
            0.5 => rate;
        }
        if ((x == "SPACE") || (x == "DISTANT") || (x == "STARS")  || (x == "STAR")  || (x == "PLANET")  || (x == "PLANETS")  || (x == "PLANETARY")  || (x == "STARRY")) 
        {   
            me.dir(-1) + "/words/space.wav" => s.read;
        }
        if ((x == "SUMMER") || (x == "HOT") || (x == "HOTTER")  || (x == "HOTTEST") || (x == "SWEAT") || (x == "SWEATING"))
        {   
            me.dir(-1) + "/words/summer.wav" => s.read;
        }

        
        // T
        if ((x == "THUNDER")||(x == "STORM"))
        {   
            me.dir(-1) + "/words/thunder.wav" => s.read;
        }
        if ((x == "TRAFFIC")||(x == "CITIES")||(x == "CITY")||(x == "URBAN"))
        {   
            me.dir(-1) + "/words/traffic.wav" => s.read;
        }
        if ((x == "TIME")||(x=="BEANS"))
        {   
            me.dir(-1) + "/words/time.wav" => s.read;
        }
        
        // V
        if ((x == "VICTIM")||(x == "MURDER")||(x == "WEAPON")||(x == "WEAPONS")||(x == "WEAPONS")||(x == "WEAPONED")||(x == "VICTIMS")||(x == "VICTIMIZED")||(x == "MURDERED")||(x == "MURDERS")||(x == "KILL")||(x == "KILLS")||(x == "KILLED")||(x == "KILLER"))
        {   
            if (Math.random2(0,1)==1)
            {
                me.dir(-1) + "/words/gun.wav" => s.read;
            }
            else
            {
                me.dir(-1) + "/words/knife.wav" => s.read;
            }
        }
        
        // W
        if ((x == "WIND") || (x == "WINDY")) 
        {   
            me.dir(-1) + "/words/wind.wav" => s.read;
        }
        if ((x == "WINTER") || (x == "COLD") || (x == "COLDER")  || (x == "COLDEST") || (x == "FREEZE") || (x == "FREEZING") || (x == "FREEZER"))
        {   
            me.dir(-1) + "/words/winter.wav" => s.read;
        }
        if ((x == "WOLF") || (x == "COYOTE"))
        {   
            me.dir(-1) + "/words/wolf.wav" => s.read;
        }
        if ((x == "WOMAN")||(x=="LADY")||(x == "FEMALE"))
        {   
            me.dir(-1) + "/words/man.wav" => s.read;
            1.2 => p.shift;
            1.0 => p.mix;
        }
        if ((x == "WOMEN")||(x=="LADIES")||(x=="FEMALES"))
        {   
            me.dir(-1) + "/words/man.wav" => s.read;
            1.2 => p.shift;
            1.0 => p.mix;
            0.5 => c.modDepth;
            0.5 => c.mix;
            0.5 => c.modFreq;
            550::ms => k.max;
            550::ms => k.delay;
            0.5 => k.mix;
        }
        
        s.samples() => int sam;
        
        // NOT IN LIBRARY
        
        if (sam == 0)
        {
            1 => check;
        }
        
        // SOUND BUFFER
        
        sam::samp => now;
        
    }
    
    
    fun void letters ( int x[] )
    {
        <<<"NOT IN LIBRARY!!!", x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9] >>>;
        
        //Abstract Sound Creation from first 10 letters
        
        //Letter 1&2
        FMVoices l0 => NRev r0 => dac;
        Std.mtof(x[0]+40) => l0.freq;
        (x[1]/26.0) => l0.vowel;
        (gain/6) => l0.gain;
        1.0 => l0.adsrTarget;
        1 => l0.noteOn;
        
        //Letter 3,4,&5
        Shakers l2 => NRev r02 => dac;
        Std.mtof(x[2]+40) => l2.freq;
        (x[3]*4) =>l2.objects;
        (gain/2) => l2.gain;
        if (x[4] < 23)
        {
            x[4] =>l2.preset;
        }
        else
        {
            (x[4]/26.0) => l2.energy;
        }
        1 => l2.noteOn;
        
        //Letter 6,7,&8
        ModalBar l5 => NRev r05 => dac;
        Std.mtof(x[5]+40) => l5.freq;
        (x[6]/26) =>l5.stickHardness;
        (gain) => l5.gain;
        if (x[7] < 9)
        {
            x[7] =>l5.preset;
        }
        else
        {
            (x[7]/26.0) => l5.volume;
        }
        1 => l5.noteOn;
        
        //Letter 9&10
        Noise l8 => ADSR e08 => LPF lpf8 => NRev r08 => dac;
        (0.2::second, 0.3::second, (gain/2), 5::second) => e08.set;
        1.0 => l8.gain;
        Std.mtof(x[8]+60) => lpf8.freq;
        (x[9]/26) =>lpf8.Q;
        1 => e08.keyOn;
        
        
        
        
        //Hold Sound
        1.0::second => now;
        
        //Stop Sound
        1 => l0.noteOff;
        1 => l2.noteOff;
        1 => l5.noteOff;
        1 => e08.keyOff;
        
        //Sound Buffer
        3.0::second => now;
        
        
    }
}