Mixing samples

Started by hugabug,

hugabug

Hi folks,

I'm using the code below to play a simple rhythm. However, playback is very inconsistent, in terms of sample attack definition, relative prominence, etc. Can anyone suggest what I might be doing wrong?

Many thanks,
Hugh

bool RBBGenerator::Init()
{
     BASS_Init(-1,44100,BASS_DEVICE_MONO,0); BASS_Start();
     t=0; delta_t = 125;
     return true;
}

void RBBGenerator::run()
{
DWORD lastTime=GetTickCount(), tmp;

HSAMPLE bass = BASS_SampleLoad(FALSE,"g:\\hugh\\rave\\samples\\909 bd 1.wav",0,0,40,BASS_SAMPLE_OVER_VOL);

HSAMPLE snare = BASS_SampleLoad(FALSE,"g:\\hugh\\rave\\samples\\909 snare 2.wav",0,0,40,BASS_SAMPLE_OVER_VOL);

HSAMPLE hat = BASS_SampleLoad(FALSE,"g:\\hugh\\rave\\samples\\909 c_hat 1.wav",0,0,40,BASS_SAMPLE_OVER_VOL);

      while(1)
      {
            tmp = GetTickCount();
            if (tmp - lastTime > delta_t)
            {
                  lastTime = tmp;
                  if (t % 8 == 0) BASS_SamplePlayEx(bass,0,-1,100,0,0);
                  if (t % 8 == 3) BASS_SamplePlayEx(bass,0,-1,60,0,0);
                  if (t % 8 == 7) BASS_SamplePlayEx(bass,0,-1,60,0,0);
                  if (t % 8 == 4) BASS_SamplePlayEx(snare,0,-1,100,0,0);
                  if (t % 2 == 0) BASS_SamplePlay(hat);
                  t++;
            }
            Sleep(5);
      }
}
[/color]

Ian @ un4seen

What Windows version are you using? GetTickCount is not guaranteed to be millisecond accurate, nor is Sleep guaranteed to wait for exactly the length of time you ask.

I think the best thing would probably be to use a multimedia timer (timeSetEvent), with a period of 125ms (or whatever you want :))

hugabug

Yup, it works better with timeSetEvent. Many thanks!