Fixes: functional code
This commit is contained in:
parent
8f35b00bce
commit
36c588d9d9
|
|
@ -2,7 +2,7 @@ CC = gcc
|
||||||
CFLAGS = -Wall -std=gnu99 -c -g -O2
|
CFLAGS = -Wall -std=gnu99 -c -g -O2
|
||||||
|
|
||||||
app: rds.o waveforms.o pi_fm_rds.o
|
app: rds.o waveforms.o pi_fm_rds.o
|
||||||
$(CC) -o pi_fm_rds rds.o waveforms.o pi_fm_rds.o -lm
|
$(CC) -o pi_fm_rds rds.o waveforms.o pi_fm_rds.o -lm -lsndfile
|
||||||
|
|
||||||
rds_wav: rds.o waveforms.o rds_wav.o
|
rds_wav: rds.o waveforms.o rds_wav.o
|
||||||
$(CC) -o rds_wav rds_wav.o rds.o waveforms.o -lsndfile
|
$(CC) -o rds_wav rds_wav.o rds.o waveforms.o -lsndfile
|
||||||
|
|
@ -19,8 +19,5 @@ pi_fm_rds.o: pi_fm_rds.c
|
||||||
rds_wav.o: rds_wav.c
|
rds_wav.o: rds_wav.c
|
||||||
$(CC) $(CFLAGS) rds_wav.c
|
$(CC) $(CFLAGS) rds_wav.c
|
||||||
|
|
||||||
waveforms.h: generate_waveforms.py
|
|
||||||
python generate_waveforms.py
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm *.o
|
rm *.o
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,7 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
#include <sndfile.h>
|
||||||
|
|
||||||
#include "rds.h"
|
#include "rds.h"
|
||||||
|
|
||||||
|
|
@ -259,6 +260,7 @@ map_peripheral(uint32_t base, uint32_t len)
|
||||||
|
|
||||||
#define SUBSIZE 1
|
#define SUBSIZE 1
|
||||||
#define RDS_DATA_SIZE 5000
|
#define RDS_DATA_SIZE 5000
|
||||||
|
#define DATA_SIZE 10000
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
@ -375,7 +377,7 @@ main(int argc, char **argv)
|
||||||
clk_reg[PWMCLK_CNTL] = 0x5A000006; // Source=PLLD and disable
|
clk_reg[PWMCLK_CNTL] = 0x5A000006; // Source=PLLD and disable
|
||||||
udelay(100);
|
udelay(100);
|
||||||
// theorically : 1096 + 2012*2^-12
|
// theorically : 1096 + 2012*2^-12
|
||||||
clk_reg[PWMCLK_DIV] = 0x5A000000 | (1096<<12) | 1916; // 1916 on my RaspberryPi
|
clk_reg[PWMCLK_DIV] = 0x5A000000 | (1096<<12) | 2012; // 1916 on my RaspberryPi
|
||||||
udelay(100);
|
udelay(100);
|
||||||
clk_reg[PWMCLK_CNTL] = 0x5A000216; // Source=PLLD and enable + MASH filter 1
|
clk_reg[PWMCLK_CNTL] = 0x5A000216; // Source=PLLD and enable + MASH filter 1
|
||||||
udelay(100);
|
udelay(100);
|
||||||
|
|
@ -399,16 +401,19 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
|
|
||||||
// Try to read audio samples from a .wav file
|
// Try to read audio samples from a .wav file
|
||||||
fd = 0;
|
SNDFILE *sf = NULL;
|
||||||
short data[1024];
|
SF_INFO info;
|
||||||
|
|
||||||
|
float data[DATA_SIZE];
|
||||||
int data_len = 0;
|
int data_len = 0;
|
||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
fd = open(argv[1], 'r');
|
sf = sf_open(argv[1],SFM_READ,&info);
|
||||||
|
if(sf == NULL)
|
||||||
data_len = read(fd, data, 22);
|
|
||||||
if (data_len < 22)
|
|
||||||
fatal("Failed to read .wav file\n");
|
fatal("Failed to read .wav file\n");
|
||||||
|
if(info.samplerate != 228000)
|
||||||
|
fatal("Sample rate must be 228 kHz\n");
|
||||||
|
|
||||||
data_len = 0;
|
data_len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -426,13 +431,7 @@ main(int argc, char **argv)
|
||||||
uint16_t count = 0;
|
uint16_t count = 0;
|
||||||
uint16_t count2 = 0;
|
uint16_t count2 = 0;
|
||||||
|
|
||||||
printf("Starting to transmit\n");
|
printf("Starting to transmit on %3.1f MHz.\n", carrier_freq/1e6);
|
||||||
|
|
||||||
int do_tune = 1;
|
|
||||||
int tune_on = 1;
|
|
||||||
uint8_t tune_idx = 0;
|
|
||||||
uint32_t tune_cycle_counter = 0;
|
|
||||||
float tune_level = 1;
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if(count == 512) {
|
if(count == 512) {
|
||||||
|
|
@ -465,13 +464,16 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// read samples in the wav file if necessary
|
// read samples in the wav file if necessary
|
||||||
if(fd && data_len == 0) {
|
if(sf && data_len == 0) {
|
||||||
data_len = read(fd, data, sizeof(data));
|
for(int j=0; j<2; j++) { // one retry
|
||||||
if (data_len < 0)
|
data_len = sf_read_float(sf, data, DATA_SIZE);
|
||||||
fatal("Error reading data: %m\n");
|
if (data_len < 0)
|
||||||
data_len /= 2;
|
fatal("Error reading data: %m\n");
|
||||||
if(data_len == 0) {
|
if(data_len == 0) {
|
||||||
lseek(fd, 22, SEEK_SET);
|
sf_seek(sf, 0, SEEK_SET);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
data_index = 0;
|
data_index = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -482,30 +484,15 @@ main(int argc, char **argv)
|
||||||
float dval = rds_data[rds_index] * (DEVIATION / 10.);
|
float dval = rds_data[rds_index] * (DEVIATION / 10.);
|
||||||
rds_index++;
|
rds_index++;
|
||||||
|
|
||||||
// add modulation from a 445 Hz (228000 /2 /256) tune
|
|
||||||
if(do_tune) {
|
|
||||||
if(tune_idx == 0 && tune_on) {
|
|
||||||
tune_level = 1-tune_level;
|
|
||||||
}
|
|
||||||
dval += tune_level * DEVIATION/5.;
|
|
||||||
tune_idx++;
|
|
||||||
|
|
||||||
tune_cycle_counter++;
|
|
||||||
if(tune_cycle_counter >= 228000) {
|
|
||||||
tune_cycle_counter = 0;
|
|
||||||
tune_on = !tune_on;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// add modulation from .wav?
|
// add modulation from .wav?
|
||||||
else if(fd && data_len > 0) {
|
if(sf && data_len > 0) {
|
||||||
|
dval += data[data_index] * DEVIATION/2;
|
||||||
data_index++;
|
data_index++;
|
||||||
data_len--;
|
data_len--;
|
||||||
// do something here
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int intval = (int)((floor)(dval));
|
int intval = (int)((floor)(dval));
|
||||||
//int frac = (int)((dval - (float)intval) * SUBSIZE);
|
//int frac = (int)((dval - (float)intval) * SUBSIZE);
|
||||||
//int j;
|
|
||||||
|
|
||||||
|
|
||||||
ctl->sample[last_sample++] = (0x5A << 24 | freq_ctl) + intval; //(frac > j ? intval + 1 : intval);
|
ctl->sample[last_sample++] = (0x5A << 24 | freq_ctl) + intval; //(frac > j ? intval + 1 : intval);
|
||||||
|
|
@ -516,8 +503,6 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
last_cb = (uint32_t)virtbase + last_sample * sizeof(dma_cb_t) * 2;
|
last_cb = (uint32_t)virtbase + last_sample * sizeof(dma_cb_t) * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("EOF reached\n");
|
|
||||||
|
|
||||||
terminate(0);
|
terminate(0);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue