- sound is finally playing, but the volume needs balancing and positioning doesn't seem to be 100% correct.

This commit is contained in:
Christoph Oelckers 2019-12-15 20:16:36 +01:00
parent 4f9eda189a
commit 22ef66209d
3 changed files with 70 additions and 5 deletions

View file

@ -35,14 +35,15 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef _WIN32
#include <io.h>
#endif
#include "s_soundinternal.h" #include "s_soundinternal.h"
#include "m_swap.h" #include "m_swap.h"
#include "superfasthash.h" #include "superfasthash.h"
#ifdef _WIN32
#undef DrawText
#endif
#ifdef DEFAULT_PITCH // undefine garbage from Windows.h #ifdef DEFAULT_PITCH // undefine garbage from Windows.h
#undef DEFAULT_PITCH #undef DEFAULT_PITCH
#endif #endif
@ -1705,4 +1706,66 @@ void SoundEngine::AddRandomSound(int Owner, TArray<uint32_t> list)
S_sfx[Owner].link = index; S_sfx[Owner].link = index;
S_sfx[Owner].bRandomHeader = true; S_sfx[Owner].bRandomHeader = true;
S_sfx[Owner].NearLimit = -1; S_sfx[Owner].NearLimit = -1;
} }
#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();
}

View file

@ -345,6 +345,7 @@ public:
void Reset(); void Reset();
void MarkUsed(int num); void MarkUsed(int num);
void CacheMarkedSounds(); void CacheMarkedSounds();
FString NoiseDebug();
TArray<FSoundChan*> AllActiveChannels(); TArray<FSoundChan*> AllActiveChannels();
void MarkAllUnused() void MarkAllUnused()

View file

@ -155,6 +155,7 @@ int S_DefineSound(unsigned index, const char *filename, int minpitch, int maxpit
sfx->Volume = volume; sfx->Volume = volume;
sfx->NearLimit = 4; sfx->NearLimit = 4;
sfx->bTentative = false; sfx->bTentative = false;
sfx->name = filename;
return 0; return 0;
} }
@ -354,7 +355,7 @@ void S_Update(void)
{ {
listener.angle = (float)ca * pi::pi() / 2048; // todo: Check value range for angle. listener.angle = (float)ca * pi::pi() / 2048; // todo: Check value range for angle.
listener.velocity.Zero(); 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; listener.underwater = false;
// This should probably use a real environment instead of the pitch hacking in S_PlaySound3D. // This should probably use a real environment instead of the pitch hacking in S_PlaySound3D.
// listenactor->waterlevel == 3; // listenactor->waterlevel == 3;