2015-11-20 07:59:09 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
2016-07-27 21:26:03 +02:00
|
|
|
* Copyright (C) 2016 Furrtek
|
2015-11-20 07:59:09 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2016-07-27 21:26:03 +02:00
|
|
|
#include "proc_afsk.hpp"
|
2015-11-20 07:59:09 +01:00
|
|
|
#include "portapack_shared_memory.hpp"
|
2016-07-27 21:26:03 +02:00
|
|
|
#include "sine_table_int8.hpp"
|
2016-07-27 03:03:40 +02:00
|
|
|
#include "event_m4.hpp"
|
2015-11-20 07:59:09 +01:00
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
2016-07-27 21:26:03 +02:00
|
|
|
void AFSKProcessor::execute(const buffer_c8_t& buffer) {
|
2023-05-19 08:16:05 +12:00
|
|
|
// This is called at 2.28M/2048 = 1113Hz
|
|
|
|
|
|
|
|
if (!configured) return;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < buffer.count; i++) {
|
|
|
|
if (sample_count >= afsk_samples_per_bit) {
|
|
|
|
if (configured) {
|
|
|
|
cur_word = *word_ptr;
|
|
|
|
|
|
|
|
if (!cur_word) {
|
|
|
|
// End of data
|
|
|
|
if (repeat_counter < afsk_repeat) {
|
|
|
|
// Repeat
|
|
|
|
bit_pos = 0;
|
|
|
|
word_ptr = (uint16_t*)shared_memory.bb_data.data;
|
|
|
|
cur_word = *word_ptr;
|
|
|
|
txprogress_message.done = false;
|
|
|
|
txprogress_message.progress = repeat_counter + 1;
|
|
|
|
shared_memory.application_queue.push(txprogress_message);
|
|
|
|
repeat_counter++;
|
|
|
|
} else {
|
|
|
|
// Stop
|
|
|
|
cur_word = 0;
|
|
|
|
txprogress_message.done = true;
|
|
|
|
shared_memory.application_queue.push(txprogress_message);
|
|
|
|
configured = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cur_bit = (cur_word >> (symbol_count - bit_pos)) & 1;
|
|
|
|
|
|
|
|
if (bit_pos >= symbol_count) {
|
|
|
|
bit_pos = 0;
|
|
|
|
word_ptr++;
|
|
|
|
} else {
|
|
|
|
bit_pos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
sample_count = 0;
|
|
|
|
} else {
|
|
|
|
sample_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cur_bit)
|
|
|
|
tone_phase += afsk_phase_inc_mark;
|
|
|
|
else
|
|
|
|
tone_phase += afsk_phase_inc_space;
|
|
|
|
|
|
|
|
tone_sample = sine_table_i8[(tone_phase & 0xFF000000U) >> 24];
|
|
|
|
|
|
|
|
delta = tone_sample * fm_delta;
|
|
|
|
|
|
|
|
phase += delta;
|
|
|
|
sphase = phase + (64 << 24);
|
|
|
|
|
|
|
|
re = (sine_table_i8[(sphase & 0xFF000000U) >> 24]);
|
|
|
|
im = (sine_table_i8[(phase & 0xFF000000U) >> 24]);
|
|
|
|
|
|
|
|
buffer.p[i] = {re, im};
|
|
|
|
}
|
2015-11-20 07:59:09 +01:00
|
|
|
}
|
2016-07-27 03:03:40 +02:00
|
|
|
|
2016-08-17 02:55:34 +02:00
|
|
|
void AFSKProcessor::on_message(const Message* const msg) {
|
2023-05-19 08:16:05 +12:00
|
|
|
const auto message = *reinterpret_cast<const AFSKTxConfigureMessage*>(msg);
|
|
|
|
|
|
|
|
if (message.id == Message::ID::AFSKTxConfigure) {
|
|
|
|
if (message.samples_per_bit) {
|
|
|
|
afsk_samples_per_bit = message.samples_per_bit;
|
|
|
|
afsk_phase_inc_mark = message.phase_inc_mark * AFSK_DELTA_COEF;
|
|
|
|
afsk_phase_inc_space = message.phase_inc_space * AFSK_DELTA_COEF;
|
|
|
|
afsk_repeat = message.repeat - 1;
|
|
|
|
fm_delta = message.fm_delta * (0xFFFFFFULL / AFSK_SAMPLERATE);
|
|
|
|
symbol_count = message.symbol_count - 1;
|
|
|
|
|
|
|
|
sample_count = afsk_samples_per_bit;
|
|
|
|
repeat_counter = 0;
|
|
|
|
bit_pos = 0;
|
|
|
|
word_ptr = (uint16_t*)shared_memory.bb_data.data;
|
|
|
|
cur_word = 0;
|
|
|
|
cur_bit = 0;
|
|
|
|
configured = true;
|
|
|
|
} else
|
|
|
|
configured = false; // Kill
|
|
|
|
}
|
2016-07-27 21:26:03 +02:00
|
|
|
}
|
|
|
|
|
2016-07-27 03:03:40 +02:00
|
|
|
int main() {
|
2023-05-19 08:16:05 +12:00
|
|
|
EventDispatcher event_dispatcher{std::make_unique<AFSKProcessor>()};
|
|
|
|
event_dispatcher.run();
|
|
|
|
return 0;
|
2016-07-27 03:03:40 +02:00
|
|
|
}
|