Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow non-standard frequencies and frequency deviations #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -166,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)
Expand Down
27 changes: 20 additions & 7 deletions src/pi_fm_rds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -217,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)
{
Expand Down Expand Up @@ -271,7 +280,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];

Expand Down Expand Up @@ -492,7 +501,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--;

Expand Down Expand Up @@ -521,6 +530,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
Expand All @@ -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);
Expand All @@ -553,14 +563,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);
}