From 22ef66209d492e4db22563473bae5fdbb8098e1f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 15 Dec 2019 20:16:36 +0100 Subject: [PATCH] - sound is finally playing, but the volume needs balancing and positioning doesn't seem to be 100% correct. --- source/common/sound/s_sound.cpp | 71 +++++++++++++++++++++++++-- source/common/sound/s_soundinternal.h | 1 + source/duke3d/src/sounds.cpp | 3 +- 3 files changed, 70 insertions(+), 5 deletions(-) diff --git a/source/common/sound/s_sound.cpp b/source/common/sound/s_sound.cpp index 35cd5af72..66957eb21 100644 --- a/source/common/sound/s_sound.cpp +++ b/source/common/sound/s_sound.cpp @@ -35,14 +35,15 @@ #include #include -#ifdef _WIN32 -#include -#endif #include "s_soundinternal.h" #include "m_swap.h" #include "superfasthash.h" +#ifdef _WIN32 +#undef DrawText +#endif + #ifdef DEFAULT_PITCH // undefine garbage from Windows.h #undef DEFAULT_PITCH #endif @@ -1705,4 +1706,66 @@ void SoundEngine::AddRandomSound(int Owner, TArray list) S_sfx[Owner].link = index; S_sfx[Owner].bRandomHeader = true; S_sfx[Owner].NearLimit = -1; -} \ No newline at end of file +} + +#include "basics.h" +#include "stats.h" +#include "v_text.h" +//========================================================================== +// +// S_NoiseDebug +// +// [RH] Print sound debug info. Called by status bar. +//========================================================================== + +FString SoundEngine::NoiseDebug() +{ + FVector3 listener; + FVector3 origin; + + FString out = "*** SOUND DEBUG INFO ***\n" + "x y z vol dist chan pri flags aud pos name\n"; + + + if (Channels == nullptr) + { + return out; + } + + + listener = this->listener.position; + int ch = 0; + for (auto chan = Channels; chan; chan = chan->NextChan) + { + if (!(chan->ChanFlags & CHAN_IS3D)) + { + out += "--- --- --- --- "; + } + else + { + CalcPosVel(chan, &origin, nullptr); + out.AppendFormat(TEXTCOLOR_GOLD "%5.0f | %5.0f | %5.0f | %5.0f ", origin.X, origin.Z, origin.Y, (origin - listener).Length()); + } + out.AppendFormat("%-.2g %-4d %-4d %s3%sZ%sU%sM%sN%sA%sL%sE%sV" TEXTCOLOR_GOLD " %-5.4f %-4u %s\n", chan->Volume, chan->EntChannel, chan->Priority, + (chan->ChanFlags & CHAN_IS3D) ? TEXTCOLOR_GREEN : TEXTCOLOR_BLACK, + (chan->ChanFlags & CHAN_LISTENERZ) ? TEXTCOLOR_GREEN : TEXTCOLOR_BLACK, + (chan->ChanFlags & CHAN_UI) ? TEXTCOLOR_GREEN : TEXTCOLOR_BLACK, + (chan->ChanFlags & CHAN_MAYBE_LOCAL) ? TEXTCOLOR_GREEN : TEXTCOLOR_BLACK, + (chan->ChanFlags & CHAN_NOPAUSE) ? TEXTCOLOR_GREEN : TEXTCOLOR_BLACK, + (chan->ChanFlags & CHAN_AREA) ? TEXTCOLOR_GREEN : TEXTCOLOR_BLACK, + (chan->ChanFlags & CHAN_LOOP) ? TEXTCOLOR_GREEN : TEXTCOLOR_BLACK, + (chan->ChanFlags & CHAN_EVICTED) ? TEXTCOLOR_GREEN : TEXTCOLOR_BLACK, + (chan->ChanFlags & CHAN_VIRTUAL) ? TEXTCOLOR_GREEN : TEXTCOLOR_BLACK, + GSnd->GetAudibility(chan), GSnd->GetPosition(chan), S_sfx[chan->SoundID].name.GetChars()); + ch++; + } + out.AppendFormat("%d channels\n", ch); + return out; +} + +ADD_STAT(sounddebug) +{ + return soundEngine->NoiseDebug(); +} + + diff --git a/source/common/sound/s_soundinternal.h b/source/common/sound/s_soundinternal.h index e8c28d61d..f2f58102c 100644 --- a/source/common/sound/s_soundinternal.h +++ b/source/common/sound/s_soundinternal.h @@ -345,6 +345,7 @@ public: void Reset(); void MarkUsed(int num); void CacheMarkedSounds(); + FString NoiseDebug(); TArray AllActiveChannels(); void MarkAllUnused() diff --git a/source/duke3d/src/sounds.cpp b/source/duke3d/src/sounds.cpp index 97db6de22..3ddba504d 100644 --- a/source/duke3d/src/sounds.cpp +++ b/source/duke3d/src/sounds.cpp @@ -155,6 +155,7 @@ int S_DefineSound(unsigned index, const char *filename, int minpitch, int maxpit sfx->Volume = volume; sfx->NearLimit = 4; sfx->bTentative = false; + sfx->name = filename; return 0; } @@ -354,7 +355,7 @@ void S_Update(void) { listener.angle = (float)ca * pi::pi() / 2048; // todo: Check value range for angle. listener.velocity.Zero(); - listener.position = { c->x / 16.f, c->z / 256.f, c->y / 16.f }; + listener.position = { c->x / 16.f, c->z / 256.f, -c->y / 16.f }; listener.underwater = false; // This should probably use a real environment instead of the pitch hacking in S_PlaySound3D. // listenactor->waterlevel == 3;