From f9e4bff487ed8f9571bd9a598d2f4b7c84f50897 Mon Sep 17 00:00:00 2001 From: Cesar Torres Date: Sun, 21 Mar 2021 13:43:27 +0100 Subject: [PATCH] SoundPlayer: Reduce sample buffer size and add a sample load event --- Userland/Applications/SoundPlayer/CMakeLists.txt | 4 ++++ Userland/Applications/SoundPlayer/PlaybackManager.cpp | 6 ++++-- Userland/Applications/SoundPlayer/PlaybackManager.h | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Userland/Applications/SoundPlayer/CMakeLists.txt b/Userland/Applications/SoundPlayer/CMakeLists.txt index 99e1da4653..70c3d79965 100644 --- a/Userland/Applications/SoundPlayer/CMakeLists.txt +++ b/Userland/Applications/SoundPlayer/CMakeLists.txt @@ -3,6 +3,10 @@ set(SOURCES PlaybackManager.cpp SampleWidget.cpp SoundPlayerWidget.cpp + SoundPlayerWidgetAdvancedView.cpp + BarsVisualizationWidget.cpp + AudioAlgorithms.cpp + NoVisualizationWidget.cpp ) serenity_app(SoundPlayer ICON app-sound-player) diff --git a/Userland/Applications/SoundPlayer/PlaybackManager.cpp b/Userland/Applications/SoundPlayer/PlaybackManager.cpp index f301df0acb..4e1c9c6fbb 100644 --- a/Userland/Applications/SoundPlayer/PlaybackManager.cpp +++ b/Userland/Applications/SoundPlayer/PlaybackManager.cpp @@ -128,13 +128,16 @@ void PlaybackManager::load_next_buffer() if (m_buffers.size() < 10) { for (int i = 0; i < 20 && m_loader->loaded_samples() < m_loader->total_samples(); i++) { auto buffer = m_loader->get_more_samples(PLAYBACK_MANAGER_BUFFER_SIZE); - if (buffer) + if (buffer) { m_buffers.append(buffer); + } } } if (m_next_ptr < m_buffers.size()) { m_next_buffer = m_buffers.at(m_next_ptr++); + if (on_load_sample_buffer) + on_load_sample_buffer(*m_next_buffer); } else { m_next_buffer = nullptr; } @@ -163,7 +166,6 @@ void PlaybackManager::next_buffer() { if (on_update) on_update(); - if (m_paused) return; diff --git a/Userland/Applications/SoundPlayer/PlaybackManager.h b/Userland/Applications/SoundPlayer/PlaybackManager.h index 35be78fe9d..8c851b093f 100644 --- a/Userland/Applications/SoundPlayer/PlaybackManager.h +++ b/Userland/Applications/SoundPlayer/PlaybackManager.h @@ -32,7 +32,7 @@ #include #include -#define PLAYBACK_MANAGER_BUFFER_SIZE 64 * KiB +#define PLAYBACK_MANAGER_BUFFER_SIZE 48 * KiB #define PLAYBACK_MANAGER_RATE 44100 class PlaybackManager final { @@ -56,6 +56,7 @@ public: NonnullRefPtr connection() const { return m_connection; } Function on_update; + Function on_load_sample_buffer; private: void next_buffer();