diff --git a/src/dogs.h b/src/dogs.h index 4fc60782..8cd1b397 100644 --- a/src/dogs.h +++ b/src/dogs.h @@ -3564,8 +3564,8 @@ static const unsigned char dsdgact[] = { // http://creativecommons.org/publicdomain/zero/1.0/ static const unsigned char dsdgatk[] = { - 3,0,34,86,213,30,0,0,120,112,113,110,109,106,105,103,102,102,102,102,104,106, - 110,113,117,122,127,132,137,141,144,147,149,150,151,152,152,152,151,150,148, + 3,0,34,86,213,30,0,0,128,127,126,125,124,123,121,120,118,117,116,115,114,115, + 116,117,120,123,127,131,136,140,144,147,149,150,151,152,152,152,151,150,148, 145,142,138,135,131,128,125,123,121,121,120,121,121,121,121,121,121,121,121, 120,120,119,119,118,118,117,116,116,116,116,117,119,120,122,125,127,130,133, 136,139,141,144,146,147,148,149,149,148,146,144,142,139,136,134,131,128,125, diff --git a/src/i_oalsound.c b/src/i_oalsound.c index e5342c63..f97f296b 100644 --- a/src/i_oalsound.c +++ b/src/i_oalsound.c @@ -546,6 +546,22 @@ static boolean IsPaddedSound(const byte *data, int size) return true; } +static void FadeInMono8(byte *data, ALsizei size, ALsizei freq) +{ + const int fadelen = freq * FADETIME / 1000000; + int i; + + if (data[0] == 128 || size < fadelen) + { + return; + } + + for (i = 0; i < fadelen; i++) + { + data[i] = (data[i] - 128) * i / fadelen + 128; + } +} + boolean I_OAL_CacheSound(sfxinfo_t *sfx) { int lumpnum; @@ -604,6 +620,9 @@ boolean I_OAL_CacheSound(sfxinfo_t *sfx) // All Doom sounds are 8-bit format = AL_FORMAT_MONO8; + + // Fade in sounds that start at a non-zero amplitude to prevent clicking. + FadeInMono8(sampledata, size, freq); } else { diff --git a/src/i_sndfile.c b/src/i_sndfile.c index 6dc3f682..f71cb635 100644 --- a/src/i_sndfile.c +++ b/src/i_sndfile.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "i_oalstream.h" #include "m_swap.h" @@ -483,6 +484,38 @@ static boolean OpenFile(sndfile_t *file, void *data, sf_count_t size) return true; } +static void FadeInMono16(short *data, ALsizei size, ALsizei freq) +{ + const int fadelen = freq * FADETIME / 1000000; + int i; + + if (!data[0] || size / sizeof(short) < fadelen) + { + return; + } + + for (i = 0; i < fadelen; i++) + { + data[i] = data[i] * i / fadelen; + } +} + +static void FadeInMonoFloat32(float *data, ALsizei size, ALsizei freq) +{ + const int fadelen = freq * FADETIME / 1000000; + int i; + + if (fabsf(data[0]) < 0.000001f || size / sizeof(float) < fadelen) + { + return; + } + + for (i = 0; i < fadelen; i++) + { + data[i] = data[i] * i / fadelen; + } +} + boolean I_SND_LoadFile(void *data, ALenum *format, byte **wavdata, ALsizei *size, ALsizei *freq) { @@ -519,10 +552,21 @@ boolean I_SND_LoadFile(void *data, ALenum *format, byte **wavdata, return false; } - *wavdata = local_wavdata; *size = num_frames * file.frame_size / file.sfinfo.channels; *freq = file.sfinfo.samplerate; + // Fade in sounds that start at a non-zero amplitude to prevent clicking. + if (*format == AL_FORMAT_MONO16) + { + FadeInMono16(local_wavdata, *size, *freq); + } + else if (*format == AL_FORMAT_MONO_FLOAT32) + { + FadeInMonoFloat32(local_wavdata, *size, *freq); + } + + *wavdata = local_wavdata; + CloseFile(&file); return true; diff --git a/src/i_sndfile.h b/src/i_sndfile.h index d92a6b1d..d1c7c6a3 100644 --- a/src/i_sndfile.h +++ b/src/i_sndfile.h @@ -22,6 +22,8 @@ #include "al.h" #include "doomtype.h" +#define FADETIME 1000 // microseconds + boolean I_SND_LoadFile(void *data, ALenum *format, byte **wavdata, ALsizei *size, ALsizei *freq);