Rise
The Vieneo Province
Loading...
Searching...
No Matches
VMU.cpp
Go to the documentation of this file.
1#include "Module.h"
2#include "OrbitEntryAudio.h"
3#include "LandingGearStatus.h"
4
5void Vmu::FrameMove(float fElapsed)
6{
7 if (!sound)
8 return;
9 float voiceGain = 1.f;
10 bool startedVoiceThisTurn = false;
11 const auto playVoice = [&](SOUNDS voice) {
13 startedVoiceThisTurn = true;
14 return sound->Play(voice,voiceGain);
15 };
16 const auto playPullUp = [&](bool predictive) {
17 float duration = playVoice(predictive ? SOUND_TA_PULLUP : SOUND_GPWSPULLUP);
18 // A pending vehicle voice clone must not silence an existing warning.
19 if (predictive && duration <= 0) duration = playVoice(SOUND_GPWSPULLUP);
20 return duration;
21 };
22
23 if (!powered)
24 {
25 if (ourcockpit.power > 0.75f)
26 {
27 secondsPowered += fElapsed;
28 if (secondsPowered >= 2.0f)
29 {
30 powered = true;
31 bus->vmuHold = playVoice(SOUND_AURALUNITOKAY);
32 }
33 }
34 else secondsPowered = 0.0f; // Warm-up requires uninterrupted power.
35 }
36 else
37 {
38 if (ourcockpit.power <= 0.75f)
39 {
40 powered = false;
41 secondsPowered = 0.0f;
42 }
43 }
44
45 const bool terrainAllowed = powered && bus->GPWS.terrain.enabled && bus->GPWS.IsTerrainAlert() &&
46 !bus->GPWS.inhibited &&
47 TerrainAwareness::Allowed(playerships[0].isSimulator, playerships[0].groundvehicle,
48 playerships[0].reference == REF_APNMODE || playerships[0].reference == REF_ACLMODE, ourcockpit.power);
49 const bool predictiveWindAllowed = powered && !playerships[0].isSimulator && !playerships[0].groundvehicle &&
53 // Validate predictive commands again at playback, including directly injected
54 // TA phrases. Shared Terrain Terrain/Pull Up commands still serve reactive GPWS.
55 bus->commandStream.erase(std::remove_if(bus->commandStream.begin(), bus->commandStream.end(), [&](const Command& c) {
56 if(c.name=="DORConfigLandingGear")
57 return !Orbital::EntryGearCalloutValid(c,bus->orbit,playerships[0].vehicleId,powered,
58 LandingGearStatus::ConfirmedExtent(ourcockpit.gearextent,
59 ourcockpit.vdat.leftStrut,ourcockpit.vdat.rightStrut,ourcockpit.vdat.noseStrut));
60 if (c.sValue == "GPWSTestAudio") return !powered || bus->GPWS.testLevel == 0;
61 const bool airborne = playerships[0].reference == REF_APNMODE || playerships[0].reference == REF_ACLMODE;
62 if (c.sValue == "GPWSPredictiveWind" || c.name == "GPWSPredictiveWindshear")
63 return !predictiveWindAllowed || !bus->GPWS.predictiveWindshear.caution ||
64 c.sValue != "GPWSPredictiveWind" || bus->GPWS.Alert != Bus::Gpws::Predictive_Windshear_Caution ||
65 c.ivalues[1] != playerships[0].vehicleId;
66 if (c.sValue == "GPWSReactive") return !powered || !airborne || (bus->GPWS.inhibited && c.ivalues[0] != Bus::Gpws::Mode6_Bank_Angle) || c.ivalues[0] != bus->GPWS.Alert;
67 if (c.sValue == "GPWSAltitude") return !powered || !airborne;
68 const bool terrainPhrase = c.name == "GPWSCautionTerrain" ||
69 c.name == "GPWSCautionObstacle" || c.name == "GPWSObstacleObstacle";
70 return (c.sValue == "GPWSTerrain" || terrainPhrase) &&
71 (!terrainAllowed || c.sValue != "GPWSTerrain" || c.ivalues[0] != bus->GPWS.Alert ||
72 unsigned(c.ivalues[1]) != bus->GPWS.terrainRevision);
73 }), bus->commandStream.end());
74 // Alert revisions invalidate queued commands, never the words currently
75 // being spoken. Only physical shutdown/vehicle changes, predictive-mode
76 // exclusion, and explicit self-test cancellation cut an active recording.
77 const bool terrainExcluded = playingTerrain && !TerrainAwareness::Allowed(
78 playerships[0].isSimulator,playerships[0].groundvehicle,
79 playerships[0].reference == REF_APNMODE || playerships[0].reference == REF_ACLMODE,ourcockpit.power);
80 const bool testCancelled = playingTcas != SOUND_NONE &&
82 if (playingVoice != SOUND_NONE && (!powered || playingVehicle != playerships[0].vehicleId ||
83 terrainExcluded || (playingPredictiveWind && !predictiveWindAllowed) || testCancelled || (playingGpwsTest && !bus->GPWS.testLevel) ||
85 {
88 bus->vmuHold = 0;
89 }
90 const bool gpwsAlert = (bus->GPWS.Alert != Bus::Gpws::NoAlert &&
93 testMode = static_cast<SOUNDS>(SOUND_AURALUNITOKAY + 1);
94 if (!powered)
95 {
96 testMode = static_cast<SOUNDS>(SOUND_AURALUNITOKAY + 1);
97 return;
98 }
99
100 // this keeps sounds from playing concurrently
101 // The warm-up phrase starts now, not at the beginning of the elapsed interval.
102 if (!startedVoiceThisTurn) bus->vmuHold -= fElapsed;
103 if (bus->vmuHold > 0.0f)
104 return;
108
109 // so we have one-shot aural response like "priority pilot"
110 // we have ongoing aural warnings like "dual input" based on a bus value
111 // we also have ongoing warnings added from GPWS like "pull up" and "stall" from the FCS (these could be bus conditions)
112 // GPWS alerts inhibit queued TCAS speech; the active phrase finishes first.
113 for (UINT i = 0; i < bus->commandStream.size(); i++)
114 {
115 const Command command = bus->commandStream.at(i);
116 if (command.delay > 0)
117 continue;
118
119 voiceGain = std::isfinite(command.fValue) && command.fValue > 0 ? command.fValue : 1.f;
120 playingTerrain = command.sValue == "GPWSTerrain";
121 playingPredictiveWind = command.sValue == "GPWSPredictiveWind";
122 playingGpwsTest = command.sValue == "GPWSTestAudio";
123 playingGpwsHazard = playingTerrain || playingPredictiveWind || (command.sValue == "GPWSReactive" && command.ivalues[0] != Bus::Gpws::Mode6_Bank_Angle);
124 bool erase = true;
125 const int tcasCallout = TcasAudio::Find(command.name.c_str());
126 if (tcasCallout >= 0)
127 {
128 const bool live = command.sValue == "TCASLive";
129 if ((!live || static_cast<unsigned>(command.ivalues[0]) == bus->TCASRevision) &&
131 bus->TCASInhibited, powered, gpwsAlert))
132 {
133 playingTcas = static_cast<SOUNDS>(SOUND_TCASTRAFFIC + tcasCallout);
134 playingTcasTest = command.bValue;
135 playingVmuTest = false;
136 bus->vmuHold = playVoice(playingTcas);
137 if (command.bValue) bus->TCASTestCallout = tcasCallout;
138 }
139 }
140 else if (command.name == "VMUTest")
141 {
142 logger->Log("VMU: Got a VMUTest command off the bus!");
143 if (!gpwsAlert && !bus->TCASTestActive && testMode > SOUND_AURALUNITOKAY)
144 {
146 logger->Log("VMU: Started VMU test!");
147 }
148 else
149 {
150 testMode = static_cast<SOUNDS>(SOUND_AURALUNITOKAY + 1); // stop
151 logger->Log("VMU: Stopped VMU test!");
152 }
153 }
154 else if (command.name == "CASConfigBrake")
155 bus->vmuHold = playVoice(SOUND_CONFIGBRAKE);
156 else if (command.name == "DORConfigLandingGear")
157 bus->vmuHold = playVoice(SOUND_CONFIGLANDINGGEAR);
158 else if (command.name == "CASConfigAF")
159 bus->vmuHold = playVoice(SOUND_CONFIGAF);
160 else if (command.name == "CASConfigFlaps")
161 bus->vmuHold = playVoice(SOUND_CONFIGFLAPS);
162 else if (command.name == "CASConfigTrim")
163 bus->vmuHold = playVoice(SOUND_CONFIGTRIM);
164 else if (command.name == "CASConfigSpoilers")
165 bus->vmuHold = playVoice(SOUND_CONFIGSPOILERS);
166 else if (command.name == "CASCabinPressure")
167 bus->vmuHold = playVoice(SOUND_CABINPRESSURE);
168 else if (command.name == "GPWSPullUp")
169 bus->vmuHold = playPullUp(playingTerrain);
170 else if (command.name == "GPWSTerrain")
171 bus->vmuHold = playVoice(SOUND_GPWSTERRAIN);
172 else if (command.name == "GPWSTestAcknowledge")
173 bus->vmuHold = playVoice(SOUND_AURALUNITOKAY);
174 else if (command.name == "GPWSTerrainTerrain")
176 else if (command.name == "GPWSCautionTerrain")
178 else if (command.name == "GPWSCautionObstacle")
180 else if (command.name == "GPWSObstacleObstacle")
182 else if (command.name == "GPWSTooLowTerrain")
183 bus->vmuHold = playVoice(SOUND_GPWSTOOLOWTERRAIN);
184 else if (command.name == "GPWSTooLowGear")
185 bus->vmuHold = playVoice(SOUND_GPWSTOOLOWGEAR);
186 else if (command.name == "GPWSTooLowFlaps")
187 bus->vmuHold = playVoice(SOUND_GPWSTOOLOWFLAPS);
188 else if (command.name == "GPWSSinkRate")
189 bus->vmuHold = playVoice(SOUND_GPWSSINKRATE);
190 else if (command.name == "GPWSBankAngle")
191 bus->vmuHold = playVoice(SOUND_GPWSBANKANGLE);
192 else if (command.name == "GPWSGlideslope")
193 {
194 bus->vmuHold = playVoice(SOUND_GPWSGLIDESLOPE);
195 }
196 else if (command.name == "GPWSMode6Retard")
197 bus->vmuHold = playVoice(SOUND_GPWSRETARD);
198 else if (command.name == "GPWSMode6Ten")
199 bus->vmuHold = playVoice(SOUND_GPWSTEN);
200 else if (command.name == "GPWSMode6Twenty")
201 bus->vmuHold = playVoice(SOUND_GPWSTWENTY);
202 else if (command.name == "GPWSMode6Thirty")
203 bus->vmuHold = playVoice(SOUND_GPWSTHIRTY);
204 else if (command.name == "GPWSMode6Forty")
205 bus->vmuHold = playVoice(SOUND_GPWSFORTY);
206 else if (command.name == "GPWSMode6Fifty")
207 bus->vmuHold = playVoice(SOUND_GPWSFIFTY);
208 else if (command.name == "GPWSMode6OneHundred")
209 bus->vmuHold = playVoice(SOUND_GPWSONEHUNDRED);
210 else if (command.name == "GPWSMode6TwoHundred")
211 bus->vmuHold = playVoice(SOUND_GPWSTWOHUNDRED);
212 else if (command.name == "GPWSMode6Minimums")
213 bus->vmuHold = playVoice(SOUND_GPWSMINIMUMS);
214 else if (command.name == "GPWSMode6PositiveRate")
215 bus->vmuHold = playVoice(SOUND_GPWSPOSITIVERATE);
216 else if (command.name == "GPWSMode6FiveHundred")
217 bus->vmuHold = playVoice(SOUND_GPWSFIVEHUNDRED);
218 else if (command.name == "GPWSMode6OneThousand")
219 bus->vmuHold = playVoice(SOUND_GPWSONETHOUSAND);
220 else if (command.name == "GPWSMode6Rotate")
221 bus->vmuHold = playVoice(SOUND_GPWSROTATE);
222 else if (command.name == "GPWSMode3DontSink")
223 bus->vmuHold = playVoice(SOUND_GPWSDONTSINK);
224 else if (command.name == "GPWSMode7WindshearWarning")
226 else if (command.name == "GPWSMode7WindshearCaution" || command.name == "GPWSPredictiveWindshear")
228 else if (command.name == "AuralScannerSync")
229 bus->vmuHold = playVoice(SOUND_SCANNERSYNC);
230 else if (command.name == "AuralSoundBarrier")
232 else if (command.name == "AuralHullIonization")
234 else if (command.name == "AuralGearDown")
235 bus->vmuHold = playVoice(SOUND_MONROEGEARDOWN);
236 else if (command.name == "AuralAllMooringsCleared")
238 else if (command.name == "AuralCargoBay")
239 bus->vmuHold = playVoice(SOUND_MONROECARGOBAY);
240 else if (command.name == "AuralStall")
241 bus->vmuHold = playVoice(SOUND_STALL);
242 else if (command.name == "AuralAOA")
243 bus->vmuHold = playVoice(SOUND_AOA);
244 else if (command.name == "AuralLowFuel")
245 bus->vmuHold = playVoice(SOUND_COCKPITLOWFUEL);
246 else if (command.name == "AuralReverseThrust")
247 bus->vmuHold = playVoice(SOUND_REVERSETHRUST);
248 else if (command.name == "AuralForwardThrust")
249 bus->vmuHold = playVoice(SOUND_FORWARDTHRUST);
250 else if (command.name == "CASGearDisagree")
251 bus->vmuHold = playVoice(SOUND_GEARDISAGREE);
252 else if (command.name == "AuralAirspeedAlive")
253 bus->vmuHold = playVoice(SOUND_AIRSPEEDALIVE);
254 else if (command.name == "AuralV1")
255 bus->vmuHold = playVoice(SOUND_V1);
256 else if (command.name == "AuralV2")
257 bus->vmuHold = playVoice(SOUND_V2);
258 else if (command.name == "AuralInTransit")
259 bus->vmuHold = playVoice(SOUND_INTRANSIT);
260 else if (command.name == "AuralLocalizerAlive")
261 bus->vmuHold = playVoice(SOUND_LOCALIZERALIVE);
262 else if (command.name == "AuralLocalizerCaptured")
263 bus->vmuHold = playVoice(SOUND_LOCALIZERCAPTURED);
264 else if (command.name == "AuralGlideslopeAlive")
265 bus->vmuHold = playVoice(SOUND_GLIDESLOPEALIVE);
266 else if (command.name == "AuralGlideslopeCaptured")
268 else
269 erase = false;
270 if (erase)
271 {
272 if (playingTerrain && bus->vmuHold <= 0 &&
273 (command.name == "GPWSTerrainTerrain" || command.name == "GPWSObstacleObstacle"))
274 bus->vmuHold = playPullUp(true);
275 bus->commandStream.erase(bus->commandStream.begin() + i);
276 if (command.name == "GPWSGlideslope" && command.ivalues[1] == 2 && bus->vmuHold > 0)
277 {
278 Command second = command; second.ivalues[1] = 0;
279 second.timeOnStack = 0; second.ttl = bus->vmuHold+2;
280 bus->commandStream.insert(bus->commandStream.begin()+i,second);
281 }
282 break;
283 }
284 }
285
286 voiceGain = 1.f;
288 {
290 testMode = static_cast<SOUNDS>(SOUND_TA_OBSTACLE_WARNING+1);
292 {
293 if (gpwsAlert)
294 testMode = static_cast<SOUNDS>(SOUND_TCASTESTOK + 1);
295 else
296 {
298 playingVmuTest = true;
299 }
300 }
301 bus->vmuHold = playVoice(testMode);
302 testMode = static_cast<SOUNDS>(testMode + 1);
303 if (bus->vmuHold > 0)
304 bus->vmuHold += 0.5f;
305 }
306}
307
308Vmu::Vmu(Bus* prmBus, Logger* prmLogger, Sound* prmSound) : Module(prmBus)
309{
310 logger = prmLogger;
311 sound = prmSound;
312}
@ REF_ACLMODE
Definition ServerTypes.h:44
@ REF_APNMODE
Definition ServerTypes.h:42
SOUNDS
Definition Sound.h:23
@ SOUND_AIRSPEEDALIVE
Definition Sound.h:106
@ SOUND_GPWSTOOLOWFLAPS
Definition Sound.h:49
@ SOUND_GPWSTHIRTY
Definition Sound.h:55
@ SOUND_INTRANSIT
Definition Sound.h:109
@ SOUND_GPWSPOSITIVERATE
Definition Sound.h:65
@ SOUND_CONFIGAF
Definition Sound.h:94
@ SOUND_TCASTESTOK
Definition Sound.h:88
@ SOUND_CONFIGLANDINGGEAR
Definition Sound.h:98
@ SOUND_GPWSDONTSINK
Definition Sound.h:64
@ SOUND_TA_CAUTION_OBSTACLE
Definition Sound.h:69
@ SOUND_GPWSFIVEHUNDRED
Definition Sound.h:61
@ SOUND_AURALUNITOKAY
Definition Sound.h:114
@ SOUND_GPWSTEN
Definition Sound.h:53
@ SOUND_CONFIGSPOILERS
Definition Sound.h:97
@ SOUND_GLIDESLOPECAPTURED
Definition Sound.h:113
@ SOUND_MONROEALLMOORINGSCLEARED
Definition Sound.h:91
@ SOUND_TCASTRAFFIC
Definition Sound.h:74
@ SOUND_CONFIGFLAPS
Definition Sound.h:95
@ SOUND_GPWSMINIMUMS
Definition Sound.h:60
@ SOUND_AOA
Definition Sound.h:170
@ SOUND_COCKPITLOWFUEL
Definition Sound.h:40
@ SOUND_NONE
Definition Sound.h:24
@ SOUND_GLIDESLOPEALIVE
Definition Sound.h:112
@ SOUND_MONROESOUNDBARRIER
Definition Sound.h:100
@ SOUND_MONROEGEARDOWN
Definition Sound.h:92
@ SOUND_GPWSTOOLOWTERRAIN
Definition Sound.h:47
@ SOUND_GPWSTOOLOWGEAR
Definition Sound.h:48
@ SOUND_MONROEHULLIONIZATION
Definition Sound.h:99
@ SOUND_GPWSTWOHUNDRED
Definition Sound.h:59
@ SOUND_GPWSBANKANGLE
Definition Sound.h:50
@ SOUND_GPWSFORTY
Definition Sound.h:56
@ SOUND_LOCALIZERCAPTURED
Definition Sound.h:111
@ SOUND_GPWSPULLUP
Definition Sound.h:45
@ SOUND_GPWSGLIDESLOPE
Definition Sound.h:51
@ SOUND_REVERSETHRUST
Definition Sound.h:103
@ SOUND_GPWSFIFTY
Definition Sound.h:57
@ SOUND_V1
Definition Sound.h:107
@ SOUND_SCANNERSYNC
Definition Sound.h:101
@ SOUND_GEARDISAGREE
Definition Sound.h:105
@ SOUND_TA_OBSTACLE_WARNING
Definition Sound.h:70
@ SOUND_GPWSROTATE
Definition Sound.h:63
@ SOUND_MONROECARGOBAY
Definition Sound.h:90
@ SOUND_CABINPRESSURE
Definition Sound.h:104
@ SOUND_CONFIGBRAKE
Definition Sound.h:93
@ SOUND_GPWSRETARD
Definition Sound.h:52
@ SOUND_GPWSTWENTY
Definition Sound.h:54
@ SOUND_FORWARDTHRUST
Definition Sound.h:102
@ SOUND_TA_PULLUP
Definition Sound.h:72
@ SOUND_GPWSWINDSHEARCAUTION
Definition Sound.h:67
@ SOUND_GPWSTERRAIN
Definition Sound.h:71
@ SOUND_AURALUNITTESTA
Definition Sound.h:38
@ SOUND_CONFIGTRIM
Definition Sound.h:96
@ SOUND_STALL
Definition Sound.h:41
@ SOUND_GPWSONEHUNDRED
Definition Sound.h:58
@ SOUND_V2
Definition Sound.h:108
@ SOUND_LOCALIZERALIVE
Definition Sound.h:110
@ SOUND_GPWSWINDSHEARWARNING
Definition Sound.h:66
@ SOUND_GPWSTERRAINTERRAIN
Definition Sound.h:46
@ SOUND_TA_CAUTION_TERRAIN
Definition Sound.h:68
@ SOUND_GPWSONETHOUSAND
Definition Sound.h:62
@ SOUND_GPWSSINKRATE
Definition Sound.h:44
Definition Bus.h:20
int TCASTestCallout
Definition Bus.h:342
struct Bus::Gpws GPWS
bool TCASTestActive
Definition Bus.h:341
bool TCASInhibited
Definition Bus.h:340
float RadioAltitudeKm
Definition Bus.h:157
unsigned TCASRevision
Definition Bus.h:345
std::vector< Command > commandStream
Definition Bus.h:442
float vmuHold
Definition Bus.h:507
void Log(const char *msg, Level level=Info, int errorCode=0)
Definition Logger.cpp:283
Bus * bus
Definition Module.h:21
Definition Sound.h:369
void Stop(SOUNDS soundEnum) const
Definition Sound.cpp:3397
float Play(SOUNDS soundEnum, float volume=1.0f)
Definition Sound.cpp:802
bool playingGpwsHazard
Definition Module.h:127
Vmu(Bus *prmBus, Logger *prmLogger, Sound *prmSound)
Definition VMU.cpp:308
bool playingPredictiveWind
Definition Module.h:123
int playingVehicle
Definition Module.h:128
bool powered
Definition Module.h:117
void FrameMove(float fElapsedTime) override
Definition VMU.cpp:5
bool playingTcasTest
Definition Module.h:124
bool playingVmuTest
Definition Module.h:125
SOUNDS playingVoice
Definition Module.h:121
bool playingGpwsTest
Definition Module.h:126
bool playingTerrain
Definition Module.h:122
float secondsPowered
Definition Module.h:118
SOUNDS playingTcas
Definition Module.h:120
Logger * logger
Definition Module.h:114
Sound * sound
Definition Module.h:115
SOUNDS testMode
Definition Module.h:119
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
Scockpit ourcockpit
Definition globals.cpp:114
bool HeightAllowed(float radioKm)
int Find(const char *command)
Definition TcasAudio.h:38
bool ShouldPlay(bool testCallout, bool testActive, bool liveInhibited, bool powered, bool gpwsAlert)
Definition TcasAudio.h:52
bool Allowed(bool simulator, bool groundVehicle, bool airborne, float power)
bool inhibited
Definition Bus.h:250
@ NoAlert
Definition Bus.h:190
@ Mode6_Bank_Angle
Definition Bus.h:228
@ Reset
Definition Bus.h:247
unsigned faults
Definition Bus.h:259
bool IsTerrainAlert() const
Definition Bus.h:266
enum Bus::Gpws::GpwsEnum Alert
int testLevel
Definition Bus.h:260
TerrainAwareness::State terrain
Definition Bus.h:264
std::string sValue
Definition Command.h:20
float timeOnStack
Definition Command.h:14
float fValue
Definition Command.h:25
bool bValue
Definition Command.h:22
int ivalues[2]
Definition Command.h:21
std::string name
Definition Command.h:11
float delay
Definition Command.h:8
float ttl
Definition Command.h:17
float power
Definition globals.h:599
bool weatherRadarEquipped
Definition globals.h:669
bool weatherRadarPower
Definition globals.h:597
unsigned short vehicleId
Definition globals.h:537