projects/effects/effects.cpp
// The tick() function handles sample computation and scheduling of
// control updates.  It will be called automatically by RtAudio when
// the system needs a new buffer of audio samples.
The tick() function handles sample computation and scheduling of
control updates.  It will be called automatically by RtAudio when
the system needs a new buffer of audio samples.
The tick () function handles sample computation and scheduling of control updates . It will be called automatically by RtAudio when the system needs a new buffer of audio samples .
int tick( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
         double streamTime, RtAudioStreamStatus status, void *dataPointer )
{
  TickData *data = (TickData *) dataPointer;
  register StkFloat *oSamples = (StkFloat *) outputBuffer, *iSamples = (StkFloat *) inputBuffer;
  register StkFloat sample;
  Effect *effect;
  int i, counter, nTicks = (int) nBufferFrames;
  while ( nTicks > 0 && !done ) {
    if ( !data->haveMessage ) {
      data->messager.popMessage( data->message );
      if ( data->message.type > 0 ) {
        data->counter = (long) (data->message.time * Stk::sampleRate());
        data->haveMessage = true;
      }
      else
        data->counter = DELTA_CONTROL_TICKS;
    }
    counter = min( nTicks, data->counter );
    data->counter -= counter;
    for ( i=0; i<counter; i++ ) {
      if (data->effectId==8) {    
		sample = data->filter.tick(*iSamples++);
		*oSamples++ = sample; 
        *oSamples++ = sample;
      }
      else if ( data->effectId < 3 ) { 
        if ( data->effectId == 0 )
          sample = data->envelope.tick() * data->echo.tick( *iSamples++ );
        else if ( data->effectId == 1 )
          sample = data->envelope.tick() * data->shifter.tick( *iSamples++ );
        else
          sample = data->envelope.tick() * data->lshifter.tick( *iSamples++ );
        *oSamples++ = sample; 
        *oSamples++ = sample;
      }
      else { 
        if ( data->effectId == 3 ) {
          data->chorus.tick( *iSamples++ );
          effect = (Effect *) &(data->chorus);
        }
        else if ( data->effectId == 4 ) {
          data->prcrev.tick( *iSamples++ );
          effect = (Effect *) &(data->prcrev);
        }
        else if ( data->effectId == 5 ) {
          data->jcrev.tick( *iSamples++ );
          effect = (Effect *) &(data->jcrev);
        }
        else if ( data->effectId == 6 ) {
          data->nrev.tick( *iSamples++ );
          effect = (Effect *) &(data->nrev);
        }
        else {
          data->frev.tick( *iSamples++ );
          effect = (Effect *) &(data->frev);
        }
        const StkFrames& samples = effect->lastFrame();
        *oSamples++ = data->envelope.tick() * samples[0];
        *oSamples++ = data->envelope.lastOut() * samples[1];
      }
      nTicks--;
    }
    if ( nTicks == 0 ) break;
    if ( data->haveMessage ) processMessage( data );
  }
  return 0;
}
int tick ( void * outputBuffer , void * inputBuffer , unsigned int nBufferFrames , double streamTime , RtAudioStreamStatus status , void * dataPointer ) { TickData * data = ( TickData * ) dataPointer ; register StkFloat * oSamples = ( StkFloat * ) outputBuffer , * iSamples = ( StkFloat * ) inputBuffer ; register StkFloat sample ; Effect * effect ; int i , counter , nTicks = ( int ) nBufferFrames ; while ( nTicks > 0 && ! done ) { if ( ! data -> haveMessage ) { data -> messager . popMessage ( data -> message ) ; if ( data -> message . type > 0 ) { data -> counter = ( long ) ( data -> message . time * Stk :: sampleRate ( ) ) ; data -> haveMessage = true ; } else data -> counter = DELTA_CONTROL_TICKS ; } counter = min ( nTicks , data -> counter ) ; data -> counter -= counter ; for ( i = 0 ; i < counter ; i ++ ) { if ( data -> effectId == 8 ) { sample = data -> filter . tick ( * iSamples ++ ) ; * oSamples ++ = sample ; * oSamples ++ = sample ; } else if ( data -> effectId < 3 ) { if ( data -> effectId == 0 ) sample = data -> envelope . tick ( ) * data -> echo . tick ( * iSamples ++ ) ; else if ( data -> effectId == 1 ) sample = data -> envelope . tick ( ) * data -> shifter . tick ( * iSamples ++ ) ; else sample = data -> envelope . tick ( ) * data -> lshifter . tick ( * iSamples ++ ) ; * oSamples ++ = sample ; * oSamples ++ = sample ; } else { if ( data -> effectId == 3 ) { data -> chorus . tick ( * iSamples ++ ) ; effect = ( Effect * ) & ( data -> chorus ) ; } else if ( data -> effectId == 4 ) { data -> prcrev . tick ( * iSamples ++ ) ; effect = ( Effect * ) & ( data -> prcrev ) ; } else if ( data -> effectId == 5 ) { data -> jcrev . tick ( * iSamples ++ ) ; effect = ( Effect * ) & ( data -> jcrev ) ; } else if ( data -> effectId == 6 ) { data -> nrev . tick ( * iSamples ++ ) ; effect = ( Effect * ) & ( data -> nrev ) ; } else { data -> frev . tick ( * iSamples ++ ) ; effect = ( Effect * ) & ( data -> frev ) ; } const StkFrames & samples = effect -> lastFrame ( ) ; * oSamples ++ = data -> envelope . tick ( ) * samples [ 0 ] ; * oSamples ++ = data -> envelope . lastOut ( ) * samples [ 1 ] ; } nTicks -- ; } if ( nTicks == 0 ) break ; if ( data -> haveMessage ) processMessage ( data ) ; } return 0 ; }
The tick() function handles sample computation and scheduling of
control updates.
The tick () function handles sample computation and scheduling of control updates .
// atr - filter // two channels interleaved // Echo, PitShift and LentPitShift ... mono output // two channels interleaved // Chorus or a reverb ... stereo output // Process control messages.