Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/OverspeedAudioTests.cpp

Source at documentation-generation time. See Test catalog for fixture associations.

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}
12enum SOUNDS { SOUND_OVERSPEED };
14struct Player { int reference = REF_APNMODE; float mslKm = 1.f; } playerships[1];
15struct Bus { float IndicatedAirspeedKms = 0.f, ComputedVneKms = 0.f; } bus;
16struct Game { Bus* bus; } gameState{&bus};
17struct Cockpit { float power = 1.f; } ourcockpit;
18struct Sound
19{
20 Game* game = &gameState;
21 HSTREAM sound_stream[1]{}, sound_streamFx[1]{};
22 void UpdateWarning();
23 void Stop(SOUNDS soundEnum) const;
24 // Model unchanged PlayEx with native BASS playback. Run both channels so
25 // production Stop must silence either camera path; no audible output device.
26 void PlayEx(SOUNDS soundEnum, bool loop, float, float, float, bool restart)
27 {
28 for (HSTREAM stream : {sound_stream[soundEnum], sound_streamFx[soundEnum]})
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 {
36 for (HSTREAM* stream : {sound_stream, sound_streamFx})
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();
46 for (HSTREAM stream : {sound_stream[0], sound_streamFx[0]})
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
58int main()
59{
60 Check(BASS_Init(0, 44100, 0, nullptr, nullptr), "silent BASS device");
61 Sound sound;
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 {
68 playerships[0].mslKm = altitude;
69 playerships[0].reference = altitude == 0 ? REF_ONGROUND : REF_APNMODE;
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 // Keep the overspeed inputs unchanged while the electrical power falls.
77 // Run the same stop/recovery behavior on the ground and at flight altitudes.
78 for (float altitude : {0.f, .01f, 5.f, 60.f, 150.f, 300.f, 60.f, 5.f})
79 {
80 playerships[0].mslKm = altitude;
81 playerships[0].reference = altitude == 0 ? REF_ONGROUND : REF_APNMODE;
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 {
88 ourcockpit.power = sample.value;
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");
93 ourcockpit.power = 1.f;
94 sound.Expect(true, "restored power re-arms a still-valid overspeed condition");
95 }
96 }
97 ourcockpit.power = 0.f;
98 sound.Expect(false, "complete vehicle shutdown silences the clacker");
99 bus.IndicatedAirspeedKms = .025f;
100 ourcockpit.power = 1.f;
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");
132 playerships[0].mslKm = -1.f;
133 sound.Expect(false, "uninitialized altitude is silent");
134 playerships[0].mslKm = 1.f;
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
@ REF_ACLMODE
Definition ServerTypes.h:44
@ REF_INANOTHER
Definition ServerTypes.h:45
@ REF_APNMODE
Definition ServerTypes.h:42
@ REF_ONGROUND
Definition ServerTypes.h:43
SOUNDS
Definition Sound.h:23
@ SOUND_OVERSPEED
Definition Sound.h:42
Definition Bus.h:20
float IndicatedAirspeedKms
Definition Bus.h:34
float ComputedVneKms
Definition Bus.h:38
Definition Sound.h:369
void Stop(SOUNDS soundEnum) const
Definition Sound.cpp:3397
GameClass * game
Definition Sound.h:374
HSTREAM sound_stream[SOUND_ENUMERATION]
Definition Sound.h:381
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)
Definition Sound.cpp:1006
HSTREAM sound_streamFx[SOUND_ENUMERATION]
Definition Sound.h:382
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
Scockpit ourcockpit
Definition globals.cpp:114
@ Game
Use the game audio system.
Definition discordpp.h:505
float power
Definition globals.h:599