diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-08-27 21:17:53 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-08-28 09:45:19 +1000 |
| commit | f253d2ee7568b61ce2fab962f7328a50e2da6adf (patch) | |
| tree | 394969e7827134684493b499503d7a08918a8867 /src/tangara/audio/resample.cpp | |
| parent | ef227f8c518f2b6cfd5e55ca052a12e70515f2ef (diff) | |
| download | tangara-fw-f253d2ee7568b61ce2fab962f7328a50e2da6adf.tar.gz | |
Timeout when writing output samples throughout the audio pipeline
This allows the audio pipeline to remain responsive even when the drain
buffer has completely filled. This in turn means that you now see the
track info in the 'now playing' screen change if the current track
changes whilst you are paused.
Since I was fucking around a lot in the audio processor anyway, I also
added mono->stereo expansion so that playing mono tracks on Bluetooth no
longer destroys your ears.
Diffstat (limited to 'src/tangara/audio/resample.cpp')
| -rw-r--r-- | src/tangara/audio/resample.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/tangara/audio/resample.cpp b/src/tangara/audio/resample.cpp index 143ce230..d6369022 100644 --- a/src/tangara/audio/resample.cpp +++ b/src/tangara/audio/resample.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: GPL-3.0-only */ #include "audio/resample.hpp" +#include <stdint.h> #include <algorithm> #include <cmath> @@ -31,6 +32,7 @@ Resampler::Resampler(uint32_t source_sample_rate, kQuality, &err_)), num_channels_(num_channels) { + speex_resampler_skip_zeros(resampler_); assert(err_ == 0); } @@ -38,18 +40,24 @@ Resampler::~Resampler() { speex_resampler_destroy(resampler_); } +auto Resampler::sourceRate() -> uint32_t { + uint32_t input = 0; + uint32_t output = 0; + speex_resampler_get_rate(resampler_, &input, &output); + return input; +} + auto Resampler::Process(std::span<sample::Sample> input, std::span<sample::Sample> output, bool end_of_data) -> std::pair<size_t, size_t> { - uint32_t samples_used = input.size() / num_channels_; - uint32_t samples_produced = output.size() / num_channels_; + uint32_t frames_used = input.size() / num_channels_; + uint32_t frames_produced = output.size() / num_channels_; int err = speex_resampler_process_interleaved_int( - resampler_, input.data(), &samples_used, output.data(), - &samples_produced); + resampler_, input.data(), &frames_used, output.data(), &frames_produced); assert(err == 0); - return {samples_used * num_channels_, samples_produced * num_channels_}; + return {frames_used * num_channels_, frames_produced * num_channels_}; } } // namespace audio |
