From 300414ef5e49e8c4f24ee91b722c7380833e12c6 Mon Sep 17 00:00:00 2001 From: zeitbinder Date: Sat, 8 Nov 2014 23:32:46 +0100 Subject: [PATCH 1/3] Added command line option for frequency deviation. --- README.md | 1 + src/pi_fm_rds.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c79410f..0e3e423 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ All arguments are optional: * `-rt` specifies the radiotext (RT) to be transmitted. Limit: 64 characters. Example: `-rt 'Hello, world!'`. * `-ctl` specifies a named pipe (FIFO) to use as a control channel to change PS and RT at run-time (see below). * `-ppm` specifies your Raspberry Pi's oscillator error in parts per million (ppm), see below. +* `-dev` specifies the frequency deviation (in KHz). Example `-dev 25.0`. By default the PS changes back and forth between `Pi-FmRds` and a sequence number, starting at `00000000`. The PS changes around one time per second. diff --git a/src/pi_fm_rds.c b/src/pi_fm_rds.c index 4a414a3..c5a723a 100644 --- a/src/pi_fm_rds.c +++ b/src/pi_fm_rds.c @@ -156,7 +156,6 @@ // The deviation specifies how wide the signal is. Use 25.0 for WBFM // (broadcast radio) and about 3.5 for NBFM (walkie-talkie style radio) -#define DEVIATION 25.0 typedef struct { @@ -271,7 +270,7 @@ map_peripheral(uint32_t base, uint32_t len) #define DATA_SIZE 5000 -int tx(uint32_t carrier_freq, char *audio_file, uint16_t pi, char *ps, char *rt, float ppm, char *control_pipe) { +int tx(uint32_t carrier_freq, char *audio_file, uint16_t pi, char *ps, char *rt, float ppm, char *control_pipe, float deviation) { int i, fd, pid; char pagemap_fn[64]; @@ -492,7 +491,7 @@ int tx(uint32_t carrier_freq, char *audio_file, uint16_t pi, char *ps, char *rt, data_index = 0; } - float dval = data[data_index] * (DEVIATION / 10.); + float dval = data[data_index] * (deviation / 10.); data_index++; data_len--; @@ -521,6 +520,7 @@ int main(int argc, char **argv) { char *rt = "PiFmRds: live FM-RDS transmission from the RaspberryPi"; uint16_t pi = 0x1234; float ppm = 0; + float deviation = 25.0; // Parse command-line arguments @@ -553,14 +553,17 @@ int main(int argc, char **argv) { } else if(strcmp("-ctl", arg)==0 && param != NULL) { i++; control_pipe = param; + } else if(strcmp("-dev", arg)==0 && param != NULL) { + i++; + deviation = atof(param); } else { fatal("Unrecognised argument: %s\n" "Syntax: pi_fm_rds [-freq freq] [-audio file] [-ppm ppm_error] [-pi pi_code]\n" - " [-ps ps_text] [-rt rt_text] [-ctl control_pipe]\n", arg); + " [-ps ps_text] [-rt rt_text] [-ctl control_pipe] [-dev deviation]\n", arg); } } - int errcode = tx(carrier_freq, audio_file, pi, ps, rt, ppm, control_pipe); + int errcode = tx(carrier_freq, audio_file, pi, ps, rt, ppm, control_pipe, deviation); terminate(errcode); } From abfb6d945519ae7b42df28ab092c25d1ae637ee9 Mon Sep 17 00:00:00 2001 From: zeitbinder Date: Sat, 8 Nov 2014 23:34:26 +0100 Subject: [PATCH 2/3] Allow frequencies outside of the normal band. --- src/pi_fm_rds.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/pi_fm_rds.c b/src/pi_fm_rds.c index c5a723a..7e3be33 100644 --- a/src/pi_fm_rds.c +++ b/src/pi_fm_rds.c @@ -216,13 +216,23 @@ static void fatal(char *fmt, ...) { va_list ap; - + fprintf(stderr,"ERROR: "); va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); terminate(0); } +static void +warn(char *fmt, ...) +{ + va_list ap; + fprintf(stderr,"WARNING: "); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); +} + static uint32_t mem_virt_to_phys(void *virt) { @@ -537,7 +547,7 @@ int main(int argc, char **argv) { i++; carrier_freq = 1e6 * atof(param); if(carrier_freq < 87500000 || carrier_freq > 108000000) - fatal("Incorrect frequency specification. Must be in megahertz, of the form 107.9\n"); + warn("Frequency should be in megahertz between 87.5 and 108.0, but is %f MHz\n",atof(param)); } else if(strcmp("-pi", arg)==0 && param != NULL) { i++; pi = (uint16_t) strtol(param, NULL, 16); From ea98134abda738de47078e80556e0b1ea208e9c0 Mon Sep 17 00:00:00 2001 From: zeitbinder Date: Sat, 8 Nov 2014 23:40:15 +0100 Subject: [PATCH 3/3] updated changelog --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0e3e423..60bee72 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,7 @@ The samples are played by `pi_fm_rds.c` that is adapted from Richard Hirst's [Pi ## History +* 2014-11-08: support for non-standard frequencies and frequency deviations * 2014-11-01: support for toggling the Traffic Announcement (TA) flag at run-time * 2014-10-19: bugfix (cleanly stop the DMA engine when the specified file does not exist, or it's not possible to read from stdin) * 2014-08-04: bugfix (ppm now uses floats)