MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / init

Function init

TheForceEngine/TFE_Audio/audioSystem.cpp:89–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87#endif
88
89 bool init(bool useNullDevice/*=false*/, s32 outputId/*=-1*/)
90 {
91 TFE_System::logWrite(LOG_MSG, "Startup", "TFE_AudioSystem::init");
92 s_sourceCount = 0u;
93
94 CCMD("setSoundVolume", setSoundVolumeConsole, 1, "Sets the sound volume, range is 0.0 to 1.0");
95 CCMD("getSoundVolume", getSoundVolumeConsole, 0, "Get the current sound volume.");
96
97 #if AUDIO_TIMING == 1
98 TFE_COUNTER(s_soundIterMax, "SoundIterMax-MicroSec");
99 TFE_COUNTER(s_soundIterAve, "SoundIterAve-MicroSec");
100 #endif
101
102 TFE_Settings_Sound* soundSettings = TFE_Settings::getSoundSettings();
103 setVolume(soundSettings->soundFxVolume);
104
105 memset(s_sources, 0, sizeof(SoundSource) * MAX_SOUND_SOURCES);
106 for (s32 i = 0; i < MAX_SOUND_SOURCES; i++)
107 {
108 s_sources[i].slot = i;
109 }
110
111 bool audDev = TFE_AudioDevice::init(AUDIO_FRAME_SIZE, outputId, useNullDevice);
112 if (!audDev)
113 {
114 TFE_System::logWrite(LOG_ERROR, "Audio", "Cannot start audio device.");
115 s_nullDevice = true;
116 return false;
117 }
118
119 bool audStream = TFE_AudioDevice::startOutput(audioCallback, nullptr, AUDIO_CHANNEL_COUNT, AUDIO_FREQ);
120 if (!audStream)
121 {
122 TFE_System::logWrite(LOG_ERROR, "Audio", "Cannot start audio stream.");
123 s_nullDevice = true;
124 return false;
125 }
126
127 s_mutex = SDL_CreateMutex();
128 if (!s_mutex)
129 {
130 TFE_System::logWrite(LOG_ERROR, "Audio", "Cannot init SDL_mutex.");
131 TFE_AudioDevice::destroy();
132 s_nullDevice = true;
133 return false;
134 }
135
136 s_nullDevice = false;
137 return true;
138 }
139
140 void shutdown()
141 {

Callers 1

selectDeviceFunction · 0.70

Calls 5

logWriteFunction · 0.85
getSoundSettingsFunction · 0.85
startOutputFunction · 0.85
setVolumeFunction · 0.70
destroyFunction · 0.70

Tested by

no test coverage detected