kopia lustrzana https://github.com/F5OEO/PiFmRds
Complete WAV generation
rodzic
4b39365588
commit
5e389fa49d
|
@ -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
|
||||
|
|
|
@ -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)))
|
||||
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sndfile.h>
|
||||
|
||||
#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 <out.wav> <text>\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<LENGTH; i++) {
|
||||
printf("%c", (((int)(buffer[i]*50))));
|
||||
count++;
|
||||
if(sf_write_float(outf, buffer, LENGTH) != LENGTH) {
|
||||
fprintf(stderr, "Error: writing to file %s.\n", argv[1]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if(sf_close(outf) ) {
|
||||
fprintf(stderr, "Error: closing file %s.\n", argv[1]);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
File diff suppressed because one or more lines are too long
Ładowanie…
Reference in New Issue