mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:47:37 +00:00
Piano+LibAudio: Port to Core::File
This commit is contained in:
parent
fb8d4b7032
commit
7734eba03f
5 changed files with 61 additions and 59 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue