preemphasis is now configurable from CLI

by adding -preemph [eu/us/{cutoff freq}] to your Pi FM parameters, you can now select the right preemphasis for your region
This commit is contained in:
Florian Schöck 2016-03-12 19:05:39 +01:00
parent 2cc5d96e62
commit d81db0e798
3 changed files with 19 additions and 12 deletions

View File

@ -66,11 +66,7 @@ float fir_buffer_stereo[FIR_SIZE] = {0};
int fir_index = 0;
int channels;
//3.185kHz for Europe, 2.120kHz for US
const float PREEMPHASIS_US = 2120;
const float PREEMPHASIS_EU = 3185;
float *last_buffer_val;
float preemphasis_corner_freq;
float preemphasis_prewarp;
float preemphasis_coefficient;
@ -88,7 +84,7 @@ float *alloc_empty_buffer(size_t length) {
}
int fm_mpx_open(char *filename, size_t len) {
int fm_mpx_open(char *filename, size_t len, float preemphasis_corner_freq) {
length = len;
if(filename != NULL) {
@ -128,10 +124,9 @@ int fm_mpx_open(char *filename, size_t len) {
last_buffer_val = (float*) malloc(sizeof(float)*channels);
for(int i=0;i<channels;i++) last_buffer_val[i] = 0;
preemphasis_corner_freq = PREEMPHASIS_EU;
preemphasis_prewarp = tan(PI*preemphasis_corner_freq/in_samplerate);
preemphasis_coefficient = (1.0 + (1.0 - preemphasis_prewarp)/(1.0 + preemphasis_prewarp))/2.0;
printf("Created preemphasis with with cutoff at %.1f Hz\n", preemphasis_corner_freq);
printf("Created preemphasis with cutoff at %.1f Hz\n", preemphasis_corner_freq);
// Create the low-pass FIR filter

View File

@ -21,6 +21,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
extern int fm_mpx_open(char *filename, size_t len);
extern int fm_mpx_open(char *filename, size_t len, float preemphasis_corner_freq);
extern int fm_mpx_get_samples(float *mpx_buffer);
extern int fm_mpx_close();

View File

@ -191,7 +191,6 @@
// (broadcast radio) and about 3.5 for NBFM (walkie-talkie style radio)
#define DEVIATION 25.0
typedef struct {
uint32_t info, src, dst, length,
stride, next, pad[2];
@ -311,7 +310,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 preemphasis_cutoff) {
// Catch all signals possible - it is vital we kill the DMA engine
// on process exit!
for (int i = 0; i < 64; i++) {
@ -446,7 +445,7 @@ int tx(uint32_t carrier_freq, char *audio_file, uint16_t pi, char *ps, char *rt,
int data_index = 0;
// Initialize the baseband generator
if(fm_mpx_open(audio_file, DATA_SIZE) < 0) return 1;
if(fm_mpx_open(audio_file, DATA_SIZE, preemphasis_cutoff) < 0) return 1;
// Initialize the RDS modulator
char myps[9] = {0};
@ -537,6 +536,8 @@ int tx(uint32_t carrier_freq, char *audio_file, uint16_t pi, char *ps, char *rt,
return 0;
}
#define PREEMPHASIS_EU 3185
#define PREEMPHASIS_US 2120
int main(int argc, char **argv) {
char *audio_file = NULL;
@ -546,6 +547,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 preemphasis_cutoff = PREEMPHASIS_US;
// Parse command-line arguments
@ -578,6 +580,16 @@ int main(int argc, char **argv) {
} else if(strcmp("-ctl", arg)==0 && param != NULL) {
i++;
control_pipe = param;
} else if(strcmp("-preemph", arg)==0 && param != NULL) {
i++;
if(strcmp("eu", param)==0) {
preemphasis_cutoff = PREEMPHASIS_EU;
} else if(strcmp("us", param)==0) {
preemphasis_cutoff = PREEMPHASIS_US;
}
else {
preemphasis_cutoff = atof(param);
}
} else {
fatal("Unrecognised argument: %s.\n"
"Syntax: pi_fm_rds [-freq freq] [-audio file] [-ppm ppm_error] [-pi pi_code]\n"
@ -585,7 +597,7 @@ int main(int argc, char **argv) {
}
}
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, preemphasis_cutoff);
terminate(errcode);
}