make it modulate a sine wave which is generated live, not sure if works

This commit is contained in:
2025-05-25 21:47:45 +02:00
parent 854edde90b
commit 852b5041c7
6 changed files with 9 additions and 139 deletions
+7 -37
View File
@@ -1,7 +1,5 @@
#include "modulator.h"
static float waveform[2][FILTER_SIZE];
void Modulator_saveToFile(RDSModulatorParameters *emp, const char *option) {
char modulatorPath[128];
snprintf(modulatorPath, sizeof(modulatorPath), "%s/.rdsModulator", getenv("HOME"));
@@ -90,14 +88,7 @@ void init_rds_modulator(RDSModulator* rdsMod, RDSEncoder* enc) {
rdsMod->enc = enc;
if(STREAMS > 0) rdsMod->data[1].symbol_shifting.symbol_shift = FILTER_SIZE / 2;
for (uint8_t i = 0; i < 2; i++) {
for (uint16_t j = 0; j < FILTER_SIZE; j++) {
waveform[i][j] = i ?
+waveform_biphase[j] : -waveform_biphase[j];
}
}
if(STREAMS > 0) rdsMod->data[1].symbol_shift = FILTER_SIZE / 2;
if(modulatorsaved()) {
Modulator_loadFromFile(&rdsMod->params);
@@ -107,8 +98,10 @@ void init_rds_modulator(RDSModulator* rdsMod, RDSEncoder* enc) {
}
float get_rds_sample(RDSModulator* rdsMod, uint8_t stream) {
float *cur_waveform;
if (rdsMod->data[stream].sample_count == FILTER_SIZE) {
rdsMod->data[stream].phase += 1187.5 / RDS_SAMPLE_RATE;
if (rdsMod->data[stream].phase >= 1.0f) {
rdsMod->data[stream].phase -= 1.0f;
if (rdsMod->data[stream].bit_pos == BITS_PER_GROUP) {
get_rds_bits(rdsMod->enc, rdsMod->data[stream].bit_buffer, stream);
rdsMod->data[stream].bit_pos = 0;
@@ -117,33 +110,10 @@ float get_rds_sample(RDSModulator* rdsMod, uint8_t stream) {
rdsMod->data[stream].cur_bit = rdsMod->data[stream].bit_buffer[rdsMod->data[stream].bit_pos++];
rdsMod->data[stream].prev_output = rdsMod->data[stream].cur_output;
rdsMod->data[stream].cur_output = rdsMod->data[stream].prev_output ^ rdsMod->data[stream].cur_bit;
uint16_t idx = rdsMod->data[stream].in_sample_index;
cur_waveform = waveform[rdsMod->data[stream].cur_output];
for (uint16_t i = 0; i < FILTER_SIZE; i++) {
rdsMod->data[stream].sample_buffer[idx++] += *cur_waveform++;
if (idx == SAMPLE_BUFFER_SIZE) idx = 0;
}
rdsMod->data[stream].in_sample_index += FILTER_SIZE;
if (rdsMod->data[stream].in_sample_index == SAMPLE_BUFFER_SIZE) rdsMod->data[stream].in_sample_index = 0;
rdsMod->data[stream].sample_count = 0;
}
rdsMod->data[stream].sample_count++;
float sample = rdsMod->data[stream].sample_buffer[rdsMod->data[stream].out_sample_index];
if(stream != 0 && rdsMod->data[stream].symbol_shifting.symbol_shift != 0) {
rdsMod->data[stream].symbol_shifting.sample_buffer[rdsMod->data[stream].symbol_shifting.sample_buffer_idx++] = rdsMod->data[stream].sample_buffer[rdsMod->data[stream].out_sample_index];
if (rdsMod->data[stream].symbol_shifting.sample_buffer_idx == rdsMod->data[stream].symbol_shifting.symbol_shift) rdsMod->data[stream].symbol_shifting.sample_buffer_idx = 0;
sample = rdsMod->data[stream].symbol_shifting.sample_buffer[rdsMod->data[stream].symbol_shifting.sample_buffer_idx];
}
rdsMod->data[stream].sample_buffer[rdsMod->data[stream].out_sample_index++] = 0;
if (rdsMod->data[stream].out_sample_index == SAMPLE_BUFFER_SIZE) rdsMod->data[stream].out_sample_index = 0;
float sample = sinf(M_2PI * (rdsMod->data[stream].phase - rdsMod->data[stream].symbol_shift));
if(rdsMod->data[stream].cur_output == 0) sample = -sample; // do bpsk
uint8_t tooutput = rdsMod->params.rdsgen > stream ? 1 : 0;
return sample*rdsMod->params.level*tooutput;
+2 -12
View File
@@ -17,25 +17,15 @@ typedef struct
uint16_t crc;
} RDSModulatorParametersFile;
typedef struct
{
uint8_t symbol_shift: 7;
float sample_buffer[SAMPLE_BUFFER_SIZE];
uint8_t sample_buffer_idx : 7;
} RDSModulatorSymbolShifting;
typedef struct
{
uint8_t bit_buffer[BITS_PER_GROUP];
uint8_t bit_pos : 7;
float sample_buffer[SAMPLE_BUFFER_SIZE];
uint8_t prev_output : 1;
uint8_t cur_output : 1;
uint8_t cur_bit : 1;
uint8_t sample_count;
uint16_t in_sample_index;
uint16_t out_sample_index;
RDSModulatorSymbolShifting symbol_shifting;
uint8_t symbol_shift: 7;
float phase;
} RDSModulatorModulationData;
typedef struct {
-2
View File
@@ -11,8 +11,6 @@
#define GROUP_LENGTH 4
#define BITS_PER_GROUP (GROUP_LENGTH * (BLOCK_SIZE + POLY_DEG))
#define RDS_SAMPLE_RATE 4750
#define FILTER_SIZE 4
#define SAMPLE_BUFFER_SIZE (FILTER_SIZE*2)
#define STREAMS 2
-10
View File
@@ -1,10 +0,0 @@
/* This file was automatically generated by "gen_wave.py".
(C) 2014 Christophe Jacquet.
(C) 2023 Anthony96922.
(C) 2025 kuba201.
Released under the GNU GPL v3 license.
*/
float waveform_biphase[4] = {0.0, 1.0, 1.2246467991473532e-16, -1.0};
-9
View File
@@ -1,9 +0,0 @@
/* This file was automatically generated by "gen_wave.py".
(C) 2014 Christophe Jacquet.
(C) 2023 Anthony96922.
(C) 2025 kuba201.
Released under the GNU GPL v3 license.
*/
extern float waveform_biphase[4];