bool AlsaSound::Start() { m_thread_status.store(ALSAThreadStatus::RUNNING); if (!AlsaInit()) { m_thread_status.store(ALSAThreadStatus::STOPPED); return false; } thread = std::thread(&AlsaSound::SoundLoop, this); return true; }
// Called on audio thread. void AlsaSound::SoundLoop() { if (!AlsaInit()) { thread_data = 2; return; } Common::SetCurrentThreadName("Audio thread - alsa"); while (!thread_data) { m_mixer->Mix(reinterpret_cast<short *>(mix_buffer), frames_to_deliver); int rc = m_muted ? 1337 : snd_pcm_writei(handle, mix_buffer, frames_to_deliver); if (rc == -EPIPE) { // Underrun snd_pcm_prepare(handle); } else if (rc < 0) { ERROR_LOG(AUDIO, "writei fail: %s", snd_strerror(rc)); } } AlsaShutdown(); thread_data = 2; }