[music-dsp] Real Time Tempo & Synchronising Issues

Amarpreet Basi A.S.Basi at warwick.ac.uk
Thu Feb 3 02:14:22 EST 2005


you are a star! 

>>> ben at glw.com 02/03/05 00:14 AM >>>
On Wednesday 02 February 2005 2:03 pm, music-dsp-request at ceait.calarts.edu 
wrote:
> From: "Amarpreet Basi" <A.S.Basi at warwick.ac.uk>
...
> hi Ben. I've investigated the callback route that you've outlined below.
> Got a few problems though so any suggestions would be extremely helpful.
>
> i've got something like this
>
> callback function (outputBuffer)
> {
>  /* I want to "trigger" sounds at X bpm
>  I know it involves filling the output buffer
>  with the sample data, but exactly how do i control
>  the rate of the samples being output when the
>  timing interval between each call of this function is
>  fixed at some specified constant (set by the API
>  makers, 25 milliseconds in this case) */
>
>  return outputBuffer;
> }
>
> >>> Amarpreet Basi 02/01/05 19:18 PM >>>

A simple implementation might be something like this (not guaranteed to 
compile or work!) :

int16  theWaveData[ num_samples_in_wav ];
uint32 theTimer = 0;
uint32 theWaveOffset = 0;
float  bpm = 120.0;

callback function (outputBuffer)
{
 for ( i=0; i< num_samples_in_buffer; i++ ) {
 
  //jump to the start of the wave data on every beat
  if ( theTimer == ( sample_rate / bpm ) {
   theTimer = 0;
   theWaveOffset = 0;
  }

  if ( theWaveOffset < num_samples_in_wav ) 
   outputBuffer[ i ] = theWaveData[ theWaveOffset ];
  else
   outputBuffer = 0;
 
  theTimer++;
  theWaveOffset++;
 }

 return outputBuffer;
}

Beyond that you'll have to fend for yourself.

-Ben Loftis

--
dupswapdrop -- the music-dsp mailing list and website:
subscription info, FAQ, source code archive, list archive, book reviews, dsp links
http://shoko.calarts.edu/musicdsp
http://ceait.calarts.edu/mailman/listinfo/music-dsp




More information about the music-dsp mailing list