From be46dd93d33fa6fe962818329ca8826fd6c3f91d Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Wed, 19 Mar 2025 21:51:59 +0100 Subject: [PATCH] does this cause a segfault? --- .vscode/.server-controller-port.log | 2 +- gen_wave.py | 21 +++++++++++++++------ src/rds.h | 2 +- src/waveforms.c | 2 +- src/waveforms.h | 2 +- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.vscode/.server-controller-port.log b/.vscode/.server-controller-port.log index 37c909c..90b992e 100644 --- a/.vscode/.server-controller-port.log +++ b/.vscode/.server-controller-port.log @@ -1,5 +1,5 @@ { "port": 13452, - "time": 1742327656502, + "time": 1742417504877, "version": "0.0.3" } \ No newline at end of file diff --git a/gen_wave.py b/gen_wave.py index f9f097e..ecd4cc1 100644 --- a/gen_wave.py +++ b/gen_wave.py @@ -60,20 +60,29 @@ outc.write(header) outh.write(header) def generate(): - offset = int(sample_rate*0.004) - count = int(offset / 10**(len(str(offset)) - 1)) l = int(sample_rate / 1187.5) // 2 - if count*l > l*16: raise Exception("Sample rate too small") - print(f"{offset=} {count=} {l=}") - sample = [0.0] * (count*l) + sample = [0.0] * (16*l) sample[l] = 1 sample[2*l] = -1 sf = rrcosfilter(l*16) shapedSamples = convolve(sample, sf) + + lowest = 0 + lowest_idx = 0 + highest = 0 + highest_idx = 0 + for i,j in enumerate(shapedSamples): + if j < lowest: + lowest = j + lowest_idx = i + if j > highest: + highest = j + highest_idx = i + middle = int((lowest_idx+highest_idx)/2) - out = shapedSamples[offset-l*count:offset+l*count] + out = shapedSamples[middle-int(ratio*2):middle+int(ratio*2)] out = [2 * (i - min(out)) / (max(out) - min(out)) - 1 for i in out] if max(out) > 1 or min(out) < -1: raise Exception("Clipped") diff --git a/src/rds.h b/src/rds.h index 6b0b1e1..d094e35 100644 --- a/src/rds.h +++ b/src/rds.h @@ -13,7 +13,7 @@ // Higher sample rate makes you more synchronized so you stay at the 11.4 GPS (group per sec) but lesser sample rate gives a smaller amount of cpu usage #define RDS_SAMPLE_RATE 16625 // pira's m32 works at 361 khz, which is a ratio of 304, but this does a ratio of 14, while the m232 does a ratio of about 500 #define SAMPLES_PER_BIT 14 // this would be your ratio -#define FILTER_SIZE 84 +#define FILTER_SIZE 56 #define SAMPLE_BUFFER_SIZE (SAMPLES_PER_BIT + FILTER_SIZE) #define RT_LENGTH 64 diff --git a/src/waveforms.c b/src/waveforms.c index a980bef..44d618d 100644 --- a/src/waveforms.c +++ b/src/waveforms.c @@ -6,5 +6,5 @@ Released under the GNU GPL v3 license. */ -float waveform_biphase[84] = {0.0004798810307378165, 0.0005158464188224077, 0.00013719954366608889, -0.00041476999846934426, -0.0007191892775416653, -0.0004857966171196715, 0.00018825494724739045, 0.0008295842549825849, 0.0009051529485941678, 0.0002445671263298088, -0.000751794191973798, -0.0013268465280850128, -0.0009132708722269234, 0.0003610677822902808, 0.001625489447084183, 0.0018145689052271319, 0.0005024534563098371, -0.001585786352611529, -0.002879473467708782, -0.0020438605658038567, 0.000835500801372735, 0.00390082480083076, 0.004531695189377238, 0.001311093111172612, -0.004343673377232293, -0.008325008325008265, -0.006278010462553496, 0.0027481739441221897, 0.013873333089300166, 0.01763827184078881, 0.005671482599529876, -0.021310188015785658, -0.04761904761904767, -0.04356053386843084, 0.024589602704327973, 0.17800990857960053, 0.4089809815715042, 0.6732730423553916, 0.8973021064512403, 1.0, 0.9222744610899845, 0.6523476952736391, 0.23572259472961843, -0.23572259472961843, -0.6523476952736391, -0.9222744610899845, -1.0, -0.8973021064512402, -0.6732730423553918, -0.4089809815715043, -0.17800990857960053, -0.024589602704327973, 0.04356053386843084, 0.04761904761904767, 0.02131018801578577, -0.005671482599529876, -0.01763827184078881, -0.013873333089300166, -0.0027481739441221897, 0.006278010462553496, 0.008325008325008376, 0.004343673377232404, -0.001311093111172501, -0.004531695189377238, -0.003900824800830649, -0.000835500801372846, 0.0020438605658037456, 0.002879473467708893, 0.00158578635261164, -0.000502453456309726, -0.0018145689052271319, -0.001625489447084072, -0.0003610677822902808, 0.0009132708722270344, 0.0013268465280849018, 0.000751794191973687, -0.0002445671263296978, -0.0009051529485940568, -0.0008295842549824739, -0.00018825494724750147, 0.0004857966171196715, 0.0007191892775417763, 0.00041476999846934426, -0.0001371995436661999}; +float waveform_biphase[56] = {0.001625489447084183, 0.0018145689052271319, 0.0005024534563098371, -0.001585786352611529, -0.002879473467708782, -0.0020438605658038567, 0.000835500801372735, 0.00390082480083076, 0.004531695189377238, 0.001311093111172612, -0.004343673377232293, -0.008325008325008265, -0.006278010462553496, 0.0027481739441221897, 0.013873333089300166, 0.01763827184078881, 0.005671482599529876, -0.021310188015785658, -0.04761904761904767, -0.04356053386843084, 0.024589602704327973, 0.17800990857960053, 0.4089809815715042, 0.6732730423553916, 0.8973021064512403, 1.0, 0.9222744610899845, 0.6523476952736391, 0.23572259472961843, -0.23572259472961843, -0.6523476952736391, -0.9222744610899845, -1.0, -0.8973021064512402, -0.6732730423553918, -0.4089809815715043, -0.17800990857960053, -0.024589602704327973, 0.04356053386843084, 0.04761904761904767, 0.02131018801578577, -0.005671482599529876, -0.01763827184078881, -0.013873333089300166, -0.0027481739441221897, 0.006278010462553496, 0.008325008325008376, 0.004343673377232404, -0.001311093111172501, -0.004531695189377238, -0.003900824800830649, -0.000835500801372846, 0.0020438605658037456, 0.002879473467708893, 0.00158578635261164, -0.000502453456309726}; diff --git a/src/waveforms.h b/src/waveforms.h index b56d0e6..627a029 100644 --- a/src/waveforms.h +++ b/src/waveforms.h @@ -6,4 +6,4 @@ Released under the GNU GPL v3 license. */ -extern float waveform_biphase[84]; +extern float waveform_biphase[56];