Further template BlockDecimator by element type, use for audio buffer.

Appropriating for use as a buffer accumulator that will save up enough audio samples to put into an audio DMA buffer.
This commit is contained in:
Jared Boone 2016-01-29 19:25:08 -08:00
parent aead1d8798
commit a558565886
8 changed files with 23 additions and 20 deletions

View File

@ -57,6 +57,17 @@ void AudioOutput::write(
void AudioOutput::write(
const buffer_f32_t& audio
) {
block_buffer.feed(
audio,
[this](const buffer_f32_t& buffer) {
this->on_block(buffer);
}
);
}
void AudioOutput::on_block(
const buffer_f32_t& audio
) {
const auto audio_present_now = squelch.execute(audio);

View File

@ -27,6 +27,7 @@
#include "dsp_iir.hpp"
#include "dsp_squelch.hpp"
#include "block_decimator.hpp"
#include "audio_stats_collector.hpp"
#include <cstdint>
@ -43,6 +44,8 @@ public:
void write(const buffer_f32_t& audio);
private:
BlockDecimator<float, 32> block_buffer { 1 };
IIRBiquadFilter hpf;
IIRBiquadFilter deemph;
FMSquelch squelch;
@ -51,6 +54,7 @@ private:
uint64_t audio_present_history = 0;
void on_block(const buffer_f32_t& audio);
void fill_audio_buffer(const buffer_f32_t& audio);
void feed_audio_stats(const buffer_f32_t& audio);
};

View File

@ -29,7 +29,7 @@
#include "dsp_types.hpp"
#include "complex.hpp"
template<size_t N>
template<typename T, size_t N>
class BlockDecimator {
public:
constexpr BlockDecimator(
@ -65,7 +65,7 @@ public:
}
template<typename BlockCallback>
void feed(const buffer_c16_t& src, BlockCallback callback) {
void feed(const buffer_t<T>& src, BlockCallback callback) {
/* NOTE: Input block size must be >= factor */
set_input_sampling_rate(src.sampling_rate);
@ -85,7 +85,7 @@ public:
}
private:
std::array<complex16_t, N> buffer;
std::array<T, N> buffer;
uint32_t input_sampling_rate_ { 0 };
size_t factor_ { 1 };
size_t src_i { 0 };

View File

@ -38,12 +38,8 @@ void NarrowbandAMAudio::execute(const buffer_c8_t& buffer) {
feed_channel_stats(channel_out);
channel_spectrum.feed(channel_out, channel_filter_pass_f, channel_filter_stop_f);
channel_block_buffer.feed(
channel_out, [this](const buffer_c16_t buffer) {
auto audio = this->demod.execute(buffer, this->audio_buffer);
this->audio_output.write(audio);
}
);
auto audio = demod.execute(channel_out, audio_buffer);
audio_output.write(audio);
}
void NarrowbandAMAudio::on_message(const Message* const message) {

View File

@ -58,8 +58,6 @@ private:
uint32_t channel_filter_pass_f = 0;
uint32_t channel_filter_stop_f = 0;
BlockDecimator<32> channel_block_buffer { post_channel_decimation_factor };
dsp::demodulate::AM demod;
AudioOutput audio_output;

View File

@ -38,12 +38,8 @@ void NarrowbandFMAudio::execute(const buffer_c8_t& buffer) {
feed_channel_stats(channel_out);
channel_spectrum.feed(channel_out, channel_filter_pass_f, channel_filter_stop_f);
channel_block_buffer.feed(
channel_out, [this](const buffer_c16_t buffer) {
auto audio = this->demod.execute(buffer, this->audio_buffer);
this->audio_output.write(audio);
}
);
auto audio = demod.execute(channel_out, audio_buffer);
audio_output.write(audio);
}
void NarrowbandFMAudio::on_message(const Message* const message) {

View File

@ -58,8 +58,6 @@ private:
uint32_t channel_filter_pass_f = 0;
uint32_t channel_filter_stop_f = 0;
BlockDecimator<32> channel_block_buffer { post_channel_decimation_factor };
dsp::demodulate::FM demod;
AudioOutput audio_output;

View File

@ -50,7 +50,7 @@ public:
);
private:
BlockDecimator<256> channel_spectrum_decimator;
BlockDecimator<complex16_t, 256> channel_spectrum_decimator;
ChannelSpectrumFIFO fifo;
volatile bool channel_spectrum_request_update { false };