mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 15:57:36 +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()
|
||||
|
|
|
@ -34,7 +34,7 @@ private:
|
|||
|
||||
intptr_t pipeline_thread_main();
|
||||
ErrorOr<void> send_audio_to_server();
|
||||
void write_wav_if_needed();
|
||||
ErrorOr<void> write_wav_if_needed();
|
||||
|
||||
TrackManager& m_track_manager;
|
||||
FixedArray<DSP::Sample> m_buffer;
|
||||
|
|
|
@ -65,11 +65,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
return;
|
||||
DeprecatedString error;
|
||||
wav_writer.with_locked([&](auto& wav_writer) {
|
||||
wav_writer.set_file(save_path.value());
|
||||
if (wav_writer.has_error()) {
|
||||
error = DeprecatedString::formatted("Failed to export WAV file: {}", wav_writer.error_string());
|
||||
wav_writer.clear_error();
|
||||
}
|
||||
auto error_or_void = wav_writer.set_file(save_path.value());
|
||||
if (error_or_void.is_error())
|
||||
error = DeprecatedString::formatted("Failed to export WAV file: {}", error_or_void.error());
|
||||
});
|
||||
if (!error.is_empty()) {
|
||||
GUI::MessageBox::show_error(window, error);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue