// Called on audio thread. void AlsaSound::SoundLoop() { Common::SetCurrentThreadName("Audio thread - alsa"); while (m_thread_status.load() != ALSAThreadStatus::STOPPING) { while (m_thread_status.load() == ALSAThreadStatus::RUNNING) { m_mixer->Mix(mix_buffer, frames_to_deliver); int rc = 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)); } } if (m_thread_status.load() == ALSAThreadStatus::PAUSED) { snd_pcm_drop(handle); // Stop sound output // Block until thread status changes. std::unique_lock<std::mutex> lock(cv_m); cv.wait(lock, [this]{ return m_thread_status.load() != ALSAThreadStatus::PAUSED; }); snd_pcm_prepare(handle); // resume sound output } } AlsaShutdown(); m_thread_status.store(ALSAThreadStatus::STOPPED); }
// 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; }