2015-08-27 20:14:45 +00: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_nfm_audio.hpp"
|
|
|
|
|
2016-01-11 04:25:24 +00:00
|
|
|
#include "dsp_iir_config.hpp"
|
|
|
|
#include "audio_output.hpp"
|
|
|
|
|
2015-08-27 20:14:45 +00:00
|
|
|
#include <cstdint>
|
|
|
|
#include <cstddef>
|
|
|
|
|
2016-01-03 20:49:00 +00:00
|
|
|
void NarrowbandFMAudio::execute(const buffer_c8_t& buffer) {
|
|
|
|
if( !configured ) {
|
|
|
|
return;
|
2015-12-29 18:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2015-08-27 20:14:45 +00:00
|
|
|
|
2015-12-29 18:58:53 +00:00
|
|
|
feed_channel_stats(channel_out);
|
|
|
|
channel_spectrum.feed(channel_out, channel_filter_pass_f, channel_filter_stop_f);
|
2015-08-27 20:14:45 +00:00
|
|
|
|
2015-12-29 18:58:53 +00:00
|
|
|
auto audio = demod.execute(channel_out, work_audio_buffer);
|
2015-08-27 20:14:45 +00:00
|
|
|
|
2016-01-11 04:25:24 +00:00
|
|
|
audio_output.write(audio);
|
2015-08-27 20:14:45 +00:00
|
|
|
}
|
2016-01-03 20:05:47 +00:00
|
|
|
|
|
|
|
void NarrowbandFMAudio::on_message(const Message* const message) {
|
2016-01-03 20:49:00 +00:00
|
|
|
switch(message->id) {
|
|
|
|
case Message::ID::UpdateSpectrum:
|
2016-01-12 18:32:00 +00:00
|
|
|
case Message::ID::SpectrumStreamingConfig:
|
|
|
|
channel_spectrum.on_message(message);
|
2016-01-03 20:49:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Message::ID::NBFMConfigure:
|
|
|
|
configure(*reinterpret_cast<const NBFMConfigureMessage*>(message));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2016-01-03 20:05:47 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-03 20:49:00 +00:00
|
|
|
|
|
|
|
void NarrowbandFMAudio::configure(const NBFMConfigureMessage& message) {
|
|
|
|
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;
|
|
|
|
|
|
|
|
constexpr size_t demod_input_fs = channel_filter_output_fs;
|
|
|
|
|
|
|
|
decim_0.configure(message.decim_0_filter.taps, 33554432);
|
|
|
|
decim_1.configure(message.decim_1_filter.taps, 131072);
|
|
|
|
channel_filter.configure(message.channel_filter.taps, channel_filter_decimation_factor);
|
|
|
|
demod.configure(demod_input_fs, message.deviation);
|
|
|
|
channel_filter_pass_f = message.channel_filter.pass_frequency_normalized * channel_filter_input_fs;
|
|
|
|
channel_filter_stop_f = message.channel_filter.stop_frequency_normalized * channel_filter_input_fs;
|
|
|
|
channel_spectrum.set_decimation_factor(std::floor((channel_filter_output_fs / 2) / ((channel_filter_pass_f + channel_filter_stop_f) / 2)));
|
2016-01-11 04:25:24 +00:00
|
|
|
audio_output.configure(audio_hpf_300hz_config, audio_deemph_300_6_config, 6144);
|
2016-01-03 20:49:00 +00:00
|
|
|
|
|
|
|
configured = true;
|
|
|
|
}
|