• Create Account

## SDL - inconsistent timing of sounds...?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1chiranjivi  Members

208
Like
0Likes
Like

Posted 26 March 2013 - 11:48 AM

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

### #2BGB  Members

1570
Like
0Likes
Like

Posted 26 March 2013 - 09:17 PM

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...

### #3Sik_the_hedgehog  Members

2948
Like
0Likes
Like

Posted 27 March 2013 - 07:03 PM

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

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

### #4BGB  Members

1570
Like
0Likes
Like

Posted 27 March 2013 - 09:44 PM

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...

116
Like
0Likes
Like

Posted 28 March 2013 - 03:06 AM

I think if you don't have a realtime OS you cannot guarantee that timing is perfectly accurate. The problem could also be your soundcard. Musicians have external soundinterfaces with ultra low latency but this is just a guess. For windows you could try asio drivers and for linux the jack audio system.

Edited by sbradl, 28 March 2013 - 03:06 AM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.