Files
BT411/engine/MUNGA_L4/L4AUDLVL.h
T
arcattackandClaude Fable 5 a0cec48e3f Death-crash FIXED: 25-voice explosion preset overflowed the 5-slot audio SourceSet (Gitea #12)
The weekend's crash family root-caused under cdb: SourceSet.sources[5]
receives the AllExplosion death preset's 25 streamed voices --
RequestAudioChannels wrote 20 OpenAL source ids past the array, smashing
the neighbouring heap object (Release: a vtable overwritten with a source
id -> delayed silent AV at AudioControlEvent::Send; Debug: CRT heap-
corruption abort in the death Explosion's audio teardown).  Explains all
three #12 crash flavors (solo enemy kill -- stack-confirmed; MP self-
death; MP peer PEER_DOWN cascade -- same generic teardown).

Fix: sources[] sized to AUDIO_SOURCESET_CAPACITY=25, static_assert
lockstep with MAX_PRESET_SAMPLES, + defence-in-depth clamps at the ctor
and acquisition sites.  Soak: 26+ deaths across glass AND pod builds
under cdb, zero faults, full wreck lifecycle every time.  Gotchas S21:
the fixed-array-vs-streamed-count overflow class + sweep note.

Awaiting human verification: the MP death-and-survive session.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-20 14:51:35 -05:00

203 lines
5.1 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
//-----------------------------------------------------------------------
//
void
SetupPatch(SourceSet sourceSet, int note);
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
//-----------------------------------------------------------------------
//
void
SetupPatch(SourceSet sourceSet, int note);
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();
};