MCPcopy Create free account
hub / github.com/AbyssEngine/AbyssEngineOld / fillAudioBuffer

Method fillAudioBuffer

src/Abyss/AbyssEngine.cpp:250–277  ·  view source on GitHub ↗

ReSharper disable once CppDFAUnreachableFunctionCall - fillAudioBuffer is called via SDL2 audio callback

Source from the content-addressed store, hash-verified

248
249// ReSharper disable once CppDFAUnreachableFunctionCall - fillAudioBuffer is called via SDL2 audio callback
250void AbyssEngine::fillAudioBuffer(Uint8 *stream, const int len) const {
251 if (len & 1) {
252 Common::Log::warn("Audio buffer length is not even, dropping samples...");
253 std::fill_n(stream, len, 0);
254 return;
255 }
256
257 for (auto i = 0; i < len; i += 2) {
258 int32_t sample = 0;
259
260 if (_videoStream != nullptr)
261 sample += static_cast<int32_t>(static_cast<float>(_videoStream->getAudioSample()) * _videoAudioLevelActual);
262 else if (_backgroundMusic != nullptr)
263 sample += static_cast<int32_t>(static_cast<float>(_backgroundMusic->getSample()) * _backgroundMusicAudioLevelActual);
264
265 for (const auto soundEffect : _soundEffects) {
266 if (!soundEffect->getIsPlaying())
267 continue;
268 sample += static_cast<int32_t>(static_cast<float>(soundEffect->getSample()) * _soundEffectsAudioLevelActual);
269 }
270
271 sample = static_cast<int32_t>(static_cast<float>(sample) * _masterAudioLevelActual);
272
273 sample = std::clamp(sample, -32768, 32767);
274 stream[i] = sample & 0xFF;
275 stream[i + 1] = (sample >> 8) & 0xFF;
276 }
277}
278
279AbyssEngine &AbyssEngine::getInstance() {
280 static AbyssEngine instance;

Callers 1

initializeAudioMethod · 0.80

Calls 4

warnFunction · 0.85
getAudioSampleMethod · 0.80
getSampleMethod · 0.45
getIsPlayingMethod · 0.45

Tested by

no test coverage detected