From e941048b066dc167ee870545d99532a8d1815e89 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Mon, 10 Jun 2024 13:25:48 -0400 Subject: [PATCH] stop using stride term --- main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index c3abd77..6cb6eaa 100644 --- a/main.cpp +++ b/main.cpp @@ -34,7 +34,7 @@ static constexpr auto MIC_BITS = 18u; static constexpr auto SAMPLE_RATE = 48000u; static constexpr unsigned I2S_BUFSIZ = 1024; -static constexpr unsigned I2S_STRIDE = 32; +static constexpr unsigned I2S_USESIZ = 16; // Calculate reference amplitude value at compile time static const auto MIC_REF_AMPL = sos_t((1 << (MIC_BITS - 1)) - 1) * @@ -152,19 +152,19 @@ void i2sCallback(I2SDriver *i2s) const auto source = i2sBuffer.data() + (i2sIsBufferComplete(i2s) ? halfsize : 0); auto samples = reinterpret_cast(source); std::ranges::copy( - std::views::counted(source, halfsize / I2S_STRIDE) + std::views::counted(source, I2S_USESIZ * 2) | std::ranges::views::stride(2) | std::views::transform([](uint32_t s) { return sos_t(qfp_int2float_asm(fixsample(s))); }), samples); - auto samps = std::views::counted(samples, halfsize / (2 * I2S_STRIDE)); + auto samps = std::views::counted(samples, I2S_USESIZ); // Accumulate Leq sum MIC_EQUALIZER.filter(samps); Leq_sum_sqr += WEIGHTING.filter_sum_sqr(samps); - Leq_samples += samps.size(); + Leq_samples += halfsize / 2; // Wakeup main thread for dB calculation every half second - if (Leq_samples >= SAMPLE_RATE / I2S_STRIDE / 2) { + if (Leq_samples >= SAMPLE_RATE / 2) { i2sReady.store(true); SCB->SCR &= ~SCB_SCR_SLEEPONEXIT_Msk; }