summaryrefslogtreecommitdiff
path: root/Userland/Applications/Piano/AudioPlayerLoop.cpp
diff options
context:
space:
mode:
authorCameron Youell <cameronyouell@gmail.com>2023-03-27 00:37:17 +0000
committerAndrew Kaster <andrewdkaster@gmail.com>2023-04-09 20:58:54 -0600
commit7734eba03f8ded9005d036f48e6a5f4cc99025e7 (patch)
tree53f0bea4b262761bb86c571e72ad52638b49ad35 /Userland/Applications/Piano/AudioPlayerLoop.cpp
parentfb8d4b703247a4edee13e8459caa7d1bd541deb1 (diff)
downloadserenity-7734eba03f8ded9005d036f48e6a5f4cc99025e7.zip
Piano+LibAudio: Port to `Core::File`
Diffstat (limited to 'Userland/Applications/Piano/AudioPlayerLoop.cpp')
-rw-r--r--Userland/Applications/Piano/AudioPlayerLoop.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/Userland/Applications/Piano/AudioPlayerLoop.cpp b/Userland/Applications/Piano/AudioPlayerLoop.cpp
index 2a4d820410..82dd16edef 100644
--- a/Userland/Applications/Piano/AudioPlayerLoop.cpp
+++ b/Userland/Applications/Piano/AudioPlayerLoop.cpp
@@ -93,14 +93,14 @@ intptr_t AudioPlayerLoop::pipeline_thread_main()
// The track manager guards against allocations itself.
m_track_manager.fill_buffer(m_buffer);
- auto result = send_audio_to_server();
// Tolerate errors in the audio pipeline; we don't want this thread to crash the program. This might likely happen with OOM.
- if (result.is_error()) [[unlikely]] {
+ if (auto result = send_audio_to_server(); result.is_error()) [[unlikely]] {
dbgln("Error in audio pipeline: {}", result.error());
m_track_manager.reset();
}
- write_wav_if_needed();
+ if (auto result = write_wav_if_needed(); result.is_error()) [[unlikely]]
+ dbgln("Error writing WAV: {}", result.error());
}
m_audio_client->async_pause_playback();
return static_cast<intptr_t>(0);
@@ -131,28 +131,32 @@ ErrorOr<void> AudioPlayerLoop::send_audio_to_server()
return {};
}
-void AudioPlayerLoop::write_wav_if_needed()
+ErrorOr<void> AudioPlayerLoop::write_wav_if_needed()
{
bool _true = true;
if (m_need_to_write_wav.compare_exchange_strong(_true, false)) {
m_audio_client->async_pause_playback();
- m_wav_writer.with_locked([this](auto& wav_writer) {
+ TRY(m_wav_writer.with_locked([this](auto& wav_writer) -> ErrorOr<void> {
m_track_manager.reset();
m_track_manager.set_should_loop(false);
do {
// FIXME: This progress detection is crude, but it works for now.
m_wav_percent_written.store(static_cast<int>(static_cast<float>(m_track_manager.transport()->time()) / roll_length * 100.0f));
m_track_manager.fill_buffer(m_buffer);
- wav_writer.write_samples(m_buffer.span());
+ TRY(wav_writer.write_samples(m_buffer.span()));
} while (m_track_manager.transport()->time());
// FIXME: Make sure that the new TrackManager APIs aren't as bad.
m_wav_percent_written.store(100);
m_track_manager.reset();
m_track_manager.set_should_loop(true);
wav_writer.finalize();
- });
+
+ return {};
+ }));
m_audio_client->async_start_playback();
}
+
+ return {};
}
void AudioPlayerLoop::toggle_paused()