From 1573a8c4cde1cd9528b422b2dcc598e37ffe94a7 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 2 May 2024 19:12:26 +1000 Subject: WIP merge cyclically dependent components into one big component --- src/tangara/audio/resample.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/tangara/audio/resample.cpp (limited to 'src/tangara/audio/resample.cpp') diff --git a/src/tangara/audio/resample.cpp b/src/tangara/audio/resample.cpp new file mode 100644 index 00000000..1e20392b --- /dev/null +++ b/src/tangara/audio/resample.cpp @@ -0,0 +1,55 @@ +/* + * Copyright 2023 jacqueline + * + * SPDX-License-Identifier: GPL-3.0-only + */ +#include "resample.hpp" + +#include +#include +#include +#include +#include +#include + +#include "esp_log.h" +#include "speex/speex_resampler.h" + +#include "sample.hpp" + +namespace audio { + +static constexpr int kQuality = SPEEX_RESAMPLER_QUALITY_MIN; + +Resampler::Resampler(uint32_t source_sample_rate, + uint32_t target_sample_rate, + uint8_t num_channels) + : err_(0), + resampler_(speex_resampler_init(num_channels, + source_sample_rate, + target_sample_rate, + kQuality, + &err_)), + num_channels_(num_channels) { + assert(err_ == 0); +} + +Resampler::~Resampler() { + speex_resampler_destroy(resampler_); +} + +auto Resampler::Process(std::span input, + std::span output, + bool end_of_data) -> std::pair { + uint32_t samples_used = input.size() / num_channels_; + uint32_t samples_produced = output.size() / num_channels_; + + int err = speex_resampler_process_interleaved_int( + resampler_, input.data(), &samples_used, output.data(), + &samples_produced); + assert(err == 0); + + return {samples_used * num_channels_, samples_produced * num_channels_}; +} + +} // namespace audio -- cgit v1.2.3 From 7d7f7755d17e1e0a2348d75d797097f166b70471 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 2 May 2024 21:41:56 +1000 Subject: start moving include files into subdirs --- src/tangara/audio/resample.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tangara/audio/resample.cpp') diff --git a/src/tangara/audio/resample.cpp b/src/tangara/audio/resample.cpp index 1e20392b..143ce230 100644 --- a/src/tangara/audio/resample.cpp +++ b/src/tangara/audio/resample.cpp @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: GPL-3.0-only */ -#include "resample.hpp" +#include "audio/resample.hpp" #include #include -- cgit v1.2.3