2015-08-27 16:07:07 -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_am_audio.hpp"
|
|
|
|
|
2016-01-10 23:25:24 -05:00
|
|
|
#include "audio_output.hpp"
|
2024-03-13 11:07:44 -04:00
|
|
|
#include "audio_dma.hpp"
|
2016-01-10 23:25:24 -05:00
|
|
|
|
2016-06-30 14:53:58 -04:00
|
|
|
#include "event_m4.hpp"
|
|
|
|
|
2016-01-03 19:58:08 -05:00
|
|
|
#include <array>
|
|
|
|
|
2015-12-29 13:58:53 -05:00
|
|
|
void NarrowbandAMAudio::execute(const buffer_c8_t& buffer) {
|
2023-05-18 16:16:05 -04:00
|
|
|
if (!configured) {
|
|
|
|
return;
|
|
|
|
}
|
2016-01-03 17:31:39 -05:00
|
|
|
|
2023-05-18 16:16:05 -04: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);
|
2020-08-18 18:04:14 -04:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
channel_spectrum.feed(decim_1_out, channel_filter_low_f, channel_filter_high_f, channel_filter_transition);
|
2020-08-18 18:04:14 -04:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
const auto decim_2_out = decim_2.execute(decim_1_out, dst_buffer);
|
|
|
|
const auto channel_out = channel_filter.execute(decim_2_out, dst_buffer);
|
2015-08-27 16:07:07 -04:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
// TODO: Feed channel_stats post-decimation data?
|
|
|
|
feed_channel_stats(channel_out);
|
2015-08-27 16:07:07 -04:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
auto audio = demodulate(channel_out);
|
|
|
|
audio_compressor.execute_in_place(audio);
|
|
|
|
audio_output.write(audio);
|
2016-01-30 21:02:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
buffer_f32_t NarrowbandAMAudio::demodulate(const buffer_c16_t& channel) {
|
2023-05-18 16:16:05 -04:00
|
|
|
if (modulation_ssb) {
|
|
|
|
return demod_ssb.execute(channel, audio_buffer);
|
|
|
|
} else {
|
|
|
|
return demod_am.execute(channel, audio_buffer);
|
|
|
|
}
|
2015-08-27 16:07:07 -04:00
|
|
|
}
|
2016-01-03 15:05:47 -05:00
|
|
|
|
|
|
|
void NarrowbandAMAudio::on_message(const Message* const message) {
|
2023-05-18 16:16:05 -04:00
|
|
|
switch (message->id) {
|
|
|
|
case Message::ID::UpdateSpectrum:
|
|
|
|
case Message::ID::SpectrumStreamingConfig:
|
|
|
|
channel_spectrum.on_message(message);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Message::ID::AMConfigure:
|
|
|
|
configure(*reinterpret_cast<const AMConfigureMessage*>(message));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Message::ID::CaptureConfig:
|
|
|
|
capture_config(*reinterpret_cast<const CaptureConfigMessage*>(message));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-01-03 15:05:47 -05:00
|
|
|
}
|
2016-01-03 17:31:39 -05:00
|
|
|
|
|
|
|
void NarrowbandAMAudio::configure(const AMConfigureMessage& message) {
|
2023-05-18 16:16:05 -04:00
|
|
|
constexpr size_t decim_0_input_fs = baseband_fs;
|
|
|
|
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_output_fs = decim_1_input_fs / decim_1.decimation_factor;
|
|
|
|
|
|
|
|
constexpr size_t decim_2_input_fs = decim_1_output_fs;
|
|
|
|
constexpr size_t decim_2_output_fs = decim_2_input_fs / decim_2_decimation_factor;
|
|
|
|
|
|
|
|
constexpr size_t channel_filter_input_fs = decim_2_output_fs;
|
|
|
|
// const size_t channel_filter_output_fs = channel_filter_input_fs / channel_filter_decimation_factor;
|
|
|
|
|
2023-08-30 12:05:49 -04:00
|
|
|
decim_0.configure(message.decim_0_filter.taps);
|
|
|
|
decim_1.configure(message.decim_1_filter.taps);
|
2023-05-18 16:16:05 -04:00
|
|
|
decim_2.configure(message.decim_2_filter.taps, decim_2_decimation_factor);
|
|
|
|
channel_filter.configure(message.channel_filter.taps, channel_filter_decimation_factor);
|
|
|
|
channel_filter_low_f = message.channel_filter.low_frequency_normalized * channel_filter_input_fs;
|
|
|
|
channel_filter_high_f = message.channel_filter.high_frequency_normalized * channel_filter_input_fs;
|
|
|
|
channel_filter_transition = message.channel_filter.transition_normalized * channel_filter_input_fs;
|
|
|
|
channel_spectrum.set_decimation_factor(1.0f);
|
|
|
|
modulation_ssb = (message.modulation == AMConfigureMessage::Modulation::SSB);
|
|
|
|
audio_output.configure(message.audio_hpf_config);
|
|
|
|
|
|
|
|
configured = true;
|
2016-01-03 17:31:39 -05:00
|
|
|
}
|
2016-04-23 18:07:44 -04:00
|
|
|
|
|
|
|
void NarrowbandAMAudio::capture_config(const CaptureConfigMessage& message) {
|
2023-05-18 16:16:05 -04:00
|
|
|
if (message.config) {
|
|
|
|
audio_output.set_stream(std::make_unique<StreamInput>(message.config));
|
|
|
|
} else {
|
|
|
|
audio_output.set_stream(nullptr);
|
|
|
|
}
|
2016-04-23 18:07:44 -04:00
|
|
|
}
|
2016-06-30 14:53:58 -04:00
|
|
|
|
2016-07-25 00:42:11 -04:00
|
|
|
int main() {
|
2024-03-13 11:07:44 -04:00
|
|
|
audio::dma::init_audio_out();
|
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
EventDispatcher event_dispatcher{std::make_unique<NarrowbandAMAudio>()};
|
|
|
|
event_dispatcher.run();
|
|
|
|
return 0;
|
2016-06-30 14:53:58 -04:00
|
|
|
}
|