From 70f61bfd83234ebcc04b890bb8638c10346983d0 Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Thu, 1 May 2025 14:05:14 +0200 Subject: [PATCH] cleanup --- CMakeLists.txt | 2 +- gen_wave.py | 28 +--------------------------- src/modulator.c | 6 +++--- src/rds.h | 3 +-- src/rds95.c | 4 ++-- 5 files changed, 8 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65959c2..8a66b49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.10) -project(rds95 VERSION 1.3) +project(rds95 VERSION 1.4) add_compile_options(-Wall -Werror -Wextra -pedantic -O2 -std=c18 -march=native -DVERSION=\"${PROJECT_VERSION}\") diff --git a/gen_wave.py b/gen_wave.py index 41265fc..8598fbc 100644 --- a/gen_wave.py +++ b/gen_wave.py @@ -7,38 +7,12 @@ if PLOT: import matplotlib.pyplot as plt if FFT: import numpy as np DATA_RATE = 1187.5 -SIZE_RATIO = 1 ratio = 4 sample_rate = DATA_RATE*ratio print(f"{sample_rate=}") if not sample_rate.is_integer(): raise ValueError("Need a even value") -# this is modified from ChristopheJacquet's pydemod -def rrcosfilter(NumSamples): - T_delta = 1/float(sample_rate) - sample_num = list(range(NumSamples)) - h_rrc = [0.0] * NumSamples - SymbolPeriod = 1/(2*DATA_RATE) - - for x in sample_num: - t = (x-NumSamples/2)*T_delta - if t == 0.0: h_rrc[x] = 1.0 - 1 + (4/math.pi) - elif t == SymbolPeriod/4: h_rrc[x] = (1/math.sqrt(2))*(((1+2/math.pi) * (math.sin(math.pi/4))) + ((1-2/math.pi)*(math.cos(math.pi/4)))) - elif t == -SymbolPeriod/4: h_rrc[x] = (1/math.sqrt(2))*(((1+2/math.pi) * (math.sin(math.pi/4))) + ((1-2/math.pi)*(math.cos(math.pi/4)))) - else: h_rrc[x] = (4*(t/SymbolPeriod)*math.cos(math.pi*t*2/SymbolPeriod)) / (math.pi*t*(1-(4*t/SymbolPeriod)*(4*t/SymbolPeriod))/SymbolPeriod) - blackman = [0.42 + 0.5*math.cos(math.pi*i/(NumSamples-1)) + 0.08*math.cos(2.0*math.pi*i/(NumSamples-1)) for i in range(NumSamples)] - h_rrc = [h_rrc[i] * blackman[i] for i in range(NumSamples)] - - return h_rrc - -def convolve(a, b): - out = [0] * (len(a) + len(b) - 1) - for i in range(len(a)): - for j in range(len(b)): - out[i+j] += a[i] * b[j] - return out - PATH = os.path.dirname(os.path.abspath(__file__)) outc = io.open(f"{PATH}/src/waveforms.c", mode="w", encoding="utf8") @@ -60,7 +34,7 @@ outh.write(header) def generate(): t = [i / sample_rate for i in range(ratio)] out = [math.sin(2 * math.pi * DATA_RATE * time) for time in t] - print(f"{len(out)=} {len(out)/sample_rate=} {1/DATA_RATE=}") + print(f"{len(out)=}") if PLOT: plt.plot(out*4, label="out") diff --git a/src/modulator.c b/src/modulator.c index 336efad..d9813cf 100644 --- a/src/modulator.c +++ b/src/modulator.c @@ -90,7 +90,7 @@ void init_rds_modulator(RDSModulator* rdsMod, RDSEncoder* enc) { rdsMod->enc = enc; - if(STREAMS > 0) rdsMod->data[1].symbol_shifting.symbol_shift = SAMPLES_PER_BIT / 2; + 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++) { @@ -108,7 +108,7 @@ 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 == SAMPLES_PER_BIT) { + if (rdsMod->data[stream].sample_count == FILTER_SIZE) { 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; @@ -126,7 +126,7 @@ float get_rds_sample(RDSModulator* rdsMod, uint8_t stream) { if (idx == SAMPLE_BUFFER_SIZE) idx = 0; } - rdsMod->data[stream].in_sample_index += SAMPLES_PER_BIT; + 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; diff --git a/src/rds.h b/src/rds.h index d425ebe..7fc5fb3 100644 --- a/src/rds.h +++ b/src/rds.h @@ -11,9 +11,8 @@ #define GROUP_LENGTH 4 #define BITS_PER_GROUP (GROUP_LENGTH * (BLOCK_SIZE + POLY_DEG)) #define RDS_SAMPLE_RATE 4750 -#define SAMPLES_PER_BIT 4 #define FILTER_SIZE 4 -#define SAMPLE_BUFFER_SIZE (SAMPLES_PER_BIT + FILTER_SIZE) +#define SAMPLE_BUFFER_SIZE (FILTER_SIZE*2) #define STREAMS 2 diff --git a/src/rds95.c b/src/rds95.c index dd51689..d72a69b 100644 --- a/src/rds95.c +++ b/src/rds95.c @@ -94,8 +94,8 @@ int main(int argc, char **argv) { format.rate = RDS_SAMPLE_RATE; buffer.prebuf = 0; - buffer.tlength = NUM_MPX_FRAMES*4; - buffer.maxlength = NUM_MPX_FRAMES*4; + buffer.tlength = NUM_MPX_FRAMES*2; + buffer.maxlength = NUM_MPX_FRAMES*2; rds_device = pa_simple_new( NULL,