| 375 | } |
| 376 | |
| 377 | float SOUND::GetMixerOutput(int nChannel, float fGlobalTime, float fTimeStep) |
| 378 | { |
| 379 | // Accumulate sample for this channel |
| 380 | float fMixerSample = 0.0f; |
| 381 | |
| 382 | for (auto &s : listActiveSamples) |
| 383 | { |
| 384 | if (m_bAudioThreadActive) |
| 385 | { |
| 386 | if (s.bFlagForStop) |
| 387 | { |
| 388 | s.bLoop = false; |
| 389 | s.bFinished = true; |
| 390 | } |
| 391 | else |
| 392 | { |
| 393 | // Calculate sample position |
| 394 | s.nSamplePosition += roundf((float)vecAudioSamples[s.nAudioSampleID - 1].wavHeader.nSamplesPerSec * fTimeStep); |
| 395 | |
| 396 | // If sample position is valid add to the mix |
| 397 | if (s.nSamplePosition < vecAudioSamples[s.nAudioSampleID - 1].nSamples) |
| 398 | fMixerSample += vecAudioSamples[s.nAudioSampleID - 1].fSample[(s.nSamplePosition * vecAudioSamples[s.nAudioSampleID - 1].nChannels) + nChannel]; |
| 399 | else |
| 400 | { |
| 401 | if (s.bLoop) |
| 402 | { |
| 403 | s.nSamplePosition = 0; |
| 404 | } |
| 405 | else |
| 406 | s.bFinished = true; // Else sound has completed |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | else |
| 411 | return 0.0f; |
| 412 | } |
| 413 | |
| 414 | // If sounds have completed then remove them |
| 415 | listActiveSamples.remove_if([](const sCurrentlyPlayingSample &s) {return s.bFinished; }); |
| 416 | |
| 417 | // The users application might be generating sound, so grab that if it exists |
| 418 | if (funcUserSynth != nullptr) |
| 419 | fMixerSample += funcUserSynth(nChannel, fGlobalTime, fTimeStep); |
| 420 | |
| 421 | // Return the sample via an optional user override to filter the sound |
| 422 | if (funcUserFilter != nullptr) |
| 423 | return funcUserFilter(nChannel, fGlobalTime, fMixerSample); |
| 424 | else |
| 425 | return fMixerSample; |
| 426 | } |
| 427 | |
| 428 | std::thread SOUND::m_AudioThread; |
| 429 | std::atomic<bool> SOUND::m_bAudioThreadActive{ false }; |
nothing calls this directly
no outgoing calls
no test coverage detected