From 03b4f71edf026bb7440fc1f32abcfce9c42da774 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sat, 19 Apr 2008 22:47:54 +0000 Subject: [PATCH] - Reduced the range that area sounds require to interpolate between 2D and 3D panning. - The listener's velocity is now set at 0 for the sound engine. The player moves so fast that you can hear the doppler shift just by running around, otherwise. - Changed the sound code so that all sounds that start playing on a single tic actually start playing at the exact same sample position. SVN r927 (trunk) --- docs/rh-log.txt | 7 + src/s_sound.cpp | 2 +- src/s_sound.h | 1 + src/sound/fmodsound.cpp | 31 +-- src/sound/fmodsound.h | 3 + src/timidity/instrum.cpp | 4 + src/timidity/mix.cpp | 1 + zdoom.vcproj | 426 +++++++++++++++++++-------------------- 8 files changed, 249 insertions(+), 226 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index aa1cffafd5..152021668c 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,4 +1,11 @@ April 19, 2008 +- Reduced the range that area sounds require to interpolate between 2D and + 3D panning. +- The listener's velocity is now set at 0 for the sound engine. The player + moves so fast that you can hear the doppler shift just by running around, + otherwise. +- Changed the sound code so that all sounds that start playing on a single + tic actually start playing at the exact same sample position. - Added the writewave command to write the internal TiMidity's output to a wave file. - Changed the default channel velocity for MUS files from 64 to 100 to diff --git a/src/s_sound.cpp b/src/s_sound.cpp index 2db4688f8e..5145352143 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -827,7 +827,7 @@ static void S_StartSound (fixed_t *pt, AActor *mover, int channel, chan->X = x; chan->Y = y; chan->Z = z; - chan->ChanFlags = chanflags; + chan->ChanFlags |= chanflags; if (mover != NULL) { mover->SoundChans |= 1 << channel; diff --git a/src/s_sound.h b/src/s_sound.h index f7156ec3a2..ef3f0f90f4 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -101,6 +101,7 @@ struct FSoundChan BYTE EntChannel; // Actor's sound channel. int ChanFlags; }; +extern FSoundChan *Channels; FSoundChan *S_GetChannel(void *syschan); void S_ReturnChannel(FSoundChan *chan); diff --git a/src/sound/fmodsound.cpp b/src/sound/fmodsound.cpp index 3f32427186..304fbcf3ed 100644 --- a/src/sound/fmodsound.cpp +++ b/src/sound/fmodsound.cpp @@ -476,6 +476,8 @@ bool FMODSoundRenderer::Init() SfxGroup = NULL; PausableSfx = NULL; PrevEnvironment = DefaultEnvironments[0]; + DSPClockLo = 0; + DSPClockHi = 0; Printf("I_InitSound: Initializing FMOD\n"); @@ -728,6 +730,10 @@ bool FMODSoundRenderer::Init() Printf(TEXTCOLOR_BLUE" Could not register SPC codec. (Error %d)\n", result); } + if (FMOD_OK != Sys->getSoftwareFormat(&OutputRate, NULL, NULL, NULL, NULL, NULL)) + { + OutputRate = 48000; // Guess, but this should never happen. + } Sys->set3DSettings(0.5f, 96.f, 1.f); Sys->set3DRolloffCallback(RolloffCallback); snd_sfxvolume.Callback (); @@ -788,13 +794,7 @@ void FMODSoundRenderer::Shutdown() float FMODSoundRenderer::GetOutputRate() { - int rate; - - if (FMOD_OK == Sys->getSoftwareFormat(&rate, NULL, NULL, NULL, NULL, NULL)) - { - return float(rate); - } - return 48000.f; // Guess, but this should never happen. + return (float)OutputRate; } //========================================================================== @@ -1223,6 +1223,7 @@ FSoundChan *FMODSoundRenderer::StartSound3D(sfxinfo_t *sfx, float vol, float dis } chan->setVolume(vol); chan->set3DAttributes((FMOD_VECTOR *)pos, (FMOD_VECTOR *)vel); + chan->setDelay(FMOD_DELAYTYPE_DSPCLOCK_START, DSPClockHi, DSPClockLo); chan->setPaused(false); FSoundChan *schan = CommonChannelSetup(chan); schan->DistanceScale = distscale; @@ -1255,9 +1256,9 @@ FMOD_MODE FMODSoundRenderer::SetChanHeadSettings(FMOD::Channel *chan, sfxinfo_t cpos[1] = FIXED2FLOAT(players[consoleplayer].camera->z); if (chanflags & CHAN_AREA) { - const double interp_range = 512.0; + const double interp_range = 256.0; double dx = cpos[0] - pos[0], dy = cpos[1] - pos[1], dz = cpos[2] - pos[2]; - double min_dist = sfx->MinDistance == 0 ? (S_MinDistance == 0 ? 200 : S_MinDistance) : sfx->MinDistance; + double min_dist = sfx->MinDistance == 0 ? (S_MinDistance == 0 ? 150 : S_MinDistance * 0.75) : sfx->MinDistance; double dist_sqr = dx*dx + dy*dy + dz*dz; float level, old_level; @@ -1397,9 +1398,10 @@ void FMODSoundRenderer::UpdateListener() return; } - vel.x = listener->momx * (TICRATE/65536.f); - vel.y = listener->momz * (TICRATE/65536.f); - vel.z = listener->momy * (TICRATE/65536.f); + // Set velocity to 0 to prevent crazy doppler shifts just from running. + vel.x = 0;//listener->momx * (TICRATE/65536.f); + vel.y = 0;//listener->momz * (TICRATE/65536.f); + vel.z = 0;//listener->momy * (TICRATE/65536.f); pos.x = listener->x / 65536.f; pos.y = listener->z / 65536.f; pos.z = listener->y / 65536.f; @@ -1455,6 +1457,11 @@ void FMODSoundRenderer::UpdateListener() void FMODSoundRenderer::UpdateSounds() { + // Any sounds played between now and the next call to this function + // will start exactly one tic from now. + Sys->getDSPClock(&DSPClockHi, &DSPClockLo); + FMOD_64BIT_ADD(DSPClockHi, DSPClockLo, 0, OutputRate / TICRATE); + Sys->update(); } diff --git a/src/sound/fmodsound.h b/src/sound/fmodsound.h index 00ab4411d5..86ee012200 100644 --- a/src/sound/fmodsound.h +++ b/src/sound/fmodsound.h @@ -54,6 +54,9 @@ public: private: bool SFXPaused; bool InitSuccess; + unsigned int DSPClockLo; + unsigned int DSPClockHi; + int OutputRate; static FMOD_RESULT F_CALLBACK ChannelEndCallback (FMOD_CHANNEL *channel, FMOD_CHANNEL_CALLBACKTYPE type, int cmd, unsigned int data1, unsigned int data2); diff --git a/src/timidity/instrum.cpp b/src/timidity/instrum.cpp index 67d2decb0d..a1541f6b24 100644 --- a/src/timidity/instrum.cpp +++ b/src/timidity/instrum.cpp @@ -348,6 +348,10 @@ fail: { sp->scale_note = LittleShort(patch_data.ScaleFrequency); sp->scale_factor = LittleShort(patch_data.ScaleFactor); + if (sp->scale_factor <= 2) + { + sp->scale_factor *= 1024; + } if (sp->scale_factor != 1024) { cmsg(CMSG_INFO, VERB_DEBUG, " * Scale: note %d, factor %d\n", diff --git a/src/timidity/mix.cpp b/src/timidity/mix.cpp index e4ae9af4c0..275893f74c 100644 --- a/src/timidity/mix.cpp +++ b/src/timidity/mix.cpp @@ -26,6 +26,7 @@ #include #include "timidity.h" +#include "templates.h" namespace Timidity { diff --git a/zdoom.vcproj b/zdoom.vcproj index c5c9e494f6..f4f52a748f 100644 --- a/zdoom.vcproj +++ b/zdoom.vcproj @@ -1,7 +1,7 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - @@ -944,6 +934,16 @@ Outputs=""src/$(InputName).h"" /> + + + @@ -1538,16 +1538,6 @@ Outputs="$(IntDir)\$(InputName).obj" /> - - - @@ -1558,6 +1548,16 @@ Outputs="$(IntDir)/$(InputName).obj" /> + + + @@ -1582,16 +1582,6 @@ Outputs="$(IntDir)\$(InputName).obj" /> - - - @@ -1602,6 +1592,16 @@ Outputs="$(IntDir)/$(InputName).obj" /> + + + @@ -1626,16 +1626,6 @@ Outputs="$(IntDir)\$(InputName).obj" /> - - - @@ -1646,6 +1636,16 @@ Outputs="$(IntDir)\$(InputName).obj" /> + + + @@ -1670,16 +1670,6 @@ Outputs="$(IntDir)\$(InputName).obj" /> - - - @@ -1690,6 +1680,16 @@ Outputs="$(IntDir)\$(InputName).obj" /> + + + @@ -1714,16 +1714,6 @@ Outputs="$(IntDir)\$(InputName).obj" /> - - - @@ -1734,6 +1724,16 @@ Outputs="$(IntDir)\$(InputName).obj" /> + + + @@ -1898,6 +1898,14 @@ Outputs="$(IntDir)\$(InputName).obj" /> + + + @@ -1908,14 +1916,6 @@ Outputs="$(IntDir)\$(InputName).obj" /> - - - + + + @@ -2782,14 +2790,6 @@ AdditionalIncludeDirectories="src\win32;$(NoInherit)" /> - - - @@ -3032,7 +3032,7 @@ />