2015-11-20 01:59:09 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
2016-12-01 00:58:47 -05:00
|
|
|
* Copyright (C) 2016 Furrtek
|
2015-11-20 01:59:09 -05: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "proc_jammer.hpp"
|
|
|
|
#include "portapack_shared_memory.hpp"
|
2016-12-01 00:58:47 -05:00
|
|
|
#include "sine_table_int8.hpp"
|
2016-07-26 21:03:40 -04:00
|
|
|
#include "event_m4.hpp"
|
2015-11-20 01:59:09 -05:00
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
2016-02-04 04:27:53 -05:00
|
|
|
void JammerProcessor::execute(const buffer_c8_t& buffer) {
|
2016-12-01 00:58:47 -05:00
|
|
|
if (!configured) return;
|
|
|
|
|
2017-01-17 03:42:35 -05:00
|
|
|
for (size_t i = 0; i < buffer.count; i++) {
|
2015-11-20 01:59:09 -05:00
|
|
|
|
2017-01-17 03:42:35 -05:00
|
|
|
if (!jammer_duration) {
|
|
|
|
// Find next enabled range
|
2017-01-17 09:27:37 -05:00
|
|
|
do {
|
2017-01-17 03:42:35 -05:00
|
|
|
current_range++;
|
2017-02-02 04:29:14 -05:00
|
|
|
if (current_range == 24) current_range = 0; // Warning ! Should match JAMMER_MAX_CH
|
2017-01-17 09:27:37 -05:00
|
|
|
} while (!jammer_channels[current_range].enabled);
|
2015-11-20 01:59:09 -05:00
|
|
|
|
2017-01-17 09:27:37 -05:00
|
|
|
jammer_duration = jammer_channels[current_range].duration;
|
|
|
|
jammer_bw = jammer_channels[current_range].width / 5; // TODO: Exact value
|
2017-01-17 03:42:35 -05:00
|
|
|
|
|
|
|
// Ask for retune
|
2017-01-17 09:27:37 -05:00
|
|
|
message.freq = jammer_channels[current_range].center;
|
2017-01-17 03:42:35 -05:00
|
|
|
message.range = current_range;
|
2015-11-20 01:59:09 -05:00
|
|
|
shared_memory.application_queue.push(message);
|
|
|
|
} else {
|
2017-01-17 03:42:35 -05:00
|
|
|
jammer_duration--;
|
2015-11-20 01:59:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ramp
|
|
|
|
/*if (r >= 10) {
|
|
|
|
if (sample < 128)
|
|
|
|
sample++;
|
|
|
|
else
|
|
|
|
sample = -127;
|
|
|
|
r = 0;
|
|
|
|
} else {
|
|
|
|
r++;
|
|
|
|
}*/
|
|
|
|
|
2017-01-17 03:42:35 -05:00
|
|
|
// Phase noise
|
2017-01-17 09:27:37 -05:00
|
|
|
if (r >= 10) {
|
2017-01-29 20:09:00 -05:00
|
|
|
aphase += ((aphase >> 4) ^ 0x4573) << 20;
|
2015-11-20 01:59:09 -05:00
|
|
|
r = 0;
|
|
|
|
} else {
|
|
|
|
r++;
|
|
|
|
}
|
|
|
|
|
|
|
|
aphase += 8830;
|
2017-01-29 20:09:00 -05:00
|
|
|
sample = sine_table_i8[(aphase & 0xFF000000) >> 24];
|
2015-11-20 01:59:09 -05:00
|
|
|
|
2016-12-01 00:58:47 -05:00
|
|
|
// FM
|
2016-12-05 06:56:41 -05:00
|
|
|
delta = sample * jammer_bw;
|
2015-11-20 01:59:09 -05:00
|
|
|
|
2017-01-17 03:42:35 -05:00
|
|
|
phase += delta;
|
2017-01-29 20:09:00 -05:00
|
|
|
sphase = phase + (64 << 24);
|
2015-11-20 01:59:09 -05:00
|
|
|
|
2017-01-29 20:09:00 -05:00
|
|
|
re = (sine_table_i8[(sphase & 0xFF000000) >> 24]);
|
|
|
|
im = (sine_table_i8[(phase & 0xFF000000) >> 24]);
|
2017-01-17 03:42:35 -05:00
|
|
|
|
2017-01-29 20:09:00 -05:00
|
|
|
buffer.p[i] = {re, im};
|
2015-11-20 01:59:09 -05:00
|
|
|
}
|
|
|
|
};
|
2016-07-26 21:03:40 -04:00
|
|
|
|
2016-12-01 00:58:47 -05:00
|
|
|
void JammerProcessor::on_message(const Message* const msg) {
|
2017-01-17 03:42:35 -05:00
|
|
|
const auto message = *reinterpret_cast<const JammerConfigureMessage*>(msg);
|
2016-12-05 06:56:41 -05:00
|
|
|
|
2017-01-17 03:42:35 -05:00
|
|
|
if (message.id == Message::ID::JammerConfigure) {
|
2017-01-17 09:27:37 -05:00
|
|
|
if (message.run) {
|
|
|
|
jammer_channels = (JammerChannel*)shared_memory.bb_data.data;
|
2017-01-29 20:09:00 -05:00
|
|
|
noise_type = message.type;
|
|
|
|
noise_speed = message.speed;
|
2017-01-17 09:27:37 -05:00
|
|
|
jammer_duration = 0;
|
|
|
|
current_range = 0;
|
|
|
|
|
|
|
|
configured = true;
|
|
|
|
} else {
|
|
|
|
configured = false;
|
|
|
|
}
|
2017-01-17 03:42:35 -05:00
|
|
|
}
|
2016-12-01 00:58:47 -05:00
|
|
|
}
|
|
|
|
|
2016-07-26 21:03:40 -04:00
|
|
|
int main() {
|
|
|
|
EventDispatcher event_dispatcher { std::make_unique<JammerProcessor>() };
|
|
|
|
event_dispatcher.run();
|
|
|
|
return 0;
|
|
|
|
}
|