pi_fm_rds.c now uses fm_mpx.c, but stereo not yet functional
This commit is contained in:
parent
dad13529a3
commit
93fc47c555
|
|
@ -1,8 +1,8 @@
|
||||||
CC = gcc
|
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 fm_mpx.o
|
||||||
$(CC) -o pi_fm_rds rds.o waveforms.o pi_fm_rds.o -lm -lsndfile
|
$(CC) -o pi_fm_rds rds.o waveforms.o pi_fm_rds.o fm_mpx.o -lm -lsndfile
|
||||||
|
|
||||||
rds_wav: rds.o waveforms.o rds_wav.o fm_mpx.o
|
rds_wav: rds.o waveforms.o rds_wav.o fm_mpx.o
|
||||||
$(CC) -o rds_wav rds_wav.o rds.o waveforms.o fm_mpx.o -lm -lsndfile
|
$(CC) -o rds_wav rds_wav.o rds.o waveforms.o fm_mpx.o -lm -lsndfile
|
||||||
|
|
|
||||||
|
|
@ -245,7 +245,7 @@ int fm_mpx_close() {
|
||||||
fprintf(stderr, "Error closing audio file");
|
fprintf(stderr, "Error closing audio file");
|
||||||
}
|
}
|
||||||
|
|
||||||
free(audio_buffer);
|
if(audio_buffer != NULL) free(audio_buffer);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -100,6 +100,7 @@
|
||||||
#include <sndfile.h>
|
#include <sndfile.h>
|
||||||
|
|
||||||
#include "rds.h"
|
#include "rds.h"
|
||||||
|
#include "fm_mpx.h"
|
||||||
|
|
||||||
|
|
||||||
#define NUM_SAMPLES 50000
|
#define NUM_SAMPLES 50000
|
||||||
|
|
@ -202,6 +203,9 @@ terminate(int dummy)
|
||||||
dma_reg[DMA_CS] = BCM2708_DMA_RESET;
|
dma_reg[DMA_CS] = BCM2708_DMA_RESET;
|
||||||
udelay(10);
|
udelay(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fm_mpx_close();
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -259,11 +263,10 @@ map_peripheral(uint32_t base, uint32_t len)
|
||||||
|
|
||||||
|
|
||||||
#define SUBSIZE 1
|
#define SUBSIZE 1
|
||||||
#define RDS_DATA_SIZE 5000
|
#define DATA_SIZE 5000
|
||||||
#define DATA_SIZE 10000
|
|
||||||
|
|
||||||
|
|
||||||
int tx(uint32_t carrier_freq, SNDFILE *sf, uint16_t pi, char *ps, char *rt, int16_t ppm) {
|
int tx(uint32_t carrier_freq, char *audio_file, uint16_t pi, char *ps, char *rt, int16_t ppm) {
|
||||||
int i, fd, pid;
|
int i, fd, pid;
|
||||||
char pagemap_fn[64];
|
char pagemap_fn[64];
|
||||||
|
|
||||||
|
|
@ -407,14 +410,13 @@ int tx(uint32_t carrier_freq, SNDFILE *sf, uint16_t pi, char *ps, char *rt, int1
|
||||||
|
|
||||||
uint32_t last_cb = (uint32_t)ctl->cb;
|
uint32_t last_cb = (uint32_t)ctl->cb;
|
||||||
|
|
||||||
// Data structures for sound data
|
// Data structures for baseband data
|
||||||
float data[DATA_SIZE];
|
float data[DATA_SIZE];
|
||||||
int data_len = 0;
|
int data_len = 0;
|
||||||
int data_index = 0;
|
int data_index = 0;
|
||||||
|
|
||||||
// Data structures for RDS data
|
// Initialize the baseband generator
|
||||||
float rds_data[RDS_DATA_SIZE];
|
fm_mpx_open(audio_file, DATA_SIZE);
|
||||||
int rds_index = sizeof(rds_data);
|
|
||||||
|
|
||||||
// Initialize the RDS modulator
|
// Initialize the RDS modulator
|
||||||
char myps[9] = {0};
|
char myps[9] = {0};
|
||||||
|
|
@ -442,7 +444,7 @@ int tx(uint32_t carrier_freq, SNDFILE *sf, uint16_t pi, char *ps, char *rt, int1
|
||||||
count2++;
|
count2++;
|
||||||
}
|
}
|
||||||
if(count == 1024) {
|
if(count == 1024) {
|
||||||
set_rds_ps("Pi-FmRds");
|
set_rds_ps("RPi-Live");
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
|
|
@ -459,39 +461,16 @@ int tx(uint32_t carrier_freq, SNDFILE *sf, uint16_t pi, char *ps, char *rt, int1
|
||||||
free_slots += NUM_SAMPLES;
|
free_slots += NUM_SAMPLES;
|
||||||
|
|
||||||
while (free_slots >= SUBSIZE) {
|
while (free_slots >= SUBSIZE) {
|
||||||
// generate RDS samples if necessary
|
// get more baseband samples if necessary
|
||||||
if(rds_index >= RDS_DATA_SIZE) {
|
if(data_len == 0) {
|
||||||
get_rds_samples(rds_data, RDS_DATA_SIZE);
|
fm_mpx_get_samples(data);
|
||||||
rds_index = 0;
|
data_len = DATA_SIZE;
|
||||||
}
|
|
||||||
|
|
||||||
// read samples in the wav file if necessary
|
|
||||||
if(sf && data_len == 0) {
|
|
||||||
for(int j=0; j<2; j++) { // one retry
|
|
||||||
data_len = sf_read_float(sf, data, DATA_SIZE);
|
|
||||||
if (data_len < 0)
|
|
||||||
fatal("Error reading data: %m\n");
|
|
||||||
if(data_len == 0) {
|
|
||||||
sf_seek(sf, 0, SEEK_SET);
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
data_index = 0;
|
data_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float dval = data[data_index] * (DEVIATION / 10.);
|
||||||
|
data_index++;
|
||||||
//float dval = (float)(data[data_index])/65536.0 * DEVIATION;
|
data_len--;
|
||||||
float dval = rds_data[rds_index] * (DEVIATION / 10.);
|
|
||||||
rds_index++;
|
|
||||||
|
|
||||||
// add modulation from .wav?
|
|
||||||
if(sf && data_len > 0) {
|
|
||||||
dval += data[data_index] * DEVIATION/2;
|
|
||||||
data_index++;
|
|
||||||
data_len--;
|
|
||||||
}
|
|
||||||
|
|
||||||
int intval = (int)((floor)(dval));
|
int intval = (int)((floor)(dval));
|
||||||
//int frac = (int)((dval - (float)intval) * SUBSIZE);
|
//int frac = (int)((dval - (float)intval) * SUBSIZE);
|
||||||
|
|
@ -513,7 +492,7 @@ int tx(uint32_t carrier_freq, SNDFILE *sf, uint16_t pi, char *ps, char *rt, int1
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
SNDFILE *sf = NULL;
|
char *audio_file = NULL;
|
||||||
uint32_t carrier_freq = 107900000;
|
uint32_t carrier_freq = 107900000;
|
||||||
char *ps = NULL;
|
char *ps = NULL;
|
||||||
char *rt = "PiFmRds: live FM-RDS transmission from the RaspberryPi";
|
char *rt = "PiFmRds: live FM-RDS transmission from the RaspberryPi";
|
||||||
|
|
@ -530,12 +509,7 @@ int main(int argc, char **argv) {
|
||||||
i++;
|
i++;
|
||||||
// Try to read audio samples from a .wav file
|
// Try to read audio samples from a .wav file
|
||||||
printf("Using .wav file: %s\n", param);
|
printf("Using .wav file: %s\n", param);
|
||||||
SF_INFO info;
|
audio_file = param;
|
||||||
sf = sf_open(param,SFM_READ,&info);
|
|
||||||
if(sf == NULL)
|
|
||||||
fatal("Failed to read .wav file\n");
|
|
||||||
if(info.samplerate != 228000)
|
|
||||||
fatal("Sample rate must be 228 kHz\n");
|
|
||||||
} else if(strcmp("-freq", arg)==0 && param != NULL) {
|
} else if(strcmp("-freq", arg)==0 && param != NULL) {
|
||||||
i++;
|
i++;
|
||||||
carrier_freq = 1e6 * atof(param);
|
carrier_freq = 1e6 * atof(param);
|
||||||
|
|
@ -559,5 +533,5 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tx(carrier_freq, sf, pi, ps, rt, ppm);
|
tx(carrier_freq, audio_file, pi, ps, rt, ppm);
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue