Rebake of AM, NFM demodulators -- more flexible filtering/configuration.

Also make SpectrumCollector dynamically configurable.
Add deemphasis filter to NFM.
This commit is contained in:
Jared Boone
2015-12-29 10:58:53 -08:00
parent df593c2f0f
commit bbfcca8ec0
8 changed files with 249 additions and 64 deletions

View File

@@ -21,39 +21,77 @@
#include "proc_am_audio.hpp"
#include <cstdint>
// DSB AM 6K00A3E emission type ///////////////////////////////////////////
// IFIR image-reject filter: fs=3072000, pass=3000, stop=339000, decim=8, fout=384000
static constexpr std::array<int16_t, 24> taps_6k0_decim_0 { {
39, 104, 224, 412, 674, 1008, 1400, 1821,
2234, 2594, 2863, 3006, 3006, 2863, 2594, 2234,
1821, 1400, 1008, 674, 412, 224, 104, 39,
} };
// IFIR prototype filter: fs=384000, pass=3000, stop=45000, decim=8, fout=48000
static constexpr std::array<int16_t, 32> taps_6k0_decim_1 { {
-26, -63, -123, -195, -263, -295, -253, -99,
199, 651, 1242, 1927, 2633, 3273, 3760, 4023,
4023, 3760, 3273, 2633, 1927, 1242, 651, 199,
-99, -253, -295, -263, -195, -123, -63, -26,
} };
// Channel filter: fs=48000, pass=3000, stop=6700, decim=1, fout=48000
static constexpr std::array<int16_t, 32> taps_6k0_channel { {
95, 178, 247, 208, -21, -474, -1080, -1640,
-1857, -1411, -83, 2134, 4978, 7946, 10413, 11815,
11815, 10413, 7946, 4978, 2134, -83, -1411, -1857,
-1640, -1080, -474, -21, 208, 247, 178, 95,
} };
NarrowbandAMAudio::NarrowbandAMAudio() {
constexpr size_t baseband_fs = 3072000;
constexpr size_t decim_0_input_fs = baseband_fs;
constexpr size_t decim_0_decimation_factor = 8;
constexpr size_t decim_0_output_fs = decim_0_input_fs / decim_0_decimation_factor;
constexpr size_t decim_1_input_fs = decim_0_output_fs;
constexpr size_t decim_1_decimation_factor = 8;
constexpr size_t decim_1_output_fs = decim_1_input_fs / decim_1_decimation_factor;
constexpr size_t channel_filter_input_fs = decim_1_output_fs;
constexpr size_t channel_filter_decimation_factor = 1;
constexpr size_t channel_filter_output_fs = channel_filter_input_fs / channel_filter_decimation_factor;
decim_0.configure(taps_6k0_decim_0, 33554432);
decim_1.configure(taps_6k0_decim_1, 131072);
channel_filter.configure(taps_6k0_channel, 1);
channel_filter_pass_f = 3000;
channel_filter_stop_f = 6700;
channel_spectrum.set_decimation_factor(std::floor((channel_filter_output_fs / 2) / ((channel_filter_pass_f + channel_filter_stop_f) / 2)));
}
void NarrowbandAMAudio::execute(const buffer_c8_t& buffer) {
auto decimator_out = decimator.execute(buffer);
const buffer_c16_t work_baseband_buffer {
(complex16_t*)decimator_out.p,
sizeof(*decimator_out.p) * decimator_out.count
const buffer_c16_t dst_buffer {
dst.data(),
dst.size()
};
/* 96kHz complex<int16_t>[64]
* -> FIR filter, <?kHz (0.???fs) pass, gain 1.0
* -> 48kHz int16_t[32] */
auto channel = channel_filter.execute(decimator_out, work_baseband_buffer);
const auto decim_0_out = decim_0.execute(buffer, dst_buffer);
const auto decim_1_out = decim_1.execute(decim_0_out, dst_buffer);
const auto channel_out = channel_filter.execute(decim_1_out, dst_buffer);
// TODO: Feed channel_stats post-decimation data?
feed_channel_stats(channel);
channel_spectrum.feed(
channel,
decimator_out.sampling_rate * channel_filter_taps.pass_frequency_normalized,
decimator_out.sampling_rate * channel_filter_taps.stop_frequency_normalized
);
feed_channel_stats(channel_out);
channel_spectrum.feed(channel_out, channel_filter_pass_f, channel_filter_stop_f);
const buffer_s16_t work_audio_buffer {
(int16_t*)decimator_out.p,
sizeof(*decimator_out.p) * decimator_out.count
(int16_t*)dst.data(),
sizeof(*dst.data()) * dst.size()
};
/* 48kHz complex<int16_t>[32]
* -> AM demodulation
* -> 48kHz int16_t[32] */
auto audio = demod.execute(channel, work_audio_buffer);
auto audio = demod.execute(channel_out, work_audio_buffer);
audio_hpf.execute_in_place(audio);
fill_audio_buffer(audio);
}