SAURON's "coolant flush sound glitched and perma" is one instance of a systemic
defect. SetupPatch (L4AUDLVL.cpp) decided looping from the SAMPLE flag alone:
AL_LOOPING = (info.loop != ForceStatic)
That armed every non-ForceStatic sample -- 224 of the 603 authored zones,
including unmistakable one-shots -- as an OpenAL source that never ends on its
own. Any such sound whose note-off never arrives plays forever. Measured 1946
LoopAtWill x Transient arming events in one short session.
The sample flag expresses PERMISSION; the SOURCE decides. Three facts [T1]:
* the enum's own comments (L4AUDLVL.h:14-19) -- LoopAtWill = "will play once
OR LOOP AS DESIRED", ForceStatic = "plays only once EVEN IF LOOPED" (a
veto), LoopAlways = "ramp up and then down";
* LoopAtWill is enum value 0, i.e. the DEFAULT an unauthored sample receives
(WTPresets.cpp:37) -- it cannot mean "loop forever";
* LoopAlways, the real always-loop, is used by ZERO shipped samples.
"As desired" is the source's authored AudioRenderType (Transient=one-shot vs
Sustained=held), streamed from AUDIO*.RES (AUDLVL.cpp:28) and already consulted
by the renderer (L4AUDRND.cpp:567, AUDREND.cpp:184). SetupPatch now takes it,
threaded from all three L4AudioSource call sites (Direct/Dynamic3D/Static3D).
New rule: LoopAlways->1, ForceStatic->0, LoopAtWill->the source's render type.
MEASURED before changing behaviour (BT_LOOP_AUDIT=1, scratchpad/loopaudit.py):
LoopAtWill x Transient -> loop=0 (was 1) 1946 events
LoopAtWill x Sustained -> loop=1 unchanged 65 events
ForceStatic x Transient -> loop=0 unchanged 292 events
The engine loops (EngineAccel07_z0..z2, EngineMotor01, EnginePower01) are all
LoopAtWill/Sustained and PRESERVED -- no regression there. All 24 reclassified
samples are genuine one-shots: laser charge/fire/explosion/loaded, missile
loading, engine shift, coolant pressure inc/dec.
A/B PROOF (scratchpad/loopab.py, same session both arms, only BT_LOOP_LEGACY
differs), asking the engine's own BT_AUDIO_DUMP what is still playing with
loop=1 long after every release:
[legacy] EnginePower01, CoolantPresInc03_z2, CoolantPresDcr03_z2
[fixed] EnginePower01
The two stuck coolant sources are the reported symptom. They were eventually
reclaimed when a later trigger reused the source, which is why the bug was
intermittent -- the "perma" case is when nothing else retriggers it. The fix
removes the mechanism.
BT_LOOP_LEGACY=1 restores the old rule for a field A/B without a rebuild. The
layers to listen to are the beam sustains: LaserA/CSustain* are authored
LoopAtWill on a TRANSIENT source, so they now end with the sample instead of
looping until note-off. The render type is T1 authored data; the interpretation
that LoopAtWill defers to it is a strong reading of the enum + defaults rather
than a disassembled statement, and is flagged as such in the KB.
Plausibly bears on #32 (audio cutting in/out late in a match): a stuck looping
source holds its pool slot for the rest of the round.
Rigs: scratchpad/flushsnd.py (flush start/stop pairing), flushsnd2.py (stuck-
source hunt), loopaudit.py (the classification matrix), loopab.py (the A/B).
KB: context/wintesla-port.md audio section, context/decomp-reference.md env
table (BT_LOOP_AUDIT / BT_LOOP_LEGACY / BT_AUDIO_DUMP / BT_AUD_TAIL),
docs/AUDIO_FIDELITY.md F38. checkctx.py CLEAN.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
213 lines
5.9 KiB
C++
213 lines
5.9 KiB
C++
#pragma once
|
|
|
|
#include "..\munga\audlvl.h"
|
|
#include "l4audhdw.h"
|
|
#include "openal/al.h"
|
|
|
|
enum SampleChannel
|
|
{
|
|
CHANNEL_LEFT,
|
|
CHANNEL_RIGHT,
|
|
CHANNEL_CENTER
|
|
};
|
|
|
|
enum SampleLoop
|
|
{
|
|
LoopAtWill, //Will play once or loop as desired
|
|
ForceStatic, //Plays only once even if looped
|
|
LoopAlways, //Ramp up and then down
|
|
SampleLoopMax
|
|
};
|
|
|
|
struct SAMPLEINFO
|
|
{
|
|
int bufferIndex;
|
|
bool implemented;
|
|
const char *file;
|
|
SampleChannel chan;
|
|
SampleLoop loop;
|
|
// (task #50, AUDIO_FIDELITY F1/F13) full-zone metadata from the SF2 banks:
|
|
// the authored MIDI note SELECTS zones by [keyLo,keyHi]; loop regions are
|
|
// sub-ranges in sample frames (AL_SOFT_loop_points); releaseSec is the
|
|
// authored releaseVolEnv fade applied on Stop instead of an instant cut.
|
|
int keyLo;
|
|
int keyHi;
|
|
int loopStart;
|
|
int loopEnd;
|
|
float releaseSec;
|
|
};
|
|
|
|
// AllExplosion (bank2 p125) authors 25 layered zones -- the largest preset.
|
|
const int MAX_PRESET_SAMPLES = 25;
|
|
|
|
// Gitea #12: the SourceSet OpenAL-source array must hold one source per zone,
|
|
// so its capacity must cover the largest preset. If MAX_PRESET_SAMPLES ever
|
|
// grows past the SourceSet array, channel acquisition would overflow the heap
|
|
// (the death-crash class) -- lock the two together at compile time.
|
|
static_assert(MAX_PRESET_SAMPLES <= AUDIO_SOURCESET_CAPACITY,
|
|
"SourceSet.sources[] too small for MAX_PRESET_SAMPLES voices (Gitea #12)");
|
|
|
|
struct PRESETINFO
|
|
{
|
|
int sampleNum;
|
|
SAMPLEINFO samples[MAX_PRESET_SAMPLES];
|
|
bool is3d;
|
|
};
|
|
|
|
extern PRESETINFO allPresets[2][128];
|
|
|
|
bool PRESET_isImplemented(int bank, int preset);
|
|
int PRESET_getNumSamples(int bank, int preset);
|
|
SAMPLEINFO PRESET_getSampleInfo(int bank, int preset, int sampleInd);
|
|
void PRESET_setBufferIndex(int bank, int preset, int sampleInd, int index);
|
|
|
|
// (task #50, AUDIO_FIDELITY F13) authored release fades: StopNote registers a
|
|
// dB-linear gain ramp instead of cutting; AudioHead::Execute services them.
|
|
void PRESET_serviceReleaseFades(float elapsed_seconds);
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PatchLevelOfDetail ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
typedef MIDIValue SBKPatchID;
|
|
typedef MIDIValue SBKBankID;
|
|
|
|
class PatchLevelOfDetail:
|
|
public AudioLevelOfDetail
|
|
{
|
|
public:
|
|
//
|
|
//-----------------------------------------------------------------------
|
|
// Construction, Destruction, Testing
|
|
//-----------------------------------------------------------------------
|
|
//
|
|
PatchLevelOfDetail(PlugStream *stream);
|
|
~PatchLevelOfDetail();
|
|
|
|
void PlayNote(SourceSet sourceSet, int note);
|
|
void StopNote(SourceSet sourceSet);
|
|
|
|
Logical
|
|
TestInstance() const;
|
|
|
|
virtual AudioVoiceCount
|
|
GetVoiceCount()
|
|
{return PRESET_getNumSamples(bankID,patchID);}
|
|
|
|
// (task #50) expose the authored bank/patch so the game-side footstep
|
|
// intensity send can identify footstep sources precisely.
|
|
int GetBankID() const { return (int)bankID; }
|
|
int GetPatchID() const { return (int)patchID; }
|
|
|
|
//
|
|
//-----------------------------------------------------------------------
|
|
// BuildFromPage
|
|
//-----------------------------------------------------------------------
|
|
//
|
|
static void
|
|
BuildFromPage(
|
|
PlugStream *stream,
|
|
NameList *name_list,
|
|
ClassID class_ID,
|
|
ObjectID object_ID
|
|
);
|
|
|
|
//
|
|
//-----------------------------------------------------------------------
|
|
// Accessors
|
|
//-----------------------------------------------------------------------
|
|
//
|
|
// (Gitea #51) `sustained` carries the SOURCE's authored AudioRenderType
|
|
// (SustainedAudioRenderType vs TransientAudioRenderType, streamed from
|
|
// AUDIO*.RES). A LoopAtWill sample means "play once OR loop as desired"
|
|
// -- it is the SOURCE, not the sample, that decides. Default False keeps
|
|
// any unconverted caller on the safe one-shot behaviour.
|
|
void
|
|
SetupPatch(SourceSet sourceSet, int note, Logical sustained = False);
|
|
|
|
MIDINRPNValue
|
|
GetMaxMIDIFilterCutoff()
|
|
{return maxMIDIFilterCutoff;}
|
|
|
|
private:
|
|
//
|
|
//-----------------------------------------------------------------------
|
|
// Private data
|
|
//-----------------------------------------------------------------------
|
|
//
|
|
SBKBankID
|
|
bankID;
|
|
SBKPatchID
|
|
patchID;
|
|
MIDINRPNValue
|
|
maxMIDIFilterCutoff;
|
|
|
|
#ifdef LAB_ONLY
|
|
int
|
|
setupCount;
|
|
#endif
|
|
|
|
//
|
|
// Keep table of created patchs to verify that duplicates
|
|
// are not created
|
|
//
|
|
#if DEBUG_LEVEL>0
|
|
static TableOf<PatchLevelOfDetail*, unsigned int>
|
|
patchTableSocket;
|
|
#endif
|
|
};
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PatchResource ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
class PatchResource:
|
|
public AudioResource
|
|
{
|
|
public:
|
|
//
|
|
//-----------------------------------------------------------------------
|
|
// Construction, Destruction, Testing
|
|
//-----------------------------------------------------------------------
|
|
//
|
|
PatchResource(PlugStream *stream);
|
|
~PatchResource();
|
|
|
|
void PlayNote(SourceSet sourceSet, int note);
|
|
void StopNote(SourceSet sourceSet);
|
|
|
|
Logical
|
|
TestInstance() const;
|
|
|
|
//
|
|
//-----------------------------------------------------------------------
|
|
// BuildFromPage
|
|
//-----------------------------------------------------------------------
|
|
//
|
|
static void
|
|
BuildFromPage(
|
|
PlugStream *stream,
|
|
NameList *name_list,
|
|
ClassID class_ID,
|
|
ObjectID object_ID
|
|
);
|
|
|
|
//
|
|
//-----------------------------------------------------------------------
|
|
// Accessors
|
|
//-----------------------------------------------------------------------
|
|
//
|
|
// (Gitea #51) `sustained` carries the SOURCE's authored AudioRenderType
|
|
// (SustainedAudioRenderType vs TransientAudioRenderType, streamed from
|
|
// AUDIO*.RES). A LoopAtWill sample means "play once OR loop as desired"
|
|
// -- it is the SOURCE, not the sample, that decides. Default False keeps
|
|
// any unconverted caller on the safe one-shot behaviour.
|
|
void
|
|
SetupPatch(SourceSet sourceSet, int note, Logical sustained = False);
|
|
|
|
MIDINRPNValue
|
|
GetMaxMIDIFilterCutoff();
|
|
|
|
// (task #50) authored bank/patch pass-throughs (the LOD accessor is
|
|
// protected on AudioResource) -- zone metadata lookups at the source layer.
|
|
int GetBankID();
|
|
int GetPatchID();
|
|
};
|
|
|