login

online now

We have 69 guests and no members online

search

 

The following code as used to produce the "I am Ginsing" audio output. Through the use of the GinSing software interface you can do lots of stuff very easily without having to dig into the hardware registers and/or deal with serial communication to the device. For more information on how this code works check out our software page.



// -------------------------------------------------------------------------------------------------------------------------
// demo - run through some of the GinSing features
// -------------------------------------------------------------------------------------------------------------------------

#include <GinSing.h>

GinSing         GS;

GinSingVoice *  v;
GinSingPreset * fx;
GinSingPoly *   p;
GinSingSynth *  s;
GinSingMaster * m;


#define rcvPin  4
#define sndPin  3
#define ovfPin  2

// -------------------------------------------------------------------------------------------------------------------------
//  setup - system entry point for intialization
// -------------------------------------------------------------------------------------------------------------------------

void setup ()
{
  GS.begin( rcvPin , sndPin , ovfPin );
 
  v  = GS.getVoice ();
  fx = GS.getPreset();
  p  = GS.getPoly  ();
  s  = GS.getSynth ();
  m  = GS.getMaster();
 
}

void loop ()
{
  doIamGinSing (); 
  doSoundFx    (); 
  doMusic      ();
  doSing       ();
  doSynth      ();
}


// -------------------------------------------------------------------------------------------------------------------------

void doIamGinSing()
{
  v->begin();
 
  v->setNote ( C_2 );

   GSAllophone welcome[] = {_IE , _A , _M ,
                             _BENDDN , _J, _I , _NE , _SE ,  _PITCHDN , _I , _PITCHDN , _NGE , _PA0 , _ENDPHRASE };
    v->speak (welcome);
    delay ( v->getMillis (welcome ) + 500 );
}

// -------------------------------------------------------------------------------------------------------------------------

void doSoundFx()
{
  // announce
 
  v->begin();
 
  v->setBlendSpeed ( 0.12f );
  v->setNote ( C_2 );

   GSAllophone msg[] = { _IE , _PA2 , _KE , _NE , _DO , _OO , _FD2 ,
                         _SO , _OU , _NE , _DO , _E , _F , _E , _EK , _TS , _PA2 , _ENDPHRASE };
   
    v->speak (msg);
    delay ( v->getMillis (msg ) + 500 );
   
   
    // run through the effects
   
    fx->begin();
   
    for ( int presetIdx = (int) SpaceWarp; presetIdx < (int) AmpMod; presetIdx++ )
    {
       fx->load    ( 0 , (GSPreset) presetIdx );
       fx->trigger ( 0 );
   
       delay ( 250 );
   
       fx->release ( 0 );
     }
    
     delay ( 1000 );
}

// -------------------------------------------------------------------------------------------------------------------------

void doMusic()
{
  // announce
 
  v->begin();
  
  v->setBlendSpeed ( 0.12f );
  v->setNote ( C_2 );

   GSAllophone msg[] = { _IE , _PA2 , _KE , _NE , _DO , _OO , _FD2 ,
                         _M , _EE , _OO , _Z , _I , _KE , _PA0 , _ENDPHRASE };
   
    v->speak (msg);
    delay ( v->getMillis (msg ) + 500 );
 
  // play a ditty
 
  #define NumNotes 10
  GSNote bass[NumNotes] = { C_3 , E_3 , D_3 , F_3 , E_3 , G_3 , E_3 , F_3 , D_3 , E_3  };
  GSNote lead[NumNotes] = { C_6 , D_6 , E_6 , F_6 , G_6 , G_6 , F_6 , E_6 , D_6 , C_6  };
  GSNote treb[NumNotes] = { G_5 , E_5 , F_5 , D_5 , E_5 , C_5 , E_5 , D_5 , F_5 , E_5  };
  
   p->begin();
   
  for ( int loopCnt = 0; loopCnt < 4; loopCnt++ )
  {
    for ( int noteIdx = 0; noteIdx < NumNotes; noteIdx++ )
    {
        p->setNote ( 0 , bass [ noteIdx ] ); p->trigger ( 0 );
        p->setNote ( 1 , treb [ noteIdx ] ); p->trigger ( 1 );
        p->setNote ( 2 , lead [ noteIdx ] ); p->trigger ( 2 );
       delay ( 200 );                                       
    }
  }

  // release the voices and wait for the envelopes to stop
   
  p->release ( 0 ); p->release ( 1 ); p->release ( 2 );
  delay ( 1000 );
}


