Fix filtering
This commit is contained in:
parent
b24e645017
commit
4b39365588
|
|
@ -37,7 +37,7 @@ def generate_bit_in_context(pattern, name):
|
||||||
|
|
||||||
shapedSamples = rds.unmodulated_signal(pattern, sample_rate)
|
shapedSamples = rds.unmodulated_signal(pattern, sample_rate)
|
||||||
|
|
||||||
out = shapedSamples[offset:offset+l*count]
|
out = shapedSamples #[offset:offset+l*count]
|
||||||
|
|
||||||
iout = (out * 20000./max(abs(out)) ).astype(numpy.dtype('>i2'))
|
iout = (out * 20000./max(abs(out)) ).astype(numpy.dtype('>i2'))
|
||||||
wavfile.write(u"waveform_{}.wav".format(name), sample_rate, iout)
|
wavfile.write(u"waveform_{}.wav".format(name), sample_rate, iout)
|
||||||
|
|
@ -46,11 +46,11 @@ def generate_bit_in_context(pattern, name):
|
||||||
name = name,
|
name = name,
|
||||||
values = u", ".join(map(format_number, out))))
|
values = u", ".join(map(format_number, out))))
|
||||||
|
|
||||||
outh.write(u"extern float waveform_{name}[];\n".format(name=name))
|
outh.write(u"extern float waveform_{name}[{size}];\n".format(name=name, size=len(out)))
|
||||||
|
|
||||||
|
|
||||||
generate_bit_in_context([0, 0, 0], "identical")
|
generate_bit_in_context([1], "biphase")
|
||||||
generate_bit_in_context([0, 1, 0], "different")
|
#generate_bit_in_context([0, 1, 0], "different")
|
||||||
|
|
||||||
outc.close()
|
outc.close()
|
||||||
outh.close()
|
outh.close()
|
||||||
39
src/rds.c
39
src/rds.c
|
|
@ -41,6 +41,7 @@ struct {
|
||||||
|
|
||||||
#define BITS_PER_GROUP (GROUP_LENGTH * (BLOCK_SIZE+POLY_DEG))
|
#define BITS_PER_GROUP (GROUP_LENGTH * (BLOCK_SIZE+POLY_DEG))
|
||||||
#define SAMPLES_PER_BIT 192
|
#define SAMPLES_PER_BIT 192
|
||||||
|
#define FILTER_SIZE (sizeof(waveform_biphase)/sizeof(float))
|
||||||
|
|
||||||
|
|
||||||
uint16_t offset_words[] = {0x0FC, 0x198, 0x168, 0x1B4};
|
uint16_t offset_words[] = {0x0FC, 0x198, 0x168, 0x1B4};
|
||||||
|
|
@ -117,17 +118,20 @@ void get_rds_group(int *buffer) {
|
||||||
void get_rds_samples(float *buffer, int count) {
|
void get_rds_samples(float *buffer, int count) {
|
||||||
static int bit_buffer[BITS_PER_GROUP];
|
static int bit_buffer[BITS_PER_GROUP];
|
||||||
static int bit_pos = BITS_PER_GROUP;
|
static int bit_pos = BITS_PER_GROUP;
|
||||||
|
static float sample_buffer[2*FILTER_SIZE] = {0};
|
||||||
|
|
||||||
static int prev_output = 0;
|
static int prev_output = 0;
|
||||||
static int cur_output = 0;
|
static int cur_output = 0;
|
||||||
static int cur_bit = 0;
|
static int cur_bit = 0;
|
||||||
static int sample_pos = SAMPLES_PER_BIT;
|
static int sample_count = SAMPLES_PER_BIT;
|
||||||
static float *current_waveform = NULL;
|
|
||||||
static int inverting = 0;
|
static int inverting = 0;
|
||||||
static int phase = 0;
|
static int phase = 0;
|
||||||
|
|
||||||
|
static int in_sample_index = 0;
|
||||||
|
static int out_sample_index = FILTER_SIZE;
|
||||||
|
|
||||||
for(int i=0; i<count; i++) {
|
for(int i=0; i<count; i++) {
|
||||||
if(sample_pos >= SAMPLES_PER_BIT) {
|
if(sample_count >= SAMPLES_PER_BIT) {
|
||||||
if(bit_pos >= BITS_PER_GROUP) {
|
if(bit_pos >= BITS_PER_GROUP) {
|
||||||
get_rds_group(bit_buffer);
|
get_rds_group(bit_buffer);
|
||||||
bit_pos = 0;
|
bit_pos = 0;
|
||||||
|
|
@ -138,18 +142,29 @@ void get_rds_samples(float *buffer, int count) {
|
||||||
prev_output = cur_output;
|
prev_output = cur_output;
|
||||||
cur_output = prev_output ^ cur_bit;
|
cur_output = prev_output ^ cur_bit;
|
||||||
|
|
||||||
// select appropriate waveform
|
inverting = (cur_output == 1) ? 1 : -1;
|
||||||
current_waveform = (prev_output == cur_output) ?
|
|
||||||
waveform_identical : waveform_different;
|
float *src = waveform_biphase;
|
||||||
|
int idx = in_sample_index;
|
||||||
inverting = (prev_output == 0) ? 1 : -1;
|
for(int j=0; j<FILTER_SIZE; j++) {
|
||||||
|
//printf("%d ", j); fflush(stdout);
|
||||||
|
if(j<FILTER_SIZE-SAMPLES_PER_BIT) {
|
||||||
|
sample_buffer[idx++] += (*src++) * inverting;
|
||||||
|
} else {
|
||||||
|
sample_buffer[idx++] = (*src++) * inverting;
|
||||||
|
}
|
||||||
|
if(idx >= 2*FILTER_SIZE) idx = 0;
|
||||||
|
}
|
||||||
|
in_sample_index += SAMPLES_PER_BIT;
|
||||||
|
if(in_sample_index >= 2*FILTER_SIZE) in_sample_index -= 2*FILTER_SIZE;
|
||||||
|
|
||||||
bit_pos++;
|
bit_pos++;
|
||||||
sample_pos = 0;
|
sample_count = 0;
|
||||||
//printf("%d", cur_bit); fflush(stdout);
|
//printf("%d", cur_bit); fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
float sample = current_waveform[sample_pos] * inverting;
|
float sample = sample_buffer[out_sample_index++];
|
||||||
|
if(out_sample_index >= 2*FILTER_SIZE) out_sample_index = 0;
|
||||||
|
|
||||||
// modulate at 57 kHz
|
// modulate at 57 kHz
|
||||||
// use phase for this
|
// use phase for this
|
||||||
|
|
@ -163,7 +178,7 @@ void get_rds_samples(float *buffer, int count) {
|
||||||
if(phase >= 4) phase = 0;
|
if(phase >= 4) phase = 0;
|
||||||
|
|
||||||
*buffer++ = sample;
|
*buffer++ = sample;
|
||||||
sample_pos++;
|
sample_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,19 +2,23 @@
|
||||||
|
|
||||||
#include "rds.h"
|
#include "rds.h"
|
||||||
|
|
||||||
#define LENGTH 99840
|
#define LENGTH 100000
|
||||||
|
|
||||||
/* Simple test program */
|
/* Simple test program */
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
set_rds_params(0x1234, "Hello");
|
set_rds_params(0x1234, "Hello! World of the RaspberryPi!");
|
||||||
|
|
||||||
float buffer[LENGTH];
|
float buffer[LENGTH];
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
get_rds_samples(buffer, LENGTH);
|
for(int j=0; j<20; j++) {
|
||||||
|
get_rds_samples(buffer, LENGTH);
|
||||||
for(int j=0; j<50; j++) {
|
|
||||||
|
fprintf(stderr, "Iteration %d count=%d\n", j, count);
|
||||||
|
|
||||||
for(int i=0; i<LENGTH; i++) {
|
for(int i=0; i<LENGTH; i++) {
|
||||||
printf("%c", (((int)(buffer[i]*70))));
|
printf("%c", (((int)(buffer[i]*50))));
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -4,5 +4,4 @@
|
||||||
Released under the GNU GPL v3 license.
|
Released under the GNU GPL v3 license.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern float waveform_identical[];
|
extern float waveform_biphase[575];
|
||||||
extern float waveform_different[];
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue