MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / Sound_Init

Function Sound_Init

TombEngine/Sound/sound.cpp:998–1072  ·  view source on GitHub ↗

Initialize BASS engine and also prepare all sound data. Called once on engine start-up.

Source from the content-addressed store, hash-verified

996// Initialize BASS engine and also prepare all sound data.
997// Called once on engine start-up.
998void Sound_Init(const std::string& gameDirectory)
999{
1000 // Initialize and collect soundtrack paths.
1001 FullAudioDirectory = gameDirectory + TRACKS_PATH;
1002 EnumerateLegacyTracks();
1003
1004 if (!g_Configuration.EnableSound)
1005 return;
1006
1007 // HACK: Manually force-load ADPCM codec, because on Win11 systems it may suddenly unload otherwise.
1008 ADPCMLibrary = LoadLibrary("msadp32.acm");
1009
1010 int soundDevice = g_Configuration.SoundDevice;
1011
1012 BASS_DEVICEINFO info;
1013 if (!BASS_GetDeviceInfo(soundDevice, &info))
1014 {
1015 TENLog("Selected sound device is not available, using default", LogLevel::Warning);
1016 soundDevice = NO_VALUE;
1017 }
1018
1019 BASS_Init(soundDevice, SOUND_SAMPLE_RATE, BASS_DEVICE_3D, WindowsHandle, NULL);
1020 if (Sound_CheckBASSError("Initializing BASS sound device", true))
1021 return;
1022
1023 // Initialize BASS_FX plugin.
1024 BASS_FX_GetVersion();
1025 if (Sound_CheckBASSError("Initializing FX plugin", true))
1026 return;
1027
1028 // Set 3D world parameters.
1029 // Rolloff is lessened since we have own attenuation implementation.
1030 BASS_Set3DFactors(SOUND_BASS_UNITS, 1.5f, 1.0f);
1031 BASS_SetConfig(BASS_CONFIG_3DALGORITHM, BASS_3DALG_FULL);
1032
1033 // Set minimum latency and 2 threads for updating.
1034 // Most of modern PCs already have multi-core CPUs, so why not parallelize updating?
1035 BASS_SetConfig(BASS_CONFIG_UPDATETHREADS, 2);
1036 BASS_SetConfig(BASS_CONFIG_UPDATEPERIOD, 10);
1037
1038 // Create 3D mixdown channel and make it play forever.
1039 // For realtime mixer channels, we need minimum buffer latency. It shouldn't affect reliability.
1040 BASS_SetConfig(BASS_CONFIG_BUFFER, 40);
1041 BASS_3D_Mixdown = BASS_StreamCreate(SOUND_SAMPLE_RATE, SOUND_CHANNEL_COUNT, BASS_SAMPLE_FLOAT, STREAMPROC_DEVICE_3D, NULL);
1042 BASS_ChannelPlay(BASS_3D_Mixdown, false);
1043
1044 // Create video channel for video playback.
1045 BASS_Video = BASS_StreamCreate(SOUND_SAMPLE_RATE, SOUND_CHANNEL_COUNT, BASS_SAMPLE_FLOAT, STREAMPROC_PUSH, NULL);
1046
1047 // Reset buffer back to normal value.
1048 BASS_SetConfig(BASS_CONFIG_BUFFER, 300);
1049
1050 if (Sound_CheckBASSError("Starting 3D mixdown", true))
1051 return;
1052
1053 // Initialize channels and tracks array
1054 ZeroMemory(SoundSlot, (sizeof(SoundEffectSlot) * SOUND_MAX_CHANNELS));
1055

Callers 1

WinMainFunction · 0.85

Calls 3

EnumerateLegacyTracksFunction · 0.85
TENLogFunction · 0.85
Sound_CheckBASSErrorFunction · 0.85

Tested by

no test coverage detected