J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Thu May 29, 2008 3:14 am Post subject: SDL sample converters |
|
|
SDL has the ability to convert the format and rate of samples to the mixer format and rate, but there's a slight catch - it only converts the rate by powers of two. Look at this in SDL_audiocvt.c:
| Code: | /* We may need a slow conversion here to finish up */
if ( (lo_rate/100) != (hi_rate/100) ) {
#if 1
/* The problem with this is that if the input buffer is
say 1K, and the conversion rate is say 1.1, then the
output buffer is 1.1K, which may not be an acceptable
buffer size for the audio driver (not a power of 2)
*/
/* For now, punt and hope the rate distortion isn't great.
*/
#else
if ( src_rate < dst_rate ) {
cvt->rate_incr = (double)lo_rate/hi_rate;
cvt->len_mult *= 2;
cvt->len_ratio /= cvt->rate_incr;
} else {
cvt->rate_incr = (double)hi_rate/lo_rate;
cvt->len_ratio *= cvt->rate_incr;
}
cvt->filters[cvt->filter_index++] = SDL_RateSLOW;
#endif
} |
The "slow" rate conversion isn't enabled because on some audio cards, it can result in the mixed sample being a length that the card can't handle. The PSP wants sample lengths to be a multiple of 64, but the only result from not doing so is the possibility of a slight pop or crackle at the end of the sample. Because of that, I changed the "#if 1" to "#if 0" and recompiled SDL. This fixes the pitch problem in Duke Nukem 3D. Duke3D uses samples at 5 and 8 kHz, and relies on SDL to resample them to 11025 Hz when mixing the sounds. Without the change, the samples were being resampled to the closest power of two between 5/8 kHz and 44100 Hz (the mixer rate).
Any thoughts on enabling the slow conversion in the repo copy of SDL? |
|