# SDL - inconsistent timing of sounds...?

This topic is 1756 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm trying to make an application which functions as a metronome, clicking at a rate of 60 BPM. I'm having issues though - if i use Mix_PlayChannel() to play a 'click' sound once every 1000ms, i seem to get something very different than a steady one click per second.

I recorded the sound output in Audacity and compared clicks, and they seem to be spread out by as little as 900ms and sometimes as much as 1100ms for no reason that I can see. I assumed something must have been thrown off somewhere, so in the function that plays the sound I added:

void play_click() {
std::cout << "click on note " << n << " at " << SDL_GetTicks() << " ticks\n";
Mix_PlayChannel( -1, metronome, 0 );
}


The output this gives me is this:

click on note 1 at 1116 ticks
click on note 2 at 2116 ticks
click on note 3 at 3116 ticks
click on note 4 at 4116 ticks
click on note 5 at 5116 ticks
click on note 6 at 6116 ticks
click on note 7 at 7116 ticks
click on note 8 at 8116 ticks
click on note 9 at 9116 ticks
click on note 10 at 10116 ticks
click on note 11 at 11116 ticks
click on note 12 at 12116 ticks
click on note 13 at 13116 ticks
click on note 14 at 14116 ticks
click on note 15 at 15116 ticks


So yeah, I'm thoroughly confused. The application reports that it is triggering the sound every time at a precisely 1000ms interval without even a millisecond's variance - but when you actually listen to the sound it outputs, it's all over the place.

Are there inherent timing problems with sound in SDL that I wasn't aware of or have i just done something dumb (I suspect the latter?)

Thank you for any help

##### Share on other sites

how many samples are being mixed at a time?...

basically, check the last parameter for Mix_OpenAudio().

rather than, say, 4096, try something like, say, 1024, and maybe see if it is any better...

##### Share on other sites

We probably can't help much if we can't tell how you initialized the audio system.

##### Share on other sites

We probably can't help much if we can't tell how you initialized the audio system.

yeah... I mostly just made an educated guess... real code generally beats guesses though...