From 51dc59fb12f9d82a0d747c334d4785a50b057c52 Mon Sep 17 00:00:00 2001 From: Inglebard Date: Sat, 19 Jul 2014 14:41:00 +0200 Subject: [PATCH 1/5] Update pi_fm_rds.c Add volume option --- src/pi_fm_rds.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/pi_fm_rds.c b/src/pi_fm_rds.c index 29653f1..afe4ba5 100644 --- a/src/pi_fm_rds.c +++ b/src/pi_fm_rds.c @@ -269,7 +269,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, int16_t ppm, char *control_pipe) { +int tx(uint32_t carrier_freq, uint32_t volume, char *audio_file, uint16_t pi, char *ps, char *rt, int16_t ppm, char *control_pipe) { int i, fd, pid; char pagemap_fn[64]; @@ -490,7 +490,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.) * volume; data_index++; data_len--; @@ -517,6 +517,7 @@ int main(int argc, char **argv) { char *audio_file = NULL; char *control_pipe = NULL; uint32_t carrier_freq = 107900000; + uint32_t volume = 1; char *ps = NULL; char *rt = "PiFmRds: live FM-RDS transmission from the RaspberryPi"; uint16_t pi = 0x1234; @@ -538,6 +539,9 @@ int main(int argc, char **argv) { 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"); + } else if(strcmp("-vol", arg)==0 && param != NULL) { + i++; + volume = atof(param); } else if(strcmp("-pi", arg)==0 && param != NULL) { i++; pi = (uint16_t) strtol(param, NULL, 16); @@ -555,10 +559,10 @@ int main(int argc, char **argv) { control_pipe = param; } else { fatal("Unrecognised argument: %s\n" - "Syntax: pi_fm_rds [-freq freq] [-audio file] [-ppm ppm_error] [-pi pi_code]\n" + "Syntax: pi_fm_rds [-freq freq] [-vol volume] [-audio file] [-ppm ppm_error] [-pi pi_code]\n" " [-ps ps_text] [-rt rt_text] [-ctl control_pipe]\n", arg); } } - tx(carrier_freq, audio_file, pi, ps, rt, ppm, control_pipe); -} \ No newline at end of file + tx(carrier_freq, volume, audio_file, pi, ps, rt, ppm, control_pipe); +} From 0ce348552beb007fc69820298310bfd40583439c Mon Sep 17 00:00:00 2001 From: Inglebard Date: Sat, 19 Jul 2014 14:50:15 +0200 Subject: [PATCH 2/5] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 601a14b..071f964 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ pi_fm_rds [-freq freq] [-audio file] [-ppm ppm_error] [-pi pi_code] [-ps ps_text All arguments are optional: * `-freq` specifies the carrier frequency (in MHz). Example: `-freq 107.9`. +* `-vol` specifies the volume. Example: `-vol 4`. Default : 1 * `-audio` specifies an audio file to play as audio. The sample rate does not matter: Pi-FM-RDS will resample and filter it. If a stereo file is provided, Pi-FM-RDS will produce an FM-Stereo signal. Example: `-audio sound.wav`. The supported formats depend on `libsndfile`. This includes WAV and Ogg/Vorbis (among others) but not MP3. Specify `-` as the file name to read audio data on standard input (useful for piping audio into Pi-FM-RDS, see below). * `-pi` specifies the PI-code of the RDS broadcast. 4 hexadecimal digits. Example: `-pi FFFF`. * `-ps` specifies the station name (Program Service name, PS) of the RDS broadcast. Limit: 8 characters. Example: `-ps RASP-PI`. From a3c235d6f84f154e754ba3330d25ae40ebe21cb1 Mon Sep 17 00:00:00 2001 From: David RICQ Date: Sat, 19 Jul 2014 19:25:04 +0200 Subject: [PATCH 3/5] Update pi_fm_rds.c --- src/pi_fm_rds.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pi_fm_rds.c b/src/pi_fm_rds.c index afe4ba5..254efb9 100644 --- a/src/pi_fm_rds.c +++ b/src/pi_fm_rds.c @@ -490,7 +490,7 @@ int tx(uint32_t carrier_freq, uint32_t volume, char *audio_file, uint16_t pi, ch data_index = 0; } - float dval = data[data_index] * (DEVIATION / 10.) * volume; + float dval = data[data_index] * (DEVIATION / 10.) * (volume/100); data_index++; data_len--; @@ -517,7 +517,7 @@ int main(int argc, char **argv) { char *audio_file = NULL; char *control_pipe = NULL; uint32_t carrier_freq = 107900000; - uint32_t volume = 1; + uint32_t volume = 100; char *ps = NULL; char *rt = "PiFmRds: live FM-RDS transmission from the RaspberryPi"; uint16_t pi = 0x1234; From f2df2b10b8728938849d6ed0b80130944fd6fb80 Mon Sep 17 00:00:00 2001 From: David RICQ Date: Sat, 19 Jul 2014 19:25:44 +0200 Subject: [PATCH 4/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 071f964..d59f426 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ pi_fm_rds [-freq freq] [-audio file] [-ppm ppm_error] [-pi pi_code] [-ps ps_text All arguments are optional: * `-freq` specifies the carrier frequency (in MHz). Example: `-freq 107.9`. -* `-vol` specifies the volume. Example: `-vol 4`. Default : 1 +* `-vol` specifies the volume in percent. Example: `-vol 200`. Default : 100 * `-audio` specifies an audio file to play as audio. The sample rate does not matter: Pi-FM-RDS will resample and filter it. If a stereo file is provided, Pi-FM-RDS will produce an FM-Stereo signal. Example: `-audio sound.wav`. The supported formats depend on `libsndfile`. This includes WAV and Ogg/Vorbis (among others) but not MP3. Specify `-` as the file name to read audio data on standard input (useful for piping audio into Pi-FM-RDS, see below). * `-pi` specifies the PI-code of the RDS broadcast. 4 hexadecimal digits. Example: `-pi FFFF`. * `-ps` specifies the station name (Program Service name, PS) of the RDS broadcast. Limit: 8 characters. Example: `-ps RASP-PI`. From a2038ef55655709335d8f8f5649db9a2fd14eb03 Mon Sep 17 00:00:00 2001 From: David RICQ Date: Sat, 19 Jul 2014 19:32:06 +0200 Subject: [PATCH 5/5] Update pi_fm_rds.c --- src/pi_fm_rds.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pi_fm_rds.c b/src/pi_fm_rds.c index 254efb9..02c4dc9 100644 --- a/src/pi_fm_rds.c +++ b/src/pi_fm_rds.c @@ -269,7 +269,7 @@ map_peripheral(uint32_t base, uint32_t len) #define DATA_SIZE 5000 -int tx(uint32_t carrier_freq, uint32_t volume, char *audio_file, uint16_t pi, char *ps, char *rt, int16_t ppm, char *control_pipe) { +int tx(uint32_t carrier_freq, float volume, char *audio_file, uint16_t pi, char *ps, char *rt, int16_t ppm, char *control_pipe) { int i, fd, pid; char pagemap_fn[64]; @@ -517,7 +517,7 @@ int main(int argc, char **argv) { char *audio_file = NULL; char *control_pipe = NULL; uint32_t carrier_freq = 107900000; - uint32_t volume = 100; + float volume = 100; char *ps = NULL; char *rt = "PiFmRds: live FM-RDS transmission from the RaspberryPi"; uint16_t pi = 0x1234; @@ -542,6 +542,8 @@ int main(int argc, char **argv) { } else if(strcmp("-vol", arg)==0 && param != NULL) { i++; volume = atof(param); + if(volume < 0) + fatal("Incorrect volume specification. Must be positive\n"); } else if(strcmp("-pi", arg)==0 && param != NULL) { i++; pi = (uint16_t) strtol(param, NULL, 16);