diff options
author | Simon Howard | 2008-02-12 22:07:41 +0000 |
---|---|---|
committer | Simon Howard | 2008-02-12 22:07:41 +0000 |
commit | 7859a115019d7311436fb540ad07bcfb933a7e30 (patch) | |
tree | 29a2d467a97407f2ea95bf38a7e75e21ec8e43aa /src | |
parent | 88e70502930e07626526750e0d3230cc2d1260f7 (diff) | |
download | chocolate-doom-7859a115019d7311436fb540ad07bcfb933a7e30.tar.gz chocolate-doom-7859a115019d7311436fb540ad07bcfb933a7e30.tar.bz2 chocolate-doom-7859a115019d7311436fb540ad07bcfb933a7e30.zip |
Use SRC_SINC_FASTEST for speed when using libsamplerate for conversions,
and precache all sound effects for speed.
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 1083
Diffstat (limited to 'src')
-rw-r--r-- | src/i_sdlsound.c | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/src/i_sdlsound.c b/src/i_sdlsound.c index 5c68d00f..923b5df0 100644 --- a/src/i_sdlsound.c +++ b/src/i_sdlsound.c @@ -96,7 +96,7 @@ static void ReleaseSoundOnChannel(int channel) // unsigned 8 bits --> signed 16 bits // mono --> stereo // samplerate --> mixer_freq -// Rewritten by DWF 2008-02-10: +// DWF 2008-02-10 with cleanups by Simon Howard. static void ExpandSoundData_SRC(byte *data, int samplerate, @@ -111,7 +111,7 @@ static void ExpandSoundData_SRC(byte *data, src_data.input_frames = length; src_data.data_in = malloc(length * sizeof(float)); src_data.src_ratio = (double)mixer_freq / samplerate; - src_data.output_frames = src_data.src_ratio * length + samplerate; + src_data.output_frames = src_data.src_ratio * length + 48000; src_data.data_out = malloc(src_data.output_frames * sizeof(float)); assert(src_data.data_in != NULL && src_data.data_out != NULL); @@ -125,7 +125,7 @@ static void ExpandSoundData_SRC(byte *data, // Do the sound conversion - retn = src_simple(&src_data, SRC_SINC_MEDIUM_QUALITY, 1); + retn = src_simple(&src_data, SRC_SINC_FASTEST, 1); assert(retn == 0); // Convert the result back into 16-bit integers. @@ -472,6 +472,38 @@ static void I_SDL_ShutdownSound(void) sound_initialised = false; } + +// Preload all the sound effects - stops nasty ingame freezes + +static void I_PrecacheSounds(void) +{ + int i; + + printf("I_PrecacheSounds: Precaching all sound effects.."); + + for (i=sfx_pistol; i<NUMSFX; ++i) + { + if ((i % 6) == 0) + { + printf("."); + fflush(stdout); + } + + if (S_sfx[i].link == NULL) + { + S_sfx[i].lumpnum = I_SDL_GetSfxLumpNum(&S_sfx[i]); + CacheSFX(i); + + if (sound_chunks[i].abuf != NULL) + { + Z_ChangeTag(sound_chunks[i].abuf, PU_CACHE); + } + } + } + + printf("\n"); +} + static boolean I_SDL_InitSound() { int i; @@ -502,15 +534,17 @@ static boolean I_SDL_InitSound() ExpandSoundData = ExpandSoundData_SDL; + Mix_QuerySpec(&mixer_freq, &mixer_format, &mixer_channels); + #ifdef HAVE_LIBSAMPLERATE if (use_libsamplerate) { ExpandSoundData = ExpandSoundData_SRC; + + I_PrecacheSounds(); } #endif - Mix_QuerySpec(&mixer_freq, &mixer_format, &mixer_channels); - Mix_AllocateChannels(NUM_CHANNELS); SDL_PauseAudio(0); |