projects/aaron/marco_detector.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;
  StkFloat poloSample; 
  int i, counter, nTicks = (int) nBufferFrames;
  FileWvIn *poloFile = (FileWvIn *) data->poloFile;   
  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==9) {    
		if (data->triggered) {  
			try {
				poloSample = poloFile->tick();
			}
			catch ( StkError & ) {
				exit( 1 );
			}
			*oSamples++ = poloSample;	
			*oSamples++ = poloSample;
			data->Matched_filter.clearTrigger();	
			if ( poloFile->isFinished() ) {
				data->triggered = false;
				poloFile->reset();
				std::cout << "finished playing polo\n";
			}
			sample = data->Matched_filter.mtick(0);  
			data->snapshot = sample;  
		}
		else {	
			sample = data->Matched_filter.mtick(*iSamples++);  
			data->snapshot = sample;  
			data->gettime_now = data->Matched_filter.getTriggerTime();	
			if ((data->gettime_now.tv_nsec !=0) & !data->triggered) {
				data->triggered=true;
				std::cout << "triggered =" << data->triggered  << "\n";
			}
			*oSamples++ = 0;	
			*oSamples++ = 0;
		}
      } 
      else { 
        *oSamples++ = 0;
        *oSamples++ = 0;
      }
      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 ; StkFloat poloSample ; int i , counter , nTicks = ( int ) nBufferFrames ; FileWvIn * poloFile = ( FileWvIn * ) data -> poloFile ; 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 == 9 ) { if ( data -> triggered ) { try { poloSample = poloFile -> tick ( ) ; } catch ( StkError & ) { exit ( 1 ) ; } * oSamples ++ = poloSample ; * oSamples ++ = poloSample ; data -> Matched_filter . clearTrigger ( ) ; if ( poloFile -> isFinished ( ) ) { data -> triggered = false ; poloFile -> reset ( ) ; std :: cout << " \n " ; } sample = data -> Matched_filter . mtick ( 0 ) ; data -> snapshot = sample ; } else { sample = data -> Matched_filter . mtick ( * iSamples ++ ) ; data -> snapshot = sample ; data -> gettime_now = data -> Matched_filter . getTriggerTime ( ) ; if ( ( data -> gettime_now . tv_nsec != 0 ) & ! data -> triggered ) { data -> triggered = true ; std :: cout << " " << data -> triggered << " \n " ; } * oSamples ++ = 0 ; * oSamples ++ = 0 ; } } else { * oSamples ++ = 0 ; * oSamples ++ = 0 ; } 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 .
// used when reading the polofile one sample at a time // Effect *effect; // pointer to the polo file we want to play if marco is detected // atr - filter // two channels interleaved // atr - matched filter // if we heard the Marco sound, then keep playing the polo sound until done, then reset the trigger // state = heard marco, playing polo //std::cout << "want to play polo =" << data->triggered  << "\n";  // the 2 output channels are interleaved, so insert 2 copies in the output stream //std::cout << "p" << poloSample << " \n"; // blank the detector while playing polo // run the matched filter with blanked input because we are talking // put the latest sample in the Tickdata structure (for debugging/monitoring) // state = listening for marco // run the matched filter for 1 sample // put the latest sample in the Tickdata structure (for debugging/monitoring) // get the last trigger time of the matched filter //std::cout << "   *** trigger at =  " << data->gettime_now.tv_sec << " , " << data->gettime_now.tv_nsec << " ns\n"; // send silence to the speakers while listening for marco sound // if effectId==9 // end for loop // Process control messages. // end while