2015-08-27 16:19:34 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "proc_wfm_audio.hpp"
|
|
|
|
|
2016-01-10 23:25:24 -05:00
|
|
|
#include "audio_output.hpp"
|
|
|
|
|
2015-08-27 16:19:34 -04:00
|
|
|
#include <cstdint>
|
|
|
|
|
2015-12-10 15:36:12 -05:00
|
|
|
void WidebandFMAudio::execute(const buffer_c8_t& buffer) {
|
2016-01-03 16:38:55 -05:00
|
|
|
if( !configured ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-02 13:35:23 -05:00
|
|
|
const auto decim_0_out = decim_0.execute(buffer, dst_buffer);
|
2016-01-11 12:35:58 -05:00
|
|
|
const auto channel = decim_1.execute(decim_0_out, dst_buffer);
|
2015-08-27 16:19:34 -04:00
|
|
|
|
|
|
|
// TODO: Feed channel_stats post-decimation data?
|
|
|
|
feed_channel_stats(channel);
|
2016-01-04 20:27:18 -05:00
|
|
|
|
|
|
|
spectrum_samples += channel.count;
|
|
|
|
if( spectrum_samples >= spectrum_interval_samples ) {
|
|
|
|
spectrum_samples -= spectrum_interval_samples;
|
|
|
|
channel_spectrum.feed(channel, channel_filter_pass_f, channel_filter_stop_f);
|
|
|
|
}
|
2015-08-27 16:19:34 -04:00
|
|
|
|
2016-01-02 13:35:23 -05:00
|
|
|
/* 384kHz complex<int16_t>[256]
|
2015-08-27 16:19:34 -04:00
|
|
|
* -> FM demodulation
|
2016-01-02 13:35:23 -05:00
|
|
|
* -> 384kHz int16_t[256] */
|
2015-08-27 16:19:34 -04:00
|
|
|
/* TODO: To improve adjacent channel rejection, implement complex channel filter:
|
|
|
|
* pass < +/- 100kHz, stop > +/- 200kHz
|
|
|
|
*/
|
|
|
|
|
2016-01-11 12:35:58 -05:00
|
|
|
auto audio_oversampled = demod.execute(channel, work_audio_buffer);
|
2015-08-27 16:19:34 -04:00
|
|
|
|
|
|
|
/* 384kHz int16_t[256]
|
|
|
|
* -> 4th order CIC decimation by 2, gain of 1
|
|
|
|
* -> 192kHz int16_t[128] */
|
2016-01-02 13:35:23 -05:00
|
|
|
auto audio_4fs = audio_dec_1.execute(audio_oversampled, work_audio_buffer);
|
2015-08-27 16:19:34 -04:00
|
|
|
|
|
|
|
/* 192kHz int16_t[128]
|
|
|
|
* -> 4th order CIC decimation by 2, gain of 1
|
|
|
|
* -> 96kHz int16_t[64] */
|
2016-01-02 13:35:23 -05:00
|
|
|
auto audio_2fs = audio_dec_2.execute(audio_4fs, work_audio_buffer);
|
2015-08-27 16:19:34 -04:00
|
|
|
|
|
|
|
/* 96kHz int16_t[64]
|
|
|
|
* -> FIR filter, <15kHz (0.156fs) pass, >19kHz (0.198fs) stop, gain of 1
|
|
|
|
* -> 48kHz int16_t[32] */
|
|
|
|
auto audio = audio_filter.execute(audio_2fs, work_audio_buffer);
|
|
|
|
|
|
|
|
/* -> 48kHz int16_t[32] */
|
2016-01-10 23:25:24 -05:00
|
|
|
audio_output.write(audio);
|
2015-08-27 16:19:34 -04:00
|
|
|
}
|
2016-01-03 16:38:55 -05:00
|
|
|
|
|
|
|
void WidebandFMAudio::on_message(const Message* const message) {
|
|
|
|
switch(message->id) {
|
2016-01-04 20:27:18 -05:00
|
|
|
case Message::ID::UpdateSpectrum:
|
2016-01-12 13:32:00 -05:00
|
|
|
case Message::ID::SpectrumStreamingConfig:
|
|
|
|
channel_spectrum.on_message(message);
|
2016-01-04 20:27:18 -05:00
|
|
|
break;
|
|
|
|
|
2016-01-03 16:38:55 -05:00
|
|
|
case Message::ID::WFMConfigure:
|
|
|
|
configure(*reinterpret_cast<const WFMConfigureMessage*>(message));
|
|
|
|
break;
|
|
|
|
|
2016-05-09 15:05:11 -04:00
|
|
|
case Message::ID::CaptureConfig:
|
|
|
|
capture_config(*reinterpret_cast<const CaptureConfigMessage*>(message));
|
|
|
|
break;
|
|
|
|
|
2016-01-03 16:38:55 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WidebandFMAudio::configure(const WFMConfigureMessage& message) {
|
|
|
|
constexpr size_t decim_0_input_fs = baseband_fs;
|
2016-01-29 19:11:00 -05:00
|
|
|
constexpr size_t decim_0_output_fs = decim_0_input_fs / decim_0.decimation_factor;
|
2016-01-03 16:38:55 -05:00
|
|
|
|
|
|
|
constexpr size_t decim_1_input_fs = decim_0_output_fs;
|
2016-01-29 19:11:00 -05:00
|
|
|
constexpr size_t decim_1_output_fs = decim_1_input_fs / decim_1.decimation_factor;
|
2016-01-03 16:38:55 -05:00
|
|
|
|
|
|
|
constexpr size_t demod_input_fs = decim_1_output_fs;
|
|
|
|
|
2016-01-04 20:27:18 -05:00
|
|
|
spectrum_interval_samples = decim_1_output_fs / spectrum_rate_hz;
|
|
|
|
spectrum_samples = 0;
|
|
|
|
|
2016-01-03 16:38:55 -05:00
|
|
|
decim_0.configure(message.decim_0_filter.taps, 33554432);
|
|
|
|
decim_1.configure(message.decim_1_filter.taps, 131072);
|
2016-01-04 20:27:18 -05:00
|
|
|
channel_filter_pass_f = message.decim_1_filter.pass_frequency_normalized * decim_1_input_fs;
|
|
|
|
channel_filter_stop_f = message.decim_1_filter.stop_frequency_normalized * decim_1_input_fs;
|
2016-01-03 16:38:55 -05:00
|
|
|
demod.configure(demod_input_fs, message.deviation);
|
|
|
|
audio_filter.configure(message.audio_filter.taps);
|
2016-01-29 18:57:20 -05:00
|
|
|
audio_output.configure(message.audio_hpf_config, message.audio_deemph_config);
|
2016-01-03 16:38:55 -05:00
|
|
|
|
2016-01-04 20:27:18 -05:00
|
|
|
channel_spectrum.set_decimation_factor(1);
|
|
|
|
|
2016-01-03 16:38:55 -05:00
|
|
|
configured = true;
|
|
|
|
}
|
2016-05-09 15:05:11 -04:00
|
|
|
|
|
|
|
void WidebandFMAudio::capture_config(const CaptureConfigMessage& message) {
|
|
|
|
if( message.config ) {
|
|
|
|
audio_output.set_stream(std::make_unique<StreamInput>(message.config));
|
|
|
|
} else {
|
|
|
|
audio_output.set_stream(nullptr);
|
|
|
|
}
|
|
|
|
}
|