19 HSTREAM CreateFileSound(
int soundEnum,
const char* path,
int& error)
21 const HSTREAM stream = BASS_StreamCreateFile(FALSE, path, 0, 0, 0);
22 error = BASS_ErrorGetCode();
26 constexpr float OutdoorEngineReferenceDistanceKm = 0.1f;
27 constexpr float DistantJetMaxAudibleDistanceKmAtOneAtmosphere = 50.0f;
28 constexpr float RocketRippingMaxAudibleDistanceKmAtOneAtmosphere = 80.0f;
29 constexpr float RocketRippingThresholdNewtons = 513000.0f;
30 constexpr float RocketRippingRecordingThrustNewtons = 7607000.0f;
31 constexpr float RocketRippingRecordingDistanceKm = 4.4f;
32 constexpr float RocketRippingThrustExponent = 4.0f;
34 bool IsInterfaceSound(
SOUNDS soundEnum)
40 bool IsInvalidFloat(
float value)
42 return _isnan(value) || isinf(value);
45 float GetAtmosphericSoundPressureGain(
float relativePressure)
47 if (relativePressure <= 0.0f || IsInvalidFloat(relativePressure))
57 float GetOutdoorEngineDistanceGain(
float distanceKm)
59 if (distanceKm <= OutdoorEngineReferenceDistanceKm)
65 return OutdoorEngineReferenceDistanceKm / distanceKm;
73 const DWORD bassVersion = BASS_GetVersion();
74 const DWORD fxVersion = BASS_FX_GetVersion();
75 char versionMessage[128];
76 sprintf_s(versionMessage,
sizeof versionMessage,
"Audio runtimes: BASS %lu.%lu.%lu.%lu; BASS_FX %lu.%lu.%lu.%lu",
77 bassVersion >> 24, (bassVersion >> 16) & 255, (bassVersion >> 8) & 255, bassVersion & 255,
78 fxVersion >> 24, (fxVersion >> 16) & 255, (fxVersion >> 8) & 255, fxVersion & 255);
79 Trace(versionMessage);
81 if (HIWORD(fxVersion) != BASSVERSION)
84 sprintf_s(msg,
sizeof msg,
"FX version does not match BASS version: %i", BASSVERSION);
97 bool hasDefaultDevice =
false;
98 int defaultBassDevice = -1;
100 BASS_DEVICEINFO info;
101 while (BASS_GetDeviceInfo(count, &info))
103 const bool isDefaultDevice = (info.flags & BASS_DEVICE_DEFAULT) && info.name && strcmp(info.name,
"Default") == 0;
107 else if (info.flags & BASS_DEVICE_ENABLED)
116 hasDefaultDevice =
true;
118 else if (info.driver)
121 swprintf_s(guidText, 64, L
"%S", &info.driver[17]);
123 if (CLSIDFromString(guidText, &clsid) == NOERROR)
131 if (!isDefaultDevice)
133 if (info.flags & BASS_DEVICE_DEFAULT)
134 defaultBassDevice = count;
146 if (!hasDefaultDevice && defaultBassDevice > 0)
163 return static_cast<int>(i);
171 return static_cast<int>(i);
194 Trace(
"Loading legacy sound driver...");
196 Trace(
"Loading comms sound driver...");
198 Trace(
"Loading VMU sound driver...");
200 Trace(
"Loading radio sound driver...");
215 std::string deviceName =
"Default";
217 if (useDefaultDevice)
220 if (defaultIndex >= 0 && defaultIndex <
static_cast<int>(
deviceBassDevices.size()))
240 if (bassDevice == -1)
243 StringFromGUID2(deviceConfig->
guid, guidText, 64);
245 sprintf_s(msg,
sizeof msg,
"Could not locate previous configuration: %S", guidText);
251 MessageBox(
Rendering::ClientWindow(), L
"Could not find one of your sound devices!", L
"Initialize Sound Device", MB_ICONWARNING | MB_OK);
260 const int initDevice = useDefaultDevice ? -1 : bassDevice;
263 if (BASS_ErrorGetCode() != BASS_ERROR_ALREADY)
266 sprintf_s(msg,
sizeof msg,
"BASS_Init failed (%i) on device: %s", BASS_ErrorGetCode(), deviceName.c_str());
269 sprintf_s(msg,
sizeof msg,
"Could not initialize your sound device: %s", deviceName.c_str());
279 if (useDefaultDevice)
282 bassDevice = BASS_GetDevice();
289 MessageBox(
Rendering::ClientWindow(), L
"Could not find a default sound device!", L
"Initialize Sound Device", MB_ICONWARNING | MB_OK);
296 deviceConfig->
bassDevice =
static_cast<char>(bassDevice);
301 deviceConfig->
bassDevice =
static_cast<char>(bassDevice);
313 BASS_SetDevice(configDevice);
334 sprintf_s(msg,
sizeof msg,
"ReleaseConfigSounds BASS_StreamFree(%i): %i", i, BASS_ErrorGetCode());
346 sprintf_s(msg,
sizeof msg,
"ReleaseConfigSounds BASS_StreamFreeFx(%i): %i", i, BASS_ErrorGetCode());
366 sprintf_s(msg,
sizeof msg,
"ReleaseConfigSounds BASS_StreamFree(g_pSoundIntro): %i", BASS_ErrorGetCode());
375 BASS_ChannelStop(
comms);
397 Trace(
"Shutting down BASS...");
399 std::vector<int> freedDevices;
403 if (bassDevice <= 0 || std::find(freedDevices.begin(), freedDevices.end(), bassDevice) != freedDevices.end())
406 BASS_SetDevice(bassDevice);
407 if (!BASS_Free() && BASS_ErrorGetCode() != BASS_ERROR_INIT)
410 sprintf_s(msg,
sizeof msg,
"BASS_Free(%i): %i", bassDevice, BASS_ErrorGetCode());
413 freedDevices.emplace_back(bassDevice);
426 sprintf_s(newmsg, 999,
"SOUND: %s", msg);
433 if (!data || length == 0)
455 sprintf_s(msg,
sizeof msg,
"PlayAudioData stream creation failed: %i (%zu bytes)", streamError, length);
470#pragma region Digital Signal Processing
471 const HFX setFx1 = BASS_ChannelSetFX(
comms, BASS_FX_BFX_BQF, 5);
475 sprintf_s(msg,
sizeof msg,
"BASS_ChannelSetFX1 error: %i", BASS_ErrorGetCode());
479 BASS_BFX_BQF highPass;
480 highPass.lFilter = BASS_BFX_BQF_HIGHPASS;
481 highPass.fCenter = 400;
483 highPass.fBandwidth = 1;
486 highPass.lChannel = BASS_BFX_CHANALL;
487 if (!BASS_FXSetParameters(setFx1, &highPass))
490 sprintf_s(msg,
sizeof msg,
"BASS_FXSetParameters1 error: %i", BASS_ErrorGetCode());
494 HFX setFx2 = BASS_ChannelSetFX(
comms, BASS_FX_BFX_BQF, 6);
498 sprintf_s(msg,
sizeof msg,
"BASS_ChannelSetFX2 error: %i", BASS_ErrorGetCode());
502 BASS_BFX_BQF lowPass;
503 lowPass.lFilter = BASS_BFX_BQF_LOWPASS;
504 lowPass.fCenter = 2000;
505 lowPass.lChannel = BASS_BFX_CHANALL;
507 lowPass.fBandwidth = 1;
510 if (!BASS_FXSetParameters(setFx2, &lowPass))
513 sprintf_s(msg,
sizeof msg,
"BASS_FXSetParameters2 error: %i", BASS_ErrorGetCode());
520 if (!BASS_ChannelPlay(
comms,
true))
523 sprintf_s(msg,
sizeof msg,
"PlayAudioData BASS_ChannelPlay error: %i", BASS_ErrorGetCode());
527 char playbackMessage[160];
528 std::snprintf(playbackMessage,
sizeof playbackMessage,
"Comms stream %lu owns %zu bytes, duration %.3fs",
529 comms, length, BASS_ChannelBytes2Seconds(
comms, BASS_ChannelGetLength(
comms, BASS_POS_BYTE)));
530 Trace(playbackMessage);
536void Sound::GlobalAttenuate(
float prmGaTimeToFadeOut,
float prmGaTimeToHold,
float prmGaTimeToFadeIn,
SOUNDS soundEnum,
float prmExTimeToFadeIn,
float prmExTimeToHold,
float prmExTimeToFadeOut,
float volumeAdj)
600 return !IsInterfaceSound(soundEnum) && soundEnum !=
SOUND_WIND_MIC &&
607 const bool interfaceSound = IsInterfaceSound(soundEnum);
629 bodyToCameraFrame = childOrientation * parentOrientation;
635 yaw, -view.camera->currentTilt, view.rolltilt, referenceDistanceKm);
640 std::array<float, EngineAudio::SlotCount> weights{};
641 for (
int engine = 0; engine < engines.count; ++engine)
646 yaw, -view.camera->currentTilt, view.rolltilt, bodyToCameraFrame, weights);
651 {view.rcsThrustOutputX, view.rcsThrustOutputY, view.rcsThrustOutputZ},
654 yaw, -view.camera->currentTilt, view.rolltilt, bodyToCameraFrame);
658 volume *= spatial.gain;
667 else if (pan < -2.0f)
672 if (!interfaceSound && fabs(pan) > 1.0f)
674 float t = fabs(pan) - 1.0f;
678 pan = (pan > 0 ? 2.0f - pan : -2.0f - pan);
681 if (!BASS_ChannelSetAttribute(streamToPlay, BASS_ATTRIB_PAN, pan))
684 sprintf_s(msg,
sizeof msg,
"PlayEx BASS_ChannelSetAttribute(%i) pan %.1f failed: %i - type %i", soundEnum, pan, BASS_ErrorGetCode(),
playerships[0].type);
686 sprintf_s(msg,
sizeof msg,
"PlayEx BASS_ChannelSetAttribute(%i) pan %.1f failed: %i", soundEnum, pan, BASS_ErrorGetCode());
689 if (BASS_ErrorGetCode() == BASS_ERROR_HANDLE)
742 sprintf_s(msg,
sizeof msg,
"PlayEx BASS_ChannelSetAttribute(%i) clamped volume: %.1f", soundEnum, volume);
746 else if (volume < 0.0f)
748 sprintf_s(msg,
sizeof msg,
"PlayEx BASS_ChannelSetAttribute(%i) clamped volume: %.1f", soundEnum, volume);
753 if (!BASS_ChannelSetAttribute(streamToPlay, BASS_ATTRIB_VOL, volume))
755 sprintf_s(msg,
sizeof msg,
"PlayEx BASS_ChannelSetAttribute(%i) vol %.1f soundConfigVol %.1f globalAtt %.1f failed: %i", soundEnum, volume,
sound_config[soundEnum]->volume,
globalAttenuate, BASS_ErrorGetCode());
771 const auto sound =
static_cast<SOUNDS>(i);
773 (BASS_ChannelIsActive(
sound_stream[i]) == BASS_ACTIVE_PLAYING ||
783 const HSTREAM stream =
GlassFX(soundEnum);
804 PlayEx(soundEnum,
false, volume);
810 Trace(
"Sound::Reset");
862 sprintf_s(msg,
sizeof msg,
"Sound Glass FX Sample (%i), \"%s\") LOW rate: %.0f", soundEnum,
sound_path[soundEnum].c_str(),
sound_rate[soundEnum]);
875 sprintf_s(msg,
sizeof msg,
"GetFileSizeBytes1(%i), \"%s\"): %zu", soundEnum,
sound_path[soundEnum].c_str(), fileSize);
885 sprintf_s(msg,
sizeof msg,
"BASS_StreamCreateFile(%i), \"%s\"): %i", soundEnum,
sound_path[soundEnum].c_str(), BASS_ErrorGetCode());
892 BASS_BFX_BQF shelfParams = {};
896 shelfParams.lFilter = BASS_BFX_BQF_HIGHSHELF;
897 shelfParams.lChannel = BASS_BFX_CHANALL;
898 if (!BASS_FXSetParameters(
sound_fxShelf[soundEnum], &shelfParams))
901 sprintf_s(msg,
sizeof msg,
"GlassFX BASS_FXSetParameters(%i) BASS_BFX_BQF_HIGHSHELF: %i", soundEnum, BASS_ErrorGetCode());
907 BASS_BFX_BQF lpParams = {};
910 lpParams.lFilter = BASS_BFX_BQF_LOWPASS;
911 lpParams.lChannel = BASS_BFX_CHANALL;
912 if (!BASS_FXSetParameters(
sound_fxLP[soundEnum], &lpParams))
915 sprintf_s(msg,
sizeof msg,
"GlassFX BASS_FXSetParameters(%i) BASS_BFX_BQF_LOWPASS: %i", soundEnum, BASS_ErrorGetCode());
921 BASS_BFX_BQF notchParams = {};
924 notchParams.fBandwidth = 1.0f;
925 notchParams.lFilter = BASS_BFX_BQF_NOTCH;
926 notchParams.lChannel = BASS_BFX_CHANALL;
927 if (!BASS_FXSetParameters(
sound_fxNotch[soundEnum], ¬chParams))
930 sprintf_s(msg,
sizeof msg,
"GlassFX BASS_FXSetParameters(%i) BASS_BFX_BQF_NOTCH: %i", soundEnum, BASS_ErrorGetCode());
937 if (BASS_ChannelIsActive(
sound_stream[soundEnum]) == BASS_ACTIVE_PLAYING)
940 BASS_ChannelSetPosition(
sound_streamFx[soundEnum], BASS_ChannelGetPosition(
sound_stream[soundEnum], BASS_POS_BYTE), BASS_POS_BYTE);
945 BASS_ChannelGetAttribute(
sound_streamFx[soundEnum], BASS_ATTRIB_VOL, &oldValue);
946 BASS_ChannelSetAttribute(
sound_stream[soundEnum], BASS_ATTRIB_VOL, oldValue);
947 BASS_ChannelGetAttribute(
sound_streamFx[soundEnum], BASS_ATTRIB_PAN, &oldValue);
948 BASS_ChannelSetAttribute(
sound_stream[soundEnum], BASS_ATTRIB_PAN, oldValue);
949 BASS_ChannelGetAttribute(
sound_streamFx[soundEnum], BASS_ATTRIB_FREQ, &oldValue);
950 BASS_ChannelSetAttribute(
sound_stream[soundEnum], BASS_ATTRIB_FREQ, oldValue);
960 if (BASS_ChannelIsActive(
sound_streamFx[soundEnum]) == BASS_ACTIVE_PLAYING)
963 BASS_ChannelSetPosition(
sound_stream[soundEnum], BASS_ChannelGetPosition(
sound_streamFx[soundEnum], BASS_POS_BYTE), BASS_POS_BYTE);
968 BASS_ChannelGetAttribute(
sound_stream[soundEnum], BASS_ATTRIB_VOL, &oldValue);
969 BASS_ChannelSetAttribute(
sound_streamFx[soundEnum], BASS_ATTRIB_VOL, oldValue);
970 BASS_ChannelGetAttribute(
sound_stream[soundEnum], BASS_ATTRIB_PAN, &oldValue);
971 BASS_ChannelSetAttribute(
sound_streamFx[soundEnum], BASS_ATTRIB_PAN, oldValue);
972 BASS_ChannelGetAttribute(
sound_stream[soundEnum], BASS_ATTRIB_FREQ, &oldValue);
973 BASS_ChannelSetAttribute(
sound_streamFx[soundEnum], BASS_ATTRIB_FREQ, oldValue);
1006void Sound::PlayEx(
SOUNDS soundEnum,
bool loop,
float volume,
float frequencyMod,
float pan,
bool restart,
bool fromOutside,
bool partOfHull)
1009 const int soundIndex =
static_cast<int>(soundEnum);
1010 static bool invalidSoundEnumReported =
false;
1013 if (!invalidSoundEnumReported)
1015 invalidSoundEnumReported =
true;
1016 sprintf_s(msg,
sizeof msg,
"PlayEx rejected invalid sound index %i", soundIndex);
1021 invalidSoundEnumReported =
false;
1024 if (IsInvalidFloat(volume) || IsInvalidFloat(frequencyMod) || IsInvalidFloat(pan))
1026 if (!invalidParametersReported[soundIndex])
1028 invalidParametersReported[soundIndex] =
true;
1029 sprintf_s(msg,
sizeof msg,
"PlayEx rejected non-finite parameters for sound %i: volume %.3f frequency %.3f pan %.3f",
1030 soundIndex, volume, frequencyMod, pan);
1035 invalidParametersReported[soundIndex] =
false;
1044 sprintf_s(msg,
sizeof msg,
"PlayEx BASS_SetDevice sound %i device %i: %i", soundEnum,
sound_device[soundEnum], BASS_ErrorGetCode());
1050 const bool interfaceSound = IsInterfaceSound(soundEnum);
1063 sprintf_s(msg,
sizeof msg,
"Sound Atmospheric FX Sample (%i), \"%s\") LOW rate: %.0f", soundEnum,
sound_path[soundEnum].c_str(),
sound_rate[soundEnum]);
1072 sprintf_s(msg,
sizeof msg,
"GetFileSizeBytes2(%i), \"%s\"): %zu", soundEnum,
sound_path[soundEnum].c_str(), fileSize);
1082 sprintf_s(msg,
sizeof msg,
"BASS_StreamCreateFile(%i), \"%s\"): %i", soundEnum,
sound_path[soundEnum].c_str(), BASS_ErrorGetCode());
1090 BASS_BFX_BQF shelfParams = {};
1091 shelfParams.fCenter = 2000.0f;
1092 shelfParams.fGain = -6.0f;
1093 shelfParams.fBandwidth = 0.7f;
1094 shelfParams.lFilter = BASS_BFX_BQF_HIGHSHELF;
1095 BASS_FXSetParameters(fxShelf, &shelfParams);
1096 fxShelf = BASS_ChannelSetFX(
sound_streamFx[soundEnum], BASS_FX_BFX_BQF, 0);
1097 BASS_FXSetParameters(fxShelf, &shelfParams);
1101 BASS_BFX_BQF lp = {};
1102 lp.fCenter = 4000.0f;
1105 lp.lFilter = BASS_BFX_BQF_LOWPASS;
1106 BASS_FXSetParameters(fxLP, &lp);
1107 fxLP = BASS_ChannelSetFX(
sound_streamFx[soundEnum], BASS_FX_BFX_BQF, 1);
1108 BASS_FXSetParameters(fxLP, &lp);
1113 HSTREAM streamToPlay =
GlassFX(soundEnum);
1114 static bool caughtOne =
false;
1120 sprintf_s(msg,
sizeof msg,
"PlayEx streamToPlay NULL se%i fo%i ph%i sfo%i sph%i cam%i sd%i sfx%i", soundEnum, fromOutside, partOfHull,
sound_fromOutside[soundEnum],
sound_partOfHull[soundEnum],
game->
viewscreen->
camera &&
game->
viewscreen->
camera->
outside,
sound_debug[soundEnum],
sound_fxEnabled[soundEnum]);
1131 if (!BASS_ChannelFlags(
sound_stream[soundEnum], BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP))
1133 sprintf_s(msg,
sizeof msg,
"PlayEx BASS_ChannelFlags(%i) failed: %i", soundEnum, BASS_ErrorGetCode());
1139 sprintf_s(msg,
sizeof msg,
"PlayEx BASS_ChannelFlags(%i) failed: %i", soundEnum, BASS_ErrorGetCode());
1151#pragma region Frequency
1154 if (!BASS_ChannelSetAttribute(streamToPlay, BASS_ATTRIB_FREQ, frequency))
1156 sprintf_s(msg,
sizeof msg,
"PlayEx BASS_ChannelSetAttribute(%i) freq %.1f failed: %i", soundEnum, frequency, BASS_ErrorGetCode());
1158 sprintf_s(msg,
sizeof msg,
"--- minrate %.1f original %.1f maxrate %.1f mod %.1f",
minrate,
sound_rate[soundEnum],
maxrate, frequencyMod);
1165 if (!interfaceSound)
1168 if (!BASS_ChannelPlay(streamToPlay, !loop && restart))
1170 const int error = BASS_ErrorGetCode();
1171 if (error == BASS_ERROR_UNKNOWN || error == BASS_ERROR_BUFLOST)
1173 sprintf_s(msg,
sizeof msg,
"PlayEx BASS_ChannelPlay (%i) error %i!", soundEnum, error);
1180 PlayEx(soundEnum, loop, volume, frequencyMod, pan, restart);
1182 else if (error == BASS_ERROR_START)
1186 BASS_ChannelPlay(streamToPlay, !loop && restart);
1202 s->
Trace(
"Sound::MetaData received!");
1206 const char* icy = BASS_ChannelGetTags(s->
radio, BASS_TAG_META);
1213 sscanf_s(s->
metadata,
"StreamTitle='%[^']", msg,
static_cast<unsigned>(
sizeof(msg)));
1214 if (strlen(msg) > 76)
1216 msg[74] = msg[75] = msg[76] =
'.';
1241 sprintf_s(msg,
sizeof msg,
"MetaData BASS_ChannelGetTags error %i!", BASS_ErrorGetCode());
1251 sprintf_s(msg,
sizeof msg,
"Sound::AdvanceStage loopintro %i musicstage: %i", s->
loopintro, s->
musicstage);
1265 sprintf_s(msg,
sizeof msg,
"Sound::AdvanceStage BASS_ChannelSetPos %i: %i", s->
musicstage, BASS_ErrorGetCode());
1277 sprintf_s(msg,
sizeof msg,
"Sound::AdvanceStage BASS_ChannelSetPos %i: %i", s->
musicstage, BASS_ErrorGetCode());
1285 sprintf_s(msg,
sizeof msg,
"Sound::AdvanceStage BASS_ChannelSetPos %i: %i", s->
musicstage, BASS_ErrorGetCode());
1295 s->
game->
logger->
Log(
"Calling BASS_ChannelRemoveSync STATUS_GAME!");
1304 sprintf_s(msg,
sizeof msg,
"Sound::AdvanceStage BASS_StreamFree %i: %i", s->
musicstage, BASS_ErrorGetCode());
1319 sprintf_s(msg,
sizeof(msg),
"BASS_ChannelRemoveSync %i: %i", s->
musicstage, BASS_ErrorGetCode());
1329 sprintf_s(msg,
sizeof msg,
"Sound::AdvanceStage BASS_StreamFree %i: %i", s->
musicstage, BASS_ErrorGetCode());
1341 sprintf_s(msg,
sizeof msg,
"NOW Sound::AdvanceStage loopintro %i musicstage: %i", s->
loopintro, s->
musicstage);
1354 BASS_SYNC_POS | BASS_SYNC_MIXTIME,
1370 BASS_SYNC_POS | BASS_SYNC_MIXTIME,
1375 BASS_SYNC_POS | BASS_SYNC_MIXTIME,
1396 s->
game->
logger->
Log(
"Calling BASS_ChannelRemoveSync Case 5!");
1403 s->
game->
logger->
Log(
"Calling BASS_StreamFree g_pSoundIntro!");
1406 sprintf_s(msg,
sizeof msg,
"Sound::AdvanceStage BASS_StreamFree %i: %i", s->
musicstage, BASS_ErrorGetCode());
1418 sprintf_s(msg,
sizeof(msg),
"BASS_ChannelSetSync %i: %i", s->
musicstage, BASS_ErrorGetCode());
1428 return static_cast<size_t>(std::filesystem::file_size(str));
1430 catch (std::filesystem::filesystem_error&) {
1437 if (newDevice ==
nullptr)
1452 BASS_SetDevice(oldSoundDevice);
1460 sprintf_s(msg,
sizeof msg,
"BASS_StreamFree(%i): %i", soundEnum, BASS_ErrorGetCode());
1470 sprintf_s(msg,
sizeof msg,
"BASS_StreamFree(%i): %i", soundEnum, BASS_ErrorGetCode());
1499 sprintf_s(msg,
sizeof msg,
"GetFileSizeBytes3(%i), \"%s\"): %zu", soundEnum,
sound_path[soundEnum].c_str(), fileSize);
1503 int streamError = BASS_OK;
1508 sprintf_s(msg,
sizeof msg,
"CreateFileSound(%i), \"%s\"): %i", soundEnum,
sound_path[soundEnum].c_str(), streamError);
1515 WCHAR wstr[MAX_PATH];
1516 swprintf_s(wstr, MAX_PATH, L
"%S",
sound_path[soundEnum].c_str());
1519 BASS_CHANNELINFO info;
1520 if (BASS_ChannelGetInfo(
sound_stream[soundEnum], &info))
1522 sound_rate[soundEnum] =
static_cast<float>(info.freq);
1527 sprintf_s(msg,
sizeof msg,
"BASS_ChannelGetInfo(%i), \"%s\"): %i", soundEnum,
sound_path[soundEnum].c_str(), BASS_ErrorGetCode());
1531 const QWORD length = BASS_ChannelGetLength(
sound_stream[soundEnum], BASS_POS_BYTE);
1538 if (device ==
nullptr)
1556 BASS_SetDevice(oldsounddevice);
1564 sprintf_s(msg,
sizeof msg,
"BASS_StreamFree(%i): %i", soundEnum, BASS_ErrorGetCode());
1571 bool hadFxChannel =
false;
1581 sprintf_s(msg,
sizeof msg,
"BASS_StreamFree(%i): %i", soundEnum, BASS_ErrorGetCode());
1586 hadFxChannel =
true;
1589 if (path ==
nullptr)
1607 sprintf_s(msg,
sizeof msg,
"GetFileSizeBytes4(%i), \"%s\"): %zu", soundEnum, path, fileSize);
1611 int streamError = BASS_OK;
1612 sound_stream[soundEnum] = CreateFileSound(soundEnum, path, streamError);
1615 int fxError = BASS_OK;
1616 sound_streamFx[soundEnum] = CreateFileSound(soundEnum, path, fxError);
1620 sprintf_s(msg,
sizeof msg,
"CreateFileSound FX(%i), \"%s\"): %i", soundEnum, path, fxError);
1626 sprintf_s(msg,
sizeof msg,
"Sound Sample HAD FX Channel on replace (%i), \"%s\") LOW rate: %.0f", soundEnum,
sound_path[soundEnum].c_str(),
sound_rate[soundEnum]);
1633 sprintf_s(msg,
sizeof msg,
"CreateFileSound(%i), \"%s\"): %i", soundEnum, path, streamError);
1640 WCHAR wstr[MAX_PATH];
1641 swprintf_s(wstr, MAX_PATH, L
"%S", path);
1644 BASS_CHANNELINFO info;
1645 if (BASS_ChannelGetInfo(
sound_stream[soundEnum], &info))
1647 sound_rate[soundEnum] =
static_cast<float>(info.freq);
1652 sprintf_s(msg,
sizeof msg,
"BASS_ChannelGetInfo(%i), \"%s\"): %i", soundEnum, path, BASS_ErrorGetCode());
1656 const QWORD length = BASS_ChannelGetLength(
sound_stream[soundEnum], BASS_POS_BYTE);
1664 return BASS_StreamFree(stream);
1686 if (amount > 0.0f && !failed)
1692 if (IsInterfaceSound(
static_cast<SOUNDS>(i)))
1696 if (stream && BASS_ChannelIsActive(stream) != BASS_ACTIVE_STOPPED &&
1703 if (stream && BASS_ChannelIsActive(stream) != BASS_ACTIVE_STOPPED &&
1722 bool popped =
false;
1730 player.age, player.sex, elapsedTime, &pop);
1736 elapsedTime, popped);
1751 sprintf_s(msg,
sizeof msg,
1752 "EARPOP altitudeM=%.3f cabinMb=%.3f ambientMb=%.3f middleMb=%.3f "
1753 "deltaMb=%+.3f thresholdMb=%.3f sincePreviousS=%.3f frameS=%.4f groundVehicle=%i internalCamera=%i",
1759 for (
int i = 0; i < playback.count; ++i)
1761 const auto& voice = playback.voices[i];
1766 sprintf_s(msg,
sizeof msg,
"EARPOP_PLAY ear=%s variant=%i pan=%+.1f pitch=%.3f delayS=%.4f elapsedS=%.4f",
1767 voice.pan < 0 ?
"left" :
"right", voice.variant + 1, voice.pan, voice.pitch,
1768 voice.delaySeconds, voice.elapsedSeconds);
1775 if (BASS_ChannelIsActive(
comms) == BASS_ACTIVE_PLAYING)
1788 float volumes[4] = {}, pans[4] = {};
1789 bool attached[4] = {};
1791 for (
int slot = 0; slot <
MAX_SCAN; ++slot)
1794 if (!vehicle.active || !(vehicle.hornPressed || vehicle.crashHornFault)
1795 || vehicle.isSimulator || !vehicle.groundvehicle || (slot != 0 && !vehicle.visible))
continue;
1798 : strncmp(vehicle.hullname,
"ECTO ", 5) == 0 ? 3 : 0;
1799 const float distance = slot == 0 ? 0.f : vehicle.distance;
1800 if (distance < 0.f || distance >= 1.f)
continue;
1801 const float volume = 1.f - sqrtf(distance);
1802 if (volume <= volumes[kind])
continue;
1803 volumes[kind] = volume;
1804 attached[kind] = slot == 0;
1812 for (
int kind = 0; kind < 4; ++kind)
1815 const auto loop =
static_cast<SOUNDS>(start + 1);
1816 const auto end =
static_cast<SOUNDS>(start + 2);
1826 const bool requested = volumes[kind] > 0.f;
1833 const auto previous = playback.
phase;
1836 const bool finished = BASS_ChannelIsActive(
sound_stream[previousSound]) != BASS_ACTIVE_PLAYING
1837 && BASS_ChannelIsActive(
sound_streamFx[previousSound]) != BASS_ACTIVE_PLAYING;
1838 const auto phase = playback.Update(requested, finished);
1839 const bool changed = phase != previous;
1852 const float phase = wipers.
phase;
1860 if (active && !animated && elapsedTime > 0.f && std::isfinite(elapsedTime))
1864 const float step = elapsedTime / 1.5f;
1877 const bool moving = active && animated && elapsedTime > 0.f && wipers.moving;
1885 const bool wasPlaying = BASS_ChannelIsActive(
sound_stream[sound]) == BASS_ACTIVE_PLAYING
1886 || BASS_ChannelIsActive(
sound_streamFx[sound]) == BASS_ACTIVE_PLAYING;
1890 if (rate <= 0.f)
return;
1894 wipers.rate, !wasPlaying))
1932#pragma region Ambient Cockpit Sound
1934 const float BaseGain = 0.45f;
1935 const float BasePitch = 0.875f;
1938 const float SlowDriftGain = 0.12f;
1941 const float SlowDriftF1 = 0.08f;
1942 const float SlowDriftF2 = 0.14f;
1945 const float PitchPerGain = 0.15f;
1947 const float PressGainScale = 0.06f;
1948 const float PressPitchScale = 0.03f;
1950 const float ThrustGainScale = 0.05f;
1951 const float ThrustPitchScale = 0.02f;
1955 float raw = sinf(waveform * SlowDriftF1 + 0.9f) * 0.65f + sinf(waveform * SlowDriftF2) * 0.35f;
1958 float eased = raw * fabsf(raw);
1960 float slow = eased * SlowDriftGain;
1964 float pressNorm = 0.0f;
1969 if (n < -1.0f) n = -1.0f;
1970 if (n > 1.0f) n = 1.0f;
1976 if (thrust01 < 0.0f) thrust01 = 0.0f;
1977 if (thrust01 > 1.0f) thrust01 = 1.0f;
1980 float pressGain = pressNorm * PressGainScale;
1981 float pressPitch = pressNorm * PressPitchScale;
1983 float thrustGain = thrust01 * ThrustGainScale;
1984 float thrustPitch = thrust01 * ThrustPitchScale;
1987 float gain = BaseGain * (1.0f + slow + pressGain + thrustGain);
1988 float pitch = BasePitch * (1.0f + slow * PitchPerGain + pressPitch + thrustPitch);
1997 bool playing =
false;
2001 playing |= BASS_ChannelIsActive(
comms) == BASS_ACTIVE_PLAYING;
2037 float newAmbientVolume;
2050 constexpr float easWindThresholdKms = 0.020f;
2056 gustWindSpeedKms >= easWindThresholdKms))
2058 else if ((
gridarray[31][31].pri_transition != 0 ||
gridarray[31][31].sec_transition != 0) &&
2099 result += (ul + ll + ur + lr) * 0.25f;
2101 if (
gridarray[31][31].zone == 0 && f_temp < 1.0f)
2103 newAmbientVolume = powf(f_temp, 2.0f);
2104 newAmbientVolume = 1.0f - newAmbientVolume;
2106 else if (
gridarray[31][31].zone != 0 && f_temp < 0.5f)
2109 newAmbientVolume = powf(f_temp, 2.0f);
2110 newAmbientVolume = 1.0f - newAmbientVolume;
2113 newAmbientVolume =
Clamp(1.0f -
f_AGL, 0, 1);
2115 newAmbientVolume = 0.0f;
2144 if (newambtype2 == 6)
2148 if (newambtype2 == 1)
2172 g_pSoundIntro = BASS_StreamCreateFile(
false,
"Sounds\\ambience.ogg", 0, 0, BASS_STREAM_PRESCAN);
2176 sprintf_s(msg,
sizeof msg,
"LoadSounds BASS_StreamCreateFile error: %i", BASS_ErrorGetCode());
2182 g_pSoundIntro = BASS_StreamCreateFile(
false,
"Sounds\\goth.ogg", 0, 0, BASS_STREAM_PRESCAN);
2186 sprintf_s(msg,
sizeof msg,
"LoadSounds BASS_StreamCreateFile error: %i", BASS_ErrorGetCode());
2194 sprintf_s(msg,
sizeof msg,
"LoadSounds BASS_ChannelSetAttribute error: %i", BASS_ErrorGetCode());
2201 sprintf_s(msg,
sizeof msg,
"LoadSounds BASS_ChannelPlay error: %i", BASS_ErrorGetCode());
2210 sprintf_s(msg,
sizeof msg,
"LoadSounds BASS_ChannelSetSync error: %i", BASS_ErrorGetCode());
2219 sprintf_s(msg,
sizeof msg,
"LoadSounds BASS_ChannelSetSync error: %i", BASS_ErrorGetCode());
2245 sprintf_s(msg,
sizeof msg,
"LegacySoundRequestUniverse x%.0f y%.0f z%.0f w%.0f %i", datapacket.
f_x, datapacket.
f_y, datapacket.
f_z, datapacket.
f_w, datapacket.
array);
2248 if (datapacket.
array == 0)
2250 Trace(
"Should not be getting LegacySoundRequestUniverse calls with our slot!",
Logger::Error);
2256 Trace(
"LegacySoundRequestUniverse called with out-of-bounds array value!",
Logger::Error);
2262 Trace(
"LegacySoundRequestUniverse got a call for a vehicle that was not visible or was not active!",
Logger::Warn);
2266 if (datapacket.
f_x == 0.0f)
2268 if (datapacket.
f_y == 4.0f)
2287 float newvolume = 1.0f - tfal;
2290 if (_isnan(closing) || isinf(closing))
2296 if (_isnan(closing) || isinf(closing))
2305 if (result.z != 0.0f)
2309 float f_temp = sqrtf(mark1 * mark1 + bear1 * bear1);
2310 if (f_temp > 180.0f)
2312 f_temp = 180.0f / f_temp;
2315 if (result.z > 0.0f)
2327 float pan = bear1 / 90.0f;
2328 if (std::isnan(pan))
2334 if (datapacket.
f_y == 0.0f)
2342 else if (datapacket.
f_y == 1.0f)
2344 else if (datapacket.
f_y == 2.0f)
2346 else if (datapacket.
f_y == 3.0f)
2348 else if (datapacket.
f_y == 5.0f)
2353 else if (datapacket.
f_y == 6.0f)
2362 else if (datapacket.
f_x == 1.0f)
2372 dest.x = dest.y = dest.z = 0.0f;
2377 if (distance < 50.0f)
2379 float f_temp = distance / 50.0f;
2380 f_temp = 1.0f - f_temp;
2381 f_temp = powf(f_temp, 3.0f);
2383 Trace(
"Sonic boom detected!");
2392 else if (datapacket.
f_x == 2.0f)
2402 dest.x = dest.y = dest.z = 0.0f;
2407 if (distance < 10.0f)
2409 float f_temp = distance / 10.0f;
2410 f_temp = 1.0f - f_temp;
2413 Trace(
"Sea monster call detected!");
2448 DWORD channelStatus = BASS_ChannelIsActive(
radio);
2449 if (channelStatus != BASS_ACTIVE_PLAYING)
2452 if (!BASS_ChannelPlay(
radio, FALSE))
2454 const int error = BASS_ErrorGetCode();
2455 if (error == BASS_ERROR_HANDLE || error == BASS_ERROR_UNKNOWN)
2456 channelStatus = BASS_ACTIVE_STOPPED;
2458 channelStatus = BASS_ACTIVE_PLAYING;
2461 channelStatus = BASS_ACTIVE_PLAYING;
2472 sprintf_s(msg,
sizeof msg,
"FrameMoveAAC Lost stream or stream ended... reconnecting... station %i",
game->
bus->
station);
2477 Trace(
"FrameMoveAAC Changed radio stations...");
2528 sprintf_s(msg,
sizeof msg,
"FrameMoveAAC BASS_ChannelStop(g_pSoundIntro) failed: %i", BASS_ErrorGetCode());
2537 const int hr = BASS_ErrorGetCode();
2539 sprintf_s(msg,
sizeof msg,
"FrameMoveAAC BASS_StreamCreateURL failed (%i) for station: %i", hr,
game->
bus->
station);
2547 if (!BASS_ChannelPlay(
radio, FALSE))
2550 sprintf_s(msg,
sizeof msg,
"FrameMoveAAC BASS_ChannelPlay error: %i", BASS_ErrorGetCode());
2561 BASS_ChannelSetSync(
radio, BASS_SYNC_MIXTIME | BASS_SYNC_META, NULL,
MetaData,
this);
2585 return (effect.soundEnum >= SOUND_THUNDER_NEAR && effect.soundEnum <= SOUND_THUNDER_FAR5)
2586 || effect.soundEnum == SOUND_SPEAKERPOP;
2623 sprintf_s(msg,
sizeof msg,
"FrameMoveDelayedEffects globalAttenuate clamped volume: %.1f (%.1f, %.1f)",
globalAttenuate,
gaTimer, invVolumeAdj);
2630 float newExcludedSoundVolume = oldExcludedSoundVolume;
2639 newExcludedSoundVolume = 0.0f;
2676 float oldVolume = 0,
oldPan = 0, oldFreqMod = 0;
2679 if (
loopingeffects.at(t).soundEnum != oldSoundEnum && oldSoundEnum != -1)
2730 float newVolume = sqrtf(f_temp / 1.0f);
2731 if (newVolume > 1.0f)
2733 newVolume = 1.0f - newVolume;
2734 if (newVolume < oldVolume)
2736 oldVolume = newVolume;
2745 if (result.z != 0.0f)
2749 f_temp = sqrtf(mark1 * mark1 + bear1 * bear1);
2750 if (f_temp > 180.0f)
2752 f_temp = 180.0f / f_temp;
2755 if (result.z > 0.0f)
2775 else if (oldSoundEnum != -1)
2785 auto resetDopplerEffects = [
this]()
2797 if (IsInvalidFloat(elapsedTime) || elapsedTime < 0.0f)
2800 sprintf_s(msg,
sizeof msg,
"FrameMoveDopplerEffects skipped invalid elapsedTime %.3f", elapsedTime);
2802 resetDopplerEffects();
2808 if (speedOfSoundKms <= 0.0f || IsInvalidFloat(speedOfSoundKms))
2811 sprintf_s(msg,
sizeof msg,
"FrameMoveDopplerEffects skipped invalid speedOfSoundKms %.6f", speedOfSoundKms);
2813 resetDopplerEffects();
2818 const float atmosphericSoundPressureGain =
2820 const float distantJetMaxAudibleDistanceKm =
2821 DistantJetMaxAudibleDistanceKmAtOneAtmosphere * atmosphericSoundPressureGain;
2822 const float rocketRippingMaxAudibleDistanceKm =
2823 RocketRippingMaxAudibleDistanceKmAtOneAtmosphere * atmosphericSoundPressureGain;
2841 float closing1 = 1.0f, closing2 = 1.0f;
2842 float newvolume1 = 0.0f, newvolume2 = 0.0f;
2843 float pan = 0.0f, pan2 = 0.0f;
2859 sprintf_s(msg,
sizeof msg,
"FrameMoveDopplerEffects invalid playerships[0].inarray %i", parentArray);
2861 resetDopplerEffects();
2876 for (
short t = 1; t <
MAX_SCAN; t++)
2890 const float delaySeconds = realDistance / speedOfSoundKms;
2913 default: newtons = 0.0f;
break;
2917 const float fullRippingThrust =
RiseMath::Max(newtons - RocketRippingThresholdNewtons, 0.0f);
2918 const float rippingThrustLevel = fullRippingThrust > 0.0f
2919 ?
Clamp((thrust - RocketRippingThresholdNewtons) / fullRippingThrust, 0.0f, 1.0f)
2927 if (soundDistance < distantJetMaxAudibleDistanceKm)
2929 const float distanceGain = GetOutdoorEngineDistanceGain(soundDistance);
2930 const float proposedvolume =
RiseMath::Min(thrust / 513000.0f, 1.0f) * distanceGain;
2932 if (proposedvolume > newvolume1)
2934 newvolume1 = proposedvolume;
2937 RiseMath::Vector3 tempvec = (theirSoundPosition + theirVelocity) - (ourPosition + ourVelocity);
2939 closing1 /= speedOfSoundKms;
2943 if (soundPositionDifference.z != 0.0f)
2945 bear1 =
RiseMath::ToDegree(atanf(soundPositionDifference.x / soundPositionDifference.z));
2946 const float mark1 =
RiseMath::ToDegree(atanf(soundPositionDifference.y / soundPositionDifference.z));
2948 float f_temp = sqrtf(mark1 * mark1 + bear1 * bear1);
2949 if (f_temp > 180.0f)
2951 f_temp = 180.0f / f_temp;
2954 if (soundPositionDifference.z > 0.0f)
2972 pan = bear1 / 90.0f;
2973 if (IsInvalidFloat(pan))
2981 if (soundDistance < rocketRippingMaxAudibleDistanceKm && rippingThrustLevel > 0.0f)
2987 const float fullThrustSourceGain =
2988 (RocketRippingRecordingDistanceKm / OutdoorEngineReferenceDistanceKm) *
2989 (fullRippingThrust / (RocketRippingRecordingThrustNewtons - RocketRippingThresholdNewtons));
2990 const float thrustGain = powf(rippingThrustLevel, RocketRippingThrustExponent);
2991 const float distanceGain = GetOutdoorEngineDistanceGain(soundDistance);
2992 const float proposedvolume =
Clamp(fullThrustSourceGain * thrustGain * distanceGain, 0.0f, 1.0f);
2994 if (proposedvolume > newvolume2)
2996 newvolume2 = proposedvolume;
2999 RiseMath::Vector3 tempvec = (theirSoundPosition + theirVelocity) - (ourPosition + ourVelocity);
3001 closing2 /= speedOfSoundKms;
3005 if (soundPositionDifference.z != 0.0f)
3007 bear1 =
RiseMath::ToDegree(atanf(soundPositionDifference.x / soundPositionDifference.z));
3008 float mark1 =
RiseMath::ToDegree(atanf(soundPositionDifference.y / soundPositionDifference.z));
3009 float f_temp = sqrtf(mark1 * mark1 + bear1 * bear1);
3010 if (f_temp > 180.0f)
3012 f_temp = 180.0f / f_temp;
3015 if (soundPositionDifference.z > 0.0f)
3027 pan2 = bear1 / 90.0f;
3028 if (IsInvalidFloat(pan2))
3043 float f_temp = (newvolume1 -
oldvolume) * elapsedTime;
3045 if (IsInvalidFloat(volume))
3053 if (IsInvalidFloat(frequency_mod))
3056 frequency_mod = 1.0f;
3059 f_temp = (pan -
oldPan) * elapsedTime;
3060 float finalPan =
oldPan + f_temp;
3061 if (IsInvalidFloat(finalPan))
3084 float f_temp = (newvolume2 -
oldvolume2) * elapsedTime;
3086 if (IsInvalidFloat(volume))
3094 if (IsInvalidFloat(frequency_mod))
3097 frequency_mod = 1.0f;
3100 f_temp = (pan2 -
oldPan2) * elapsedTime;
3101 float finalPan =
oldPan2 + f_temp;
3103 if (IsInvalidFloat(finalPan))
3129 static bool invalidRelativeWindReported =
false;
3130 if (IsInvalidFloat(relativeWindTrueKms.x) || IsInvalidFloat(relativeWindTrueKms.y) || IsInvalidFloat(relativeWindTrueKms.z))
3132 if (!invalidRelativeWindReported)
3134 invalidRelativeWindReported =
true;
3136 sprintf_s(msg,
sizeof msg,
"PrecipWindSoundBarrier rejected relative wind %.3f %.3f %.3f",
3137 relativeWindTrueKms.x, relativeWindTrueKms.y, relativeWindTrueKms.z);
3143 invalidRelativeWindReported =
false;
3148 static bool invalidDensityReported =
false;
3149 if (IsInvalidFloat(densityScalar) || densityScalar < 0.0f)
3151 if (!invalidDensityReported)
3153 invalidDensityReported =
true;
3155 sprintf_s(msg,
sizeof msg,
"PrecipWindSoundBarrier rejected density scalar %.3f", densityScalar);
3158 densityScalar = 0.0f;
3161 invalidDensityReported =
false;
3173 float percentVelocity =
RiseMath::Min(velocity / 0.135f, 1.0f);
3176 float volume = powf(percentVelocity, 3.0f);
3179 float freq = 0.5f + percentVelocity * 0.8f;
3181 static bool invalidParentSlotReported =
false;
3182 static bool invalidBayDoorExtentReported =
false;
3186 if (parentSlot == 0 || parentSlot >=
MAX_SCAN)
3188 if (!invalidParentSlotReported)
3190 invalidParentSlotReported =
true;
3192 sprintf_s(msg,
sizeof msg,
"PrecipWindSoundBarrier rejected parent slot %u", parentSlot);
3199 invalidParentSlotReported =
false;
3201 if (IsInvalidFloat(bayDoorExtent) || bayDoorExtent < 0.0f)
3203 if (!invalidBayDoorExtentReported)
3205 invalidBayDoorExtentReported =
true;
3207 sprintf_s(msg,
sizeof msg,
"PrecipWindSoundBarrier rejected bay door extent %.3f for slot %u", bayDoorExtent, parentSlot);
3210 bayDoorExtent = 0.0f;
3214 invalidBayDoorExtentReported =
false;
3217 volume *= sqrtf(bayDoorExtent);
3222 invalidParentSlotReported =
false;
3223 invalidBayDoorExtentReported =
false;
3229 float pan = atan2f(relativeWindTrueKms.x, -relativeWindTrueKms.z) /
RiseMath::HalfPi;
3260#pragma region SOUND BARRIER and SONIC BOOM
3269 command.
name =
"AuralSoundBarrier";
3286 outpacket.
type = 23;
3287 outpacket.
f_x = 1.0f;
3289 outpacket.
f_z = 0.0f;
3290 outpacket.
f_w = 0.0f;
3303#pragma region Precipitation
3308 float normPrecip = precipitation <= 3.0f ? 0.0f : (precipitation - 3.0f) / 13.0f;
3309 static bool invalidPrecipReported =
false;
3310 if (IsInvalidFloat(normPrecip) || normPrecip < 0.0f || normPrecip > 1.0f)
3312 if (!invalidPrecipReported)
3314 invalidPrecipReported =
true;
3316 sprintf_s(msg,
sizeof msg,
"PrecipWindSoundBarrier clamped normalized precipitation %.3f", normPrecip);
3319 if (IsInvalidFloat(normPrecip))
3325 invalidPrecipReported =
false;
3326 float apparentPrecip = normPrecip + percentVelocity * (1.0f - normPrecip);
3329 const float base = sqrtf(normPrecip);
3330 float motionEffect = percentVelocity * base;
3331 volume = 0.6f * base + 0.4f * motionEffect;
3334 float thresholds[5] = { 0.0f, 0.25f, 0.45f, 0.65f, 0.85f };
3336 int lowIndex = -1, highIndex = -1;
3339 for (
int i = 0; i < 4; ++i) {
3340 if (apparentPrecip >= thresholds[i] && apparentPrecip < thresholds[i + 1]) {
3344 float range = thresholds[i + 1] - thresholds[i];
3345 blend = (apparentPrecip - thresholds[i]) / range;
3350 if (apparentPrecip >= thresholds[4]) {
3356 for (
int i = 0; i < 5; ++i) {
3357 float sampleVolume = 0.0f;
3360 sampleVolume = volume * (1.0f - blend);
3361 else if (i == highIndex)
3362 sampleVolume = volume * blend;
3379 sprintf_s(msg,
sizeof msg,
"AddDelayedSound adding sound %i with delay: %.3f", soundEnum, delay);
3384 PlayEx(soundEnum,
false, volume);
3389 delayedEffect.
delay = delay;
3391 delayedEffect.
volume = volume;
3392 delayedEffect.
freq = freq;
3408 sprintf_s(msg,
sizeof msg,
"AddLoopingVehicleSound sound %i array %i vehicle %i", soundEnum, array,
playerships[array].vehicleId);
3415 Trace(
"-> Already had a looping effect for that vehicle and that sound effect!");
3422 loopingEffect.
array = array;
3436 sprintf_s(msg,
sizeof msg,
"RemoveLoopingVehicleSound sound %i array %i vehicle %i", soundEnum, array,
playerships[array].vehicleId);
3438 sprintf_s(msg,
sizeof msg,
"-> Found looping effect, calling Stop and erase");
3449 sprintf_s(msg,
sizeof msg,
"RemoveLoopingVehicleSound sound %i array %i vehicle %i", soundEnum, array,
playerships[array].vehicleId);
3451 sprintf_s(msg,
sizeof msg,
"-> Could not find looping effect!");
3492 if (elapsedTime > 0.0f)
3506 bool thrustIdle =
true;
3510 if (thrustIdle && elapsedTime > 0.0f)
3535 PlayEx(soundEnum,
false, 0.2f, 1, 0,
true);
3548 return BASS_ChannelIsActive(
sound_stream[soundEnum]) == BASS_ACTIVE_PLAYING;
3552 if (BASS_ChannelIsActive(
sound_stream[i]) == BASS_ACTIVE_PLAYING)
3583 if (dockTexture == 2)
3600 else if (dockTexture == 1)
3654 for (
int i =
SOUND_PROP1; i <= SOUND_PROP6; ++i) Stop(static_cast<SOUNDS>(i));
SCRIPT_CONTROL SCRIPT_STATE const void SCRIPT_CONTROL SCRIPT_STATE const int SCRIPT_TABDEF const BYTE SCRIPT_STRING_ANALYSIS BOOL
SCRIPT_CONTROL SCRIPT_STATE const void DWORD
const GUID MYGUID_DEFAULT
constexpr auto Clamp(T1 val, T2 min, T3 max)
#define MAX_ONLINEPLAYERS
@ SOUND_COCKPITENGINERIGHT
@ SOUND_CONFIGLANDINGGEAR
@ SOUND_TA_CAUTION_OBSTACLE
@ SOUND_GLIDESLOPECAPTURED
@ SOUND_MONROEALLMOORINGSCLEARED
@ SOUND_TCASREDUCEDESCENT
@ SOUND_AIRBRAKEONMAMMOTH
@ SOUND_HORNMAMMOTH_START
@ SOUND_MONROESOUNDBARRIER
@ SOUND_GPWSTOOLOWTERRAIN
@ SOUND_MONROEHULLIONIZATION
@ SOUND_TCASINCREASECLIMB
@ SOUND_LOCALIZERCAPTURED
@ SOUND_AIRBRAKEOFFMAMMOTH
@ SOUND_TA_OBSTACLE_WARNING
@ SOUND_GPWSWINDSHEARCAUTION
@ SOUND_COCKPITENGINELEFT
@ SOUND_COCKPITENGINECENTER
@ SOUND_TCASINCREASEDESCENT
@ SOUND_GPWSWINDSHEARWARNING
@ SOUND_GPWSTERRAINTERRAIN
@ SOUND_TA_CAUTION_TERRAIN
float StaticAirPressureMb
float EngineThrustOutput[MAX_ENGINES]
RainAir::State RainAirStatus
float EngineThrustLever[MAX_ENGINES]
float IndicatedAirspeedKms
std::vector< Command > commandStream
SoundConfig soundConfigComms
SoundConfig soundConfigLegacy
SoundConfig soundConfigComputer
SoundConfig soundConfigRadio
bool Apply(HSTREAM stream)
bool SetAmount(float value)
void Remove(HSTREAM stream)
Playback Update(bool audible, unsigned int characterId, float seconds, bool popped)
bool Update(bool active, unsigned int characterId, float pressureMb, int age, int sex, float seconds, PopDiagnostics *diagnostics=nullptr)
std::unique_ptr< Bus > bus
std::unique_ptr< HMI > GUI
std::unique_ptr< Networking > networking
static void TouchFile(const WCHAR *str)
std::unique_ptr< Viewscreen > viewscreen
std::unique_ptr< Logger > logger
void ToggleFullScreen(bool goFullScreen)
SPlayerData player[MAX_ONLINEPLAYERS]
void Log(const char *msg, Level level=Info, int errorCode=0)
void AddToCallStack(const char *msg)
void SendToServer(void *pData, DWORD dwSize, bool bGuaranteed, PacketOrdering order=ORDERING_NONE) const
void SendEvent(EventType eventType, float extent=0.0f) const
void AddDelayedSound(SOUNDS soundEnum, float delay, float volume=1.0f, float freq=1.0f, bool fromOutside=false)
void AddLoopingVehicleSound(SOUNDS soundEnum, unsigned char array)
void ChangeVolume(SoundConfig *config, float modVolume)
bool cabinPassengersActive
float cabinLandingConfirmationTime
void Stop(SOUNDS soundEnum) const
void LoadSounds(short instage)
void StopCabinAnnouncements()
char sound_device[SOUND_ENUMERATION]
int GetConfigSelectionIndex(const SoundConfig *deviceConfig) const
bool sound_debug[SOUND_ENUMERATION]
float sound_volume[SOUND_ENUMERATION]
bool sound_fxEnabled[SOUND_ENUMERATION]
void FrameMoveEarPressure(float elapsedTime)
HFX sound_fxLP[SOUND_ENUMERATION]
bool cabinFlightEstablished
void RemoveQueuedCabinAnnouncement(SOUNDS soundEnum)
bool sound_fromOutside[SOUND_ENUMERATION]
void PrecipWindSoundBarrier(RiseMath::Vector3 relativeWindTrueKms)
std::vector< std::string > sound_path
void QueueCabinAnnouncement(SOUNDS soundEnum)
std::vector< Sloopingeffects > loopingeffects
void InitDevice(SoundConfig *deviceConfig)
std::vector< std::string > deviceNames
SoundConfig * sound_config[SOUND_ENUMERATION]
void FrameMoveVehicleSounds()
bool sound_partOfHull[SOUND_ENUMERATION]
void ApplyEarMuffle(HSTREAM stream)
float sound_length[SOUND_ENUMERATION]
EarMuffleChannels earMuffleChannels
static void CALLBACK AdvanceStage(HSYNC handle, DWORD channel, DWORD data, void *user)
void FrameMove(float elapsedTime)
void PlayCabinAnnouncement(SOUNDS sound_enum)
BOOL FreeStream(HSTREAM stream)
HSTREAM sound_stream[SOUND_ENUMERATION]
HSTREAM GlassFX(SOUNDS soundEnum)
HFX sound_fxShelf[SOUND_ENUMERATION]
void FrameMoveDelayedEffects(float elapsedTime)
void RemoveLoopingVehicleSound(unsigned char array, SOUNDS soundEnum=SOUND_NONE)
bool passedSoundBarrierBoom
VehicleHorn::Playback hornPlayback[4]
void Trace(const char *msg, Logger::Level severity=Logger::Level::Info) const
void FrameMoveWipers(float elapsedTime)
float Play(SOUNDS soundEnum, float volume=1.0f)
SOUNDS excludeFromGlobalAttenuate
void FrameMoveImmigration()
float sound_pan[SOUND_ENUMERATION]
static void CALLBACK MetaData(HSYNC handle, DWORD channel, DWORD data, void *user)
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)
bool IsCabinAnnouncementPlaying(SOUNDS soundEnum=SOUND_NONE) const
void LoadSound(int soundEnum, SoundConfig *device=nullptr)
void LegacySoundRequestUniverse(SServerPacket datapacket)
void ChangeCockpit(bool force)
void EnvironmentalEffects()
Sound(GameClass *gameptr)
bool UpdateSoundMix(SOUNDS soundEnum, HSTREAM streamToPlay, float modVolume)
static size_t GetFileSizeBytes(const char *str)
void ReleaseConfigSounds(SoundConfig *config)
void GlobalAttenuate(float prmGaTimeToFadeOut, float prmGaTimeToHold, float prmGaTimeToFadeIn, SOUNDS soundEnum, float prmExTimeToFadeIn, float prmExTimeToHold, float prmExTimeToFadeOut, float volumeAdj=1.0f)
void FrameMoveDopplerEffects(float elapsedTime)
std::vector< int > deviceBassDevices
bool IsVehicleAttachedSound(SOUNDS soundEnum) const
std::vector< SOUNDS > cabinAnnouncementQueue
std::vector< Sdelayedeffects > delayedeffects
void LoadCustomSound(SOUNDS sound_enum, const char *path, SoundConfig *device=nullptr)
void LoadDockSounds(short dockTexture)
float GetLength(SOUNDS soundEnum) const
char stationIdentification
HSTREAM sound_streamFx[SOUND_ENUMERATION]
float sound_rate[SOUND_ENUMERATION]
HFX sound_fxNotch[SOUND_ENUMERATION]
void PlayAudioData(unsigned char *data, size_t length)
std::vector< GUID > deviceGuids
void FrameMoveCabinAnnouncements(float elapsedTime)
void LoadCockpitSound(SOUNDS soundEnum, const char *path, bool force, SoundConfig *device=nullptr)
RiseMath::Vector3 UniverseRelativeVelocityKms
void SetHornPressed(bool pressed)
std::unique_ptr< propulsion > ptrPropulsion
RiseMath::Matrix matrixView
std::unique_ptr< weather > ptrWeather
RiseMath::Vector3 localWindVector
float dynamicDensityScalar
float GetWindspeedKms() const
s_network_objects playerships[MAX_SCAN]
RiseMath::Vector3 insidearray[63][63][3]
LOCALGRID2 gridarray[64][64]
#define SeaLevelPressureMb
#define SeaLevelSpeedOfSoundKms
int SlotForEngine(int engineCount, int engine)
VehicleSoundSpatial::Mix Calculate(const Sources &cache, int slot, const RiseMath::Vector3 &cameraFromVehicle, float yaw, float pitch, float roll, const RiseMath::Matrix &bodyToCameraFrame, const std::array< float, SlotCount > &weights)
float Strength(float output)
HSTREAM Create(const unsigned char *data, std::size_t length, DWORD flags, int &error)
float ExteriorGain(float relativePressure)
VehicleSoundSpatial::Mix CalculateExterior(const RiseMath::Vector3 &output, float downLimit, float upLimit, float lateralLimit, float bellyDepthKm, float roofHeightKm, const RiseMath::Vector3 &cameraFromVehicle, float yaw, float pitch, float roll, const RiseMath::Matrix &bodyToCameraFrame)
constexpr float CockpitGain
float Vec3Length(const Vector3 *a)
constexpr auto Min(A first, B second)
Matrix * MatrixRotationQuaternion(Matrix *out, const Quaternion *q)
Vector3 * Vec3TransformNormal(Vector3 *out, const Vector3 *a, const Matrix *m)
Matrix * MatrixInverse(Matrix *out, float *determinant, const Matrix *a)
Matrix * MatrixIdentity(Matrix *out)
constexpr auto Max(A first, B second)
constexpr float MammothReferenceDistanceKm
Mix Calculate(const RiseMath::Vector3 &cameraFromVehicle, float yaw, float pitch, float roll, float referenceDistanceKm=.005f)
float PlaybackRate(float duration, float cyclesPerSecond)
bool Synchronize(HSTREAM stream, float phase, float duration, float cyclesPerSecond, bool force)
double secondsSincePreviousPop
RiseMath::Vector3 position
EngineAudio::Sources engineSounds
RiseMath::Vector3 barycentric
RiseMath::Vector3 position
RiseMath::Vector3 dockoffset
RiseMath::Vector3 velocity
WindshieldWipers::Motion wipers