diff options
author | kleines Filmröllchen <malu.bertsch@gmail.com> | 2021-08-19 00:13:26 +0200 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-08-27 23:35:27 +0430 |
commit | d049626f402f50720a1ccc4452676a56e22debbd (patch) | |
tree | 3f362d216b825318a82661e0874261c68cf6f24e /Userland/Applications/SoundPlayer | |
parent | 9880a5c48150fd03e516c6f74ff0bd0cea5768d5 (diff) | |
download | serenity-d049626f402f50720a1ccc4452676a56e22debbd.zip |
Userland+LibAudio: Make audio applications support dynamic sample rate
All audio applications (aplay, Piano, Sound Player) respect the ability
of the system to have theoretically any sample rate. Therefore, they
resample their own audio into the system sample rate.
LibAudio previously had its loaders resample their own audio, even
though they expose their sample rate. This is now changed. The loaders
output audio data in their file's sample rate, which the user has to
query and resample appropriately. Resampling code from Buffer, WavLoader
and FlacLoader is removed.
Note that these applications only check the sample rate at startup,
which is reasonable (the user has to restart applications when changing
the sample rate). Fully dynamic adaptation could both lead to errors and
will require another IPC interface. This seems to be enough for now.
Diffstat (limited to 'Userland/Applications/SoundPlayer')
-rw-r--r-- | Userland/Applications/SoundPlayer/PlaybackManager.cpp | 5 | ||||
-rw-r--r-- | Userland/Applications/SoundPlayer/PlaybackManager.h | 1 |
2 files changed, 6 insertions, 0 deletions
diff --git a/Userland/Applications/SoundPlayer/PlaybackManager.cpp b/Userland/Applications/SoundPlayer/PlaybackManager.cpp index 9655741211..74a041cab2 100644 --- a/Userland/Applications/SoundPlayer/PlaybackManager.cpp +++ b/Userland/Applications/SoundPlayer/PlaybackManager.cpp @@ -15,6 +15,7 @@ PlaybackManager::PlaybackManager(NonnullRefPtr<Audio::ClientConnection> connecti next_buffer(); }); m_timer->stop(); + m_device_sample_rate = connection->get_sample_rate(); } PlaybackManager::~PlaybackManager() @@ -30,6 +31,7 @@ void PlaybackManager::set_loader(NonnullRefPtr<Audio::Loader>&& loader) m_device_samples_per_buffer = PlaybackManager::buffer_size_ms / 1000.0f * m_device_sample_rate; u32 source_samples_per_buffer = PlaybackManager::buffer_size_ms / 1000.0f * m_loader->sample_rate(); m_source_buffer_size_bytes = source_samples_per_buffer * m_loader->num_channels() * m_loader->bits_per_sample() / 8; + m_resampler = Audio::ResampleHelper<double>(m_loader->sample_rate(), m_device_sample_rate); m_timer->start(); } else { m_timer->stop(); @@ -116,6 +118,9 @@ void PlaybackManager::next_buffer() if (audio_server_remaining_samples < m_device_samples_per_buffer) { m_current_buffer = m_loader->get_more_samples(m_source_buffer_size_bytes); + VERIFY(m_resampler.has_value()); + m_resampler->reset(); + m_current_buffer = Audio::resample_buffer(m_resampler.value(), *m_current_buffer); if (m_current_buffer) m_connection->enqueue(*m_current_buffer); } diff --git a/Userland/Applications/SoundPlayer/PlaybackManager.h b/Userland/Applications/SoundPlayer/PlaybackManager.h index 35afc3fa2c..9d051d2cf8 100644 --- a/Userland/Applications/SoundPlayer/PlaybackManager.h +++ b/Userland/Applications/SoundPlayer/PlaybackManager.h @@ -52,6 +52,7 @@ private: RefPtr<Audio::Loader> m_loader { nullptr }; NonnullRefPtr<Audio::ClientConnection> m_connection; RefPtr<Audio::Buffer> m_current_buffer; + Optional<Audio::ResampleHelper<double>> m_resampler; RefPtr<Core::Timer> m_timer; // Controls the GUI update rate. A smaller value makes the visualizations nicer. |