Fixed LCR transmit and AFSK baseband module

This commit is contained in:
furrtek
2016-07-27 21:26:03 +02:00
parent 79f2134d91
commit e958b4bd7d
18 changed files with 390 additions and 271 deletions

View File

@@ -340,12 +340,12 @@ set(MODE_CPPSRC
)
DeclareTargets(PATX audio_tx)
### FSK LCR
### AFSK
set(MODE_CPPSRC
proc_fsk_lcr.cpp
proc_afsk.cpp
)
DeclareTargets(PLCR lcr)
DeclareTargets(PAFS afsk)
### Epar

View File

@@ -1,5 +1,6 @@
/*
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2016 Furrtek
*
* This file is part of PortaPack.
*
@@ -19,45 +20,49 @@
* Boston, MA 02110-1301, USA.
*/
#include "proc_fsk_lcr.hpp"
#include "proc_afsk.hpp"
#include "portapack_shared_memory.hpp"
#include "sine_table.hpp"
#include "sine_table_int8.hpp"
#include "event_m4.hpp"
#include <cstdint>
void LCRFSKProcessor::execute(const buffer_c8_t& buffer) {
void AFSKProcessor::execute(const buffer_c8_t& buffer) {
// This is called at 2280000/2048 = 1113Hz
if (!configured) return;
for (size_t i = 0; i<buffer.count; i++) {
//Sample generation 2.28M/10 = 228kHz
if (s >= 9) {
// Tone generation at 2280000/10 = 228kHz
if (s >= (10 - 1)) {
s = 0;
if (sample_count >= shared_memory.afsk_samples_per_bit) {
if (shared_memory.afsk_transmit_done == false) {
cur_byte = shared_memory.radio_data[byte_pos];
ext_byte = shared_memory.radio_data[byte_pos + 1];
if (sample_count >= afsk_samples_per_bit) {
if (configured == true) {
cur_byte = message_data[byte_pos];
ext_byte = message_data[byte_pos + 1];
}
if (!cur_byte) {
if (shared_memory.afsk_repeat) {
shared_memory.afsk_repeat--;
if (afsk_repeat) {
afsk_repeat--;
bit_pos = 0;
byte_pos = 0;
cur_byte = shared_memory.radio_data[0];
ext_byte = shared_memory.radio_data[1];
message.n = shared_memory.afsk_repeat;
cur_byte = message_data[0];
ext_byte = message_data[1];
message.n = afsk_repeat;
shared_memory.application_queue.push(message);
} else {
message.n = 0;
shared_memory.afsk_transmit_done = true;
configured = false;
shared_memory.application_queue.push(message);
cur_byte = 0;
ext_byte = 0;
}
}
if (shared_memory.afsk_alt_format) {
if (afsk_alt_format) {
// 0bbbbbbbbp
// Start, 8-bit data, parity
gbyte = 0;
@@ -75,7 +80,7 @@ void LCRFSKProcessor::execute(const buffer_c8_t& buffer) {
if (bit_pos == 9) {
bit_pos = 0;
if (!shared_memory.afsk_alt_format)
if (!afsk_alt_format)
byte_pos++;
else
byte_pos += 2;
@@ -88,30 +93,52 @@ void LCRFSKProcessor::execute(const buffer_c8_t& buffer) {
sample_count++;
}
if (cur_bit)
aphase += shared_memory.afsk_phase_inc_mark;
tone_phase += afsk_phase_inc_mark;
else
aphase += shared_memory.afsk_phase_inc_space;
tone_phase += afsk_phase_inc_space;
} else {
s++;
}
sample = (sine_table_f32[(aphase & 0x03FF0000)>>18]*255);
tone_sample = (sine_table_i8[(tone_phase & 0x03FC0000)>>18]);
//FM
frq = sample * shared_memory.afsk_fmmod;
// FM
// 1<<18 = 262144
// m = (262144 * BW) / 2280000 (* 115, see ui_lcr afsk_bw setting)
frq = tone_sample * afsk_bw;
phase = (phase + frq);
sphase = phase + (256<<16);
sphase = phase + (64<<18);
re = (sine_table_f32[(sphase & 0x03FF0000)>>18]*127);
im = (sine_table_f32[(phase & 0x03FF0000)>>18]*127);
re = (sine_table_i8[(sphase & 0x03FC0000)>>18]);
im = (sine_table_i8[(phase & 0x03FC0000)>>18]);
buffer.p[i] = {(int8_t)re,(int8_t)im};
}
}
void AFSKProcessor::on_message(const Message* const p) {
const auto message = *reinterpret_cast<const AFSKConfigureMessage*>(p);
if (message.id == Message::ID::AFSKConfigure) {
memcpy(message_data, message.message_data, 256);
afsk_samples_per_bit = message.afsk_samples_per_bit;
afsk_phase_inc_mark = message.afsk_phase_inc_mark;
afsk_phase_inc_space = message.afsk_phase_inc_space;
afsk_repeat = message.afsk_repeat;
afsk_bw = message.afsk_bw;
afsk_alt_format = message.afsk_alt_format;
bit_pos = 0;
byte_pos = 0;
cur_byte = 0;
ext_byte = 0;
cur_bit = 0;
configured = true;
}
}
int main() {
EventDispatcher event_dispatcher { std::make_unique<LCRFSKProcessor>() };
EventDispatcher event_dispatcher { std::make_unique<AFSKProcessor>() };
event_dispatcher.run();
return 0;
}

View File

@@ -1,5 +1,6 @@
/*
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2016 Furrtek
*
* This file is part of PortaPack.
*
@@ -19,19 +20,31 @@
* Boston, MA 02110-1301, USA.
*/
#ifndef __PROC_FSK_LCR_H__
#define __PROC_FSK_LCR_H__
#ifndef __PROC_AFSK_H__
#define __PROC_AFSK_H__
#include "baseband_processor.hpp"
#include "baseband_thread.hpp"
class LCRFSKProcessor : public BasebandProcessor {
class AFSKProcessor : public BasebandProcessor {
public:
void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const p) override;
private:
bool configured = false;
BasebandThread baseband_thread { 2280000, this, NORMALPRIO + 20, baseband::Direction::Transmit };
uint32_t afsk_samples_per_bit;
uint32_t afsk_phase_inc_mark;
uint32_t afsk_phase_inc_space;
uint8_t afsk_repeat;
uint32_t afsk_bw;
bool afsk_alt_format;
char message_data[256];
int8_t re, im;
uint8_t s;
uint8_t bit_pos = 0, byte_pos = 0;
@@ -40,8 +53,9 @@ private:
uint16_t gbyte;
uint8_t cur_bit = 0;
uint32_t sample_count;
uint32_t aphase, phase, sphase;
int32_t sample, sig, frq;
uint32_t tone_phase, phase, sphase;
int32_t tone_sample, sig, frq;
TXDoneMessage message;
};

View File

@@ -30,7 +30,8 @@
void RDSProcessor::execute(const buffer_c8_t& buffer) {
uint32_t * rdsdata;
rdsdata = (uint32_t *)shared_memory.radio_data;
// TODO
//rdsdata = (uint32_t *)shared_memory.radio_data;
for (size_t i = 0; i < buffer.count; i++) {

View File

@@ -26,7 +26,7 @@
#include "audio_output.hpp"
#include "portapack_shared_memory.hpp"
#include "sine_table.hpp"
#include "sine_table_int8.hpp"
#include "event_m4.hpp"
#include <cstdint>
@@ -35,18 +35,17 @@ void XylosProcessor::execute(const buffer_c8_t& buffer) {
// This is called at 1536000/2048 = 750Hz
if( !configured ) {
return;
}
if (!configured) return;
for (size_t i = 0; i<buffer.count; i++) {
// Sample generation rate: 1536000/10 = 153kHz
if (s >= (2-1)) {
// Tone generation at 1536000/5 = 307.2kHz
if (s >= (5 - 1)) {
s = 0;
if (silence) {
if (sample_count >= SILENCE) {
// Just occupy channel with carrier
if (sample_count >= CCIR_SILENCE) {
silence = false;
sample_count = CCIR_TONELENGTH;
} else {
@@ -54,16 +53,14 @@ void XylosProcessor::execute(const buffer_c8_t& buffer) {
}
} else {
if (sample_count >= CCIR_TONELENGTH) {
if (transmit_done == false) {
digit = xylosdata[byte_pos++];
if ((digit == 0xFF) || (byte_pos >= 21)) {
message.n = 25; // End of message code
transmit_done = true;
shared_memory.application_queue.push(message);
} else {
message.n = byte_pos; // Inform UI about progress (just as eye candy)
shared_memory.application_queue.push(message);
}
digit = xylosdata[byte_pos++];
if ((digit == 0xFF) || (byte_pos >= 21)) {
configured = false;
message.n = 25; // End of message code
shared_memory.application_queue.push(message);
} else {
message.n = byte_pos; // Inform UI about progress (just as eye candy)
shared_memory.application_queue.push(message);
}
sample_count = 0;
@@ -71,7 +68,7 @@ void XylosProcessor::execute(const buffer_c8_t& buffer) {
sample_count++;
}
aphase += ccir_phases[digit];
tone_phase += ccir_phases[digit];
}
} else {
s++;
@@ -81,7 +78,7 @@ void XylosProcessor::execute(const buffer_c8_t& buffer) {
re = 0;
im = 0;
} else {
sample = (sine_table_f32[(aphase & 0x03FC0000)>>18]*127); // 255 here before
tone_sample = (sine_table_i8[(tone_phase & 0x03FC0000)>>18]);
// Audio preview sample generation: 1536000/48000 = 32
/*if (as >= 31) {
@@ -90,15 +87,17 @@ void XylosProcessor::execute(const buffer_c8_t& buffer) {
} else {
as++;
}*/
//FM
frq = sample * 800; // ?
// FM
// 1<<18 = 262144
// m = (262144 * BW) / 1536000 / 2
frq = tone_sample * 853; // 10kHz BW
phase = (phase + frq);
sphase = phase + (256<<16);
sphase = phase + (64<<18);
re = (sine_table_f32[(sphase & 0x03FC0000)>>18]*127);
im = (sine_table_f32[(phase & 0x03FC0000)>>18]*127);
re = (sine_table_i8[(sphase & 0x03FC0000)>>18]);
im = (sine_table_i8[(phase & 0x03FC0000)>>18]);
}
buffer.p[i] = {(int8_t)re,(int8_t)im};
@@ -115,7 +114,7 @@ void XylosProcessor::on_message(const Message* const p) {
digit = 0;
sample_count = CCIR_TONELENGTH;
as = 0;
transmit_done = false;
silence = true;
configured = true;
}
}

View File

@@ -24,16 +24,13 @@
#define __PROC_XYLOS_H__
#include "baseband_processor.hpp"
#include "dsp_decimate.hpp"
#include "dsp_demodulate.hpp"
#include "audio_output.hpp"
#include "baseband_thread.hpp"
#define CCIR_TONELENGTH (15360*5)-1 // 1536000/10/10
#define PHASEV (436.91/5) // (65536*1024)/1536000*10
#define SILENCE (46080*5)-1 // 400ms
//#include "audio_output.hpp"
#define CCIR_TONELENGTH (15360*2)-1 // 1536000/10/10
#define CCIR_PHASEINC (436.91/2) // (65536*1024)/1536000*10
#define CCIR_SILENCE (122880)-1 // 400ms
class XylosProcessor : public BasebandProcessor {
public:
@@ -43,27 +40,26 @@ public:
private:
bool configured = false;
bool transmit_done = false;
BasebandThread baseband_thread { 1536000, this, NORMALPRIO + 20, baseband::Direction::Transmit };
uint32_t ccir_phases[16] = {
(uint32_t)(1981*PHASEV),
(uint32_t)(1124*PHASEV),
(uint32_t)(1197*PHASEV),
(uint32_t)(1275*PHASEV),
(uint32_t)(1358*PHASEV),
(uint32_t)(1446*PHASEV),
(uint32_t)(1540*PHASEV),
(uint32_t)(1640*PHASEV),
(uint32_t)(1747*PHASEV),
(uint32_t)(1860*PHASEV),
(uint32_t)(2400*PHASEV),
(uint32_t)(930*PHASEV),
(uint32_t)(2247*PHASEV),
(uint32_t)(991*PHASEV),
(uint32_t)(2110*PHASEV),
(uint32_t)(1055*PHASEV)
const uint32_t ccir_phases[16] = {
(uint32_t)(1981*CCIR_PHASEINC),
(uint32_t)(1124*CCIR_PHASEINC),
(uint32_t)(1197*CCIR_PHASEINC),
(uint32_t)(1275*CCIR_PHASEINC),
(uint32_t)(1358*CCIR_PHASEINC),
(uint32_t)(1446*CCIR_PHASEINC),
(uint32_t)(1540*CCIR_PHASEINC),
(uint32_t)(1640*CCIR_PHASEINC),
(uint32_t)(1747*CCIR_PHASEINC),
(uint32_t)(1860*CCIR_PHASEINC),
(uint32_t)(2400*CCIR_PHASEINC),
(uint32_t)(930*CCIR_PHASEINC),
(uint32_t)(2247*CCIR_PHASEINC),
(uint32_t)(991*CCIR_PHASEINC),
(uint32_t)(2110*CCIR_PHASEINC),
(uint32_t)(1055*CCIR_PHASEINC)
};
char xylosdata[21];
@@ -72,8 +68,8 @@ private:
uint8_t byte_pos = 0;
uint8_t digit = 0;
uint32_t sample_count = CCIR_TONELENGTH;
uint32_t aphase, phase, sphase;
int32_t sample, frq;
uint32_t tone_phase, phase, sphase;
int32_t tone_sample, frq;
bool silence = true;
TXDoneMessage message;