From de318a6f06dd24136a3d538a27ecef43a1bce1e5 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Thu, 13 Mar 2008 18:33:59 +0000 Subject: Apply SRC patch from David Flater. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1105 --- src/i_sdlsound.c | 93 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 68 insertions(+), 25 deletions(-) (limited to 'src/i_sdlsound.c') diff --git a/src/i_sdlsound.c b/src/i_sdlsound.c index 6764d19e..a250cc36 100644 --- a/src/i_sdlsound.c +++ b/src/i_sdlsound.c @@ -57,8 +57,8 @@ static int channels_playing[NUM_CHANNELS]; static int mixer_freq; static Uint16 mixer_format; static int mixer_channels; -static void (*ExpandSoundData)(byte *data, int samplerate, int length, - Mix_Chunk *destination) = NULL; +static uint32_t (*ExpandSoundData)(byte *data, int samplerate, int length, + Mix_Chunk *destination) = NULL; int use_libsamplerate = 0; @@ -97,15 +97,16 @@ static void ReleaseSoundOnChannel(int channel) // unsigned 8 bits --> signed 16 bits // mono --> stereo // samplerate --> mixer_freq +// Returns number of clipped samples. // DWF 2008-02-10 with cleanups by Simon Howard. -static void ExpandSoundData_SRC(byte *data, - int samplerate, - int length, - Mix_Chunk *destination) +static uint32_t ExpandSoundData_SRC(byte *data, + int samplerate, + int length, + Mix_Chunk *destination) { SRC_DATA src_data; - uint32_t i, abuf_index=0; + uint32_t i, abuf_index=0, clipped=0; int retn; int16_t *expanded; @@ -123,12 +124,15 @@ static void ExpandSoundData_SRC(byte *data, for (i=0; i INT16_MAX) { + cvtval_i = INT16_MAX; + ++clipped; + } // Left and right channels - expanded[abuf_index++] = cvtval; - expanded[abuf_index++] = cvtval; + expanded[abuf_index++] = cvtval_i; + expanded[abuf_index++] = cvtval_i; } free(src_data.data_in); free(src_data.data_out); + return clipped; } #endif @@ -188,12 +219,13 @@ static boolean ConvertibleRatio(int freq1, int freq2) } } -// Generic sound expansion function for any sample rate +// Generic sound expansion function for any sample rate. +// Returns number of clipped samples (always 0). -static void ExpandSoundData_SDL(byte *data, - int samplerate, - int length, - Mix_Chunk *destination) +static uint32_t ExpandSoundData_SDL(byte *data, + int samplerate, + int length, + Mix_Chunk *destination) { SDL_AudioCVT convertor; uint32_t expanded_length; @@ -284,6 +316,8 @@ static void ExpandSoundData_SDL(byte *data, } #endif /* #ifdef LOW_PASS_FILTER */ } + + return 0; } // Load and convert a sound effect @@ -294,6 +328,7 @@ static boolean CacheSFX(int sound) int lumpnum; unsigned int lumplen; int samplerate; + int clipped; unsigned int length; byte *data; @@ -332,10 +367,18 @@ static boolean CacheSFX(int sound) sound_chunks[sound].allocated = 1; sound_chunks[sound].volume = MIX_MAX_VOLUME; - ExpandSoundData(data + 8, - samplerate, - length, - &sound_chunks[sound]); + + clipped = ExpandSoundData(data + 8, + samplerate, + length, + &sound_chunks[sound]); + + if (clipped) + { + fprintf(stderr, "Sound %d: clipped %u samples (%0.2f %%)\n", + sound, clipped, + 400.0 * clipped / sound_chunks[sound].alen); + } // don't need the original lump any more -- cgit v1.2.3