// -------------------------------------------------------------------------------------------------------------------------
               
void doSing()
{
  GSAllophone doe[] = { _DO , _OE , _ENDPHRASE };
  GSAllophone ray[] = { _R  , _AE , _ENDPHRASE };
  GSAllophone mi [] = { _M  , _EE , _ENDPHRASE };
  GSAllophone fa [] = { _F  , _AA , _ENDPHRASE };
  GSAllophone so [] = { _SO , _OE , _ENDPHRASE };
  GSAllophone la [] = { _LO , _AA , _ENDPHRASE };
  GSAllophone ti [] = { _T  , _EE , _ENDPHRASE };
 
  #define NumNotes 22
  GSNote notes      [NumNotes] = { C_2 , D_2 , E_2 , F_2 , G_2 , A_2 , B_2 ,
                                   C_3 , D_3 , E_3 , F_3 , G_3 , A_3 , B_3 ,
                                   C_4 , D_4 , E_4 , F_4 , G_4 , A_4 , B_4 , C_5 };
                                   
  GSAllophone* names[7] = { doe , ray , mi  , fa  , so  , la  , ti };
 
 
 
  // announce
 
  v->begin();
 
  v->setBlendSpeed ( 0.12f );
  v->setNote ( C_2 );

   GSAllophone msg[] = { _IE , _PA2 , _KE , _NE , _SE , _I , _NGE , _PA2 , _ENDPHRASE };
   
    v->speak (msg);
    delay ( v->getMillis (msg ) + 1000 );
 
   
   // sing up the scale
   
    for ( int noteIdx = 0; noteIdx < NumNotes; noteIdx++ )
    {
      v->setNote ( notes [ noteIdx ] );
      v->speak   ( names [ noteIdx % 7 ] );
     
      delay ( 500 );

    }
   delay ( 2000 );
}

// -------------------------------------------------------------------------------------------------------------------------

void doSynth()
{
 
// announce
 
  v->begin();

  v->setNote ( C_2 );

   GSAllophone msg[] = { _IE , _A , _M , _AE ,
                         _W , _AE , _V , _F , _OR , _M ,
                         _SE ,  _I , _NE , _TH , _I, _SE , _IE , _Z , _ER , _PA0 , _ENDPHRASE };
   
    v->setBlendSpeed ( 0.12f );
    v->speak (msg);
   
    delay ( v->getMillis (msg ) + 500 );
   
 
   
 // do some synthy stuff  
 
 
   s->begin();
 
  
   // beat the three oscillators in bank A
  
   s->selectBank   ( BANK_A );
   s->setPatch     ( OSC_1_TO_MIXER | OSC_2_TO_MIXER | OSC_3_TO_MIXER );

   s->setWaveform  ( OSC_1 , SINE );  s->setFrequency ( OSC_2 ,  40.1f ); s->setAmplitude ( OSC_1 , 1.0f );
   s->setWaveform  ( OSC_2 , SINE );  s->setFrequency ( OSC_2 ,  80.0f ); s->setAmplitude ( OSC_2 , 0.8f );
   s->setWaveform  ( OSC_3 , SINE );  s->setFrequency ( OSC_3 ,  80.5f ); s->setAmplitude ( OSC_3 , 0.8f );


 
   // B2 ampmod B1 , B3 frequency sweep

   s->selectBank   ( BANK_B  );
   s->setPatch     ( OSC_2_AMPMOD_OSC_1 | OSC_1_TO_MIXER | OSC_3_TO_MIXER );
  
   s->setWaveform  ( OSC_1 , PULSE );     s->setFrequency ( OSC_1 , 4.0f );
   s->setAmplitude ( OSC_1 , 0.3f );      s->setFreqRamp  ( OSC_1 , 0.5f );  
  
   s->setWaveform  ( OSC_2 , SINE );      s->setFrequency ( OSC_2 , 8.0f );
   s->setAmplitude ( OSC_2 , 1.0f  );     s->setWavemode  ( OSC_2 , POSITIVE );
  
   s->setWaveform  ( OSC_3 , SINE );      s->setFrequency ( OSC_3 , 1.0f );
   s->setAmplitude ( OSC_3 , 0.4f );      s->setFreqDist  ( OSC_3 , 0.6f );
   s->setFreqRamp  ( OSC_3 , 0.1f );

   delay ( 8000 );
 
}