diff --git a/src/Makefile b/src/Makefile
index 7900950..f2292a0 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -5,7 +5,7 @@ app: rds.o waveforms.o pi_fm_rds.o
$(CC) -o pi_fm_rds rds.o waveforms.o pi_fm_rds.o -lm
rds_wav: rds.o waveforms.o rds_wav.o
- $(CC) -o rds_wav rds_wav.o rds.o waveforms.o
+ $(CC) -o rds_wav rds_wav.o rds.o waveforms.o -lsndfile
rds.o: rds.c waveforms.h
$(CC) $(CFLAGS) rds.c
diff --git a/src/generate_waveforms.py b/src/generate_waveforms.py
index 9a38816..0b4d318 100755
--- a/src/generate_waveforms.py
+++ b/src/generate_waveforms.py
@@ -24,12 +24,6 @@ header = u"""
outc.write(header)
outh.write(header)
-def format_number(x):
- if abs(x) < 1e-10:
- return u"0"
- else:
- return unicode(x)
-
def generate_bit_in_context(pattern, name):
offset = 240
l = 96
@@ -44,7 +38,9 @@ def generate_bit_in_context(pattern, name):
outc.write(u"float waveform_{name}[] = {{{values}}};\n\n".format(
name = name,
- values = u", ".join(map(format_number, out))))
+ values = u", ".join(map(unicode, out/3.))))
+ # note: need to limit the amplitude so as not to saturate when the biphase
+ # waveforms are summed
outh.write(u"extern float waveform_{name}[{size}];\n".format(name=name, size=len(out)))
diff --git a/src/rds_wav.c b/src/rds_wav.c
index 1996a41..3597864 100644
--- a/src/rds_wav.c
+++ b/src/rds_wav.c
@@ -1,24 +1,76 @@
+/*
+ PiFmRds - FM/RDS transmitter for the Raspberry Pi
+ Copyright (C) 2014 Christophe Jacquet, F8FTK
+
+ See https://github.com/ChristopheJacquet/PiFmRds
+
+ rds_wav.c is a test program that writes a RDS baseband signal to a WAV
+ file. It requires libsndfile.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+*/
+
+
#include
+#include
+#include
#include "rds.h"
-#define LENGTH 100000
+#define LENGTH 114000
/* Simple test program */
int main(int argc, char **argv) {
- set_rds_params(0x1234, "Hello! World of the RaspberryPi!");
+ if(argc < 3) {
+ fprintf(stderr, "Error: missing argument.\n");
+ fprintf(stderr, "Syntax: rds_wav \n");
+ return EXIT_FAILURE;
+ }
+
+ set_rds_params(0x1234, argv[2]);
float buffer[LENGTH];
- int count = 0;
- for(int j=0; j<20; j++) {
+ // Set the format of the output file
+ SNDFILE *outf;
+ SF_INFO sfinfo;
+ sfinfo.frames = LENGTH;
+ sfinfo.samplerate = 228000;
+ sfinfo.channels = 1;
+ sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
+ sfinfo.sections = 1;
+ sfinfo.seekable = 0;
+
+ // Open the output file
+ if (! (outf = sf_open(argv[1], SFM_WRITE, &sfinfo))) {
+ fprintf(stderr, "Error: could not open output file %s.\n", argv[1]) ;
+ return EXIT_FAILURE;
+ }
+
+
+ for(int j=0; j<40; j++) {
get_rds_samples(buffer, LENGTH);
- fprintf(stderr, "Iteration %d count=%d\n", j, count);
-
- for(int i=0; i