mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:37:46 +00:00
SoundPlayer: Reduce sample buffer size and add a sample load event
This commit is contained in:
parent
7aa5297835
commit
f9e4bff487
3 changed files with 10 additions and 3 deletions
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include <LibAudio/Loader.h>
|
||||
#include <LibCore/Timer.h>
|
||||
|
||||
#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<Audio::ClientConnection> connection() const { return m_connection; }
|
||||
|
||||
Function<void()> on_update;
|
||||
Function<void(Audio::Buffer&)> on_load_sample_buffer;
|
||||
|
||||
private:
|
||||
void next_buffer();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue