SDL_mixer problems with looped sounds


I’m trying to play a looped wav-file with SDL_mixer.
I tried:

/* start sound */
if(engine != -1)
engine = Mix_PlayChannel(-1, fx_engine, -1);

/* stop sound (pause mode, game over etc.) */
if(engine != -1) {
Mix_FadeOutChannel(engine, 0);
engine = -1;

I notived a few things:

  • When the effect gets looped, there is some UGLY white noise
    (for about a second). There is no noise when I play the sample
    just once.

  • Sometimes the effect gets muted.
    I.e., after a Mix_FadeOutChannel the channel is gone and
    Mix_PlayChannel doesn’t seem to do anything anymore (but it still
    returns 0 as (a valid) channel number.

Also, it would be nice if there was a callback function when
the sample has finished playing.