Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualchiranjivi

Posted 26 March 2013 - 11:49 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

#1chiranjivi

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

PARTNERS