WAVE playback bad

Ryan C. Gordon icculus at clutteredmind.org
Thu Oct 4 15:12:51 EDT 2001


> I replied to sender instead of to mailing list again... >sigh<

(I seriously need to get better mailing list software here...)

> This may be old news, but SDL already has a SDL_RateSLOW() in
> SDL_audiocvt.c, in addition to SDL_RateMUL2() and SDL_RateDIV2().
> Unfortunately it's never used. According to the comment:

Even RateSLOW() isn't particularly good, but it IS better than nothing.
Due to the nature of SDL_sound, we can probably make use of it better than
SDL itself can, since we're less concerned about powers of two.

To fix this in SDL, the data that is farmed from the audio callback needs
to be buffered if there's a conversion needed, due to the programmer
forcing the audio device into an emulated mode.

Psudeo code:

function get_data_for_audio_device()
{
  if (extrabuffer isn't empty)
  {
     move_what_you_can_to_audio_device(extrabuffer);
     if (extrabuffer still isn't empty)
        return;
  }

  audio_callback(buffer);  // get more data from application.
  if (need_conversion)
     do_conversion(buffer);

  move_what_you_can_to_audio_device(buffer);
  move_extra_sample_points_to_extra_buffer(buffer, extrabuffer);
}


...this adds overhead, but fixes the problem. note that "Move what you can
to the audio device" can still be all the data, if the audio device
doesn't require buffers to be multiples of two in size.

--ryan.






More information about the sdlsound mailing list