1#include "bass.h"
2#include <cmath>
3#include <cstdlib>
4#include <iostream>
5#include <limits>
6using std::isinf;
7
8static void Check(bool ok, const char* message)
9{
10 if (!ok) { std::cerr << "FAIL: " << message << " (BASS " << BASS_ErrorGetCode() << ")\n"; std::exit(1); }
11}
16struct Game { Bus* bus; } gameState{&bus};
17struct Cockpit {
float power = 1.f; }
ourcockpit;
19{
22 void UpdateWarning();
24
25
26 void PlayEx(
SOUNDS soundEnum,
bool loop,
float,
float,
float,
bool restart)
27 {
29 {
30 Check(BASS_ChannelFlags(stream, loop ? BASS_SAMPLE_LOOP : 0, BASS_SAMPLE_LOOP) !=
DWORD(-1),
"set loop flag");
31 Check(BASS_ChannelPlay(stream, !loop && restart), "play without restarting loop");
32 }
33 }
34 void Load()
35 {
37 {
38 if (*stream) Check(BASS_StreamFree(*stream), "free previous cockpit stream");
39 *stream = BASS_StreamCreateFile(FALSE, "Sounds/VMU/overspeed.mp3", 0, 0, 0);
40 Check(*stream != 0, "load current clacker recording normally");
41 }
42 }
43 void Expect(bool playing, const char* message)
44 {
45 UpdateWarning();
47 {
48 const DWORD state = BASS_ChannelIsActive(stream);
49 if (state !=
DWORD(playing ? BASS_ACTIVE_PLAYING : BASS_ACTIVE_STOPPED))
50 std::cerr <<
"power=" <<
ourcockpit.
power <<
" IAS=" << bus.IndicatedAirspeedKms
51 << " Vne=" << bus.ComputedVneKms << " expected=" << playing << " BASS state=" << state << '\n';
52 Check(state ==
DWORD(playing ? BASS_ACTIVE_PLAYING : BASS_ACTIVE_STOPPED), message);
53 }
54 }
55};
56#include "OverspeedProduction.generated.h"
57
59{
60 Check(BASS_Init(0, 44100, 0, nullptr, nullptr), "silent BASS device");
62 sound.Load();
63 bus.IndicatedAirspeedKms = .025f;
64 sound.Expect(false, "E-10 with unset Vne must not clack at low indicated airspeed");
65 bus.ComputedVneKms = .2f;
66 for (float altitude : {0.f, .01f, 5.f, 60.f, 150.f, 300.f, 60.f, 5.f, 0.f})
67 {
70 for (float ias : {0.f, .025f, .199f, .2f, .201f, 4.f, .199f, 0.f, .25f})
71 {
72 bus.IndicatedAirspeedKms = ias;
73 sound.Expect(ias > .2f, "ground, hover, cruise, ascent, coast, orbit and re-entry follow IAS and valid Vne");
74 }
75 }
76
77
78 for (float altitude : {0.f, .01f, 5.f, 60.f, 150.f, 300.f, 60.f, 5.f})
79 {
82 struct PowerCase { float value; bool expected; };
83 const PowerCase cases[] = {{.9f,true}, {.7501f,true}, {.75f,false}, {.74f,false}, {.5f,false}, {0.f,false}, {-.1f,false},
84 {std::numeric_limits<float>::infinity(),false}, {-std::numeric_limits<float>::infinity(),false},
85 {std::numeric_limits<float>::quiet_NaN(),false}};
86 for (const auto& sample : cases)
87 {
89 const bool powered = sample.expected;
90 sound.Expect(powered, "power loss stops both clacker channels despite unchanged overspeed inputs");
91 sound.Load();
92 sound.Expect(powered, "audio reload cannot bypass the cockpit power cutoff");
94 sound.Expect(true, "restored power re-arms a still-valid overspeed condition");
95 }
96 }
98 sound.Expect(false, "complete vehicle shutdown silences the clacker");
99 bus.IndicatedAirspeedKms = .025f;
101 sound.Expect(false, "restored power does not replay a cleared overspeed condition");
102 bus.ComputedVneKms = 0.f;
103 sound.Expect(false, "power restoration never enables the E-10 unset limit");
104 bus.IndicatedAirspeedKms = .25f;
105 bus.ComputedVneKms = .2f;
106 sound.Expect(true, "subsequent valid overspeed still starts normally");
107 const QWORD middle = BASS_ChannelSeconds2Bytes(sound.
sound_stream[0], .1);
108 Check(BASS_ChannelSetPosition(sound.
sound_stream[0], middle, BASS_POS_BYTE),
"seek into active recording");
109 for (int frame = 0; frame < 144; ++frame)
110 {
111 const QWORD before = BASS_ChannelGetPosition(sound.
sound_stream[0], BASS_POS_BYTE);
112 sound.Expect(true, "ongoing overspeed remains active");
113 Check(BASS_ChannelGetPosition(sound.
sound_stream[0], BASS_POS_BYTE) >= before,
"warning update does not rewind");
114 }
115 for (float limit : {0.f, -.1f, std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::quiet_NaN()})
116 {
117 bus.ComputedVneKms = limit;
118 sound.Expect(false, "invalid or absent limit stops both channels");
119 bus.ComputedVneKms = .2f;
120 sound.Expect(true, "valid limit re-arms warning");
121 }
122 for (float speed : {std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::quiet_NaN()})
123 {
124 bus.IndicatedAirspeedKms = speed;
125 sound.Expect(false, "non-finite IAS stops both channels");
126 }
127 bus.IndicatedAirspeedKms = .25f;
129 sound.Expect(false, "inside another vehicle is silent");
131 sound.Expect(true, "returning to own vehicle re-arms warning");
133 sound.Expect(false, "uninitialized altitude is silent");
135 sound.Expect(true, "valid altitude re-arms warning");
136 sound.Load();
137 sound.Expect(true, "cockpit or audio reload resumes current warning");
138 bus.ComputedVneKms = 0.f;
139 sound.Expect(false, "switching to E-10 stops old warning");
140 sound.Load();
141 sound.Expect(false, "reloading E-10 does not revive old warning");
142 Check(BASS_Free(), "clean audio shutdown");
143 std::cout << "PASS: production overspeed decision and Stop, real x64 BASS channels, E-10 unset limit, flight phases, invalid inputs, power loss/recovery, immediate stop, re-entry and reload.\n";
144}
SCRIPT_CONTROL SCRIPT_STATE const void DWORD
float IndicatedAirspeedKms
void Stop(SOUNDS soundEnum) const
HSTREAM sound_stream[SOUND_ENUMERATION]
void PlayEx(SOUNDS soundEnum, bool loop, float volume=1.0f, float frequencyMod=1.0f, float pan=0.0f, bool restart=true, bool fromOutside=false, bool partOfHull=false)
HSTREAM sound_streamFx[SOUND_ENUMERATION]
s_network_objects playerships[MAX_SCAN]
@ Game
Use the game audio system.