Author Topic: Mixing samples  (Read 2842 times)

hugabug

  • Posts: 2
Mixing samples
« on: 31 Mar '03 - 23:14 »
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);
     }
}
« Last Edit: 31 Mar '03 - 23:15 by hugabug »

Ian @ un4seen

  • Administrator
  • Posts: 26083
Re: Mixing samples
« Reply #1 on: 1 Apr '03 - 18:55 »
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

  • Posts: 2
Re: Mixing samples
« Reply #2 on: 5 Apr '03 - 00:12 »
Yup, it works better with timeSetEvent. Many thanks!