trying to make a option to disable preemphasis
This commit is contained in:
parent
66974f2c7e
commit
aecd242b97
|
|
@ -133,21 +133,20 @@ int fm_mpx_open(char *filename, size_t len, int raw, double preemphasis, int raw
|
||||||
|
|
||||||
// Create the low-pass FIR filter, with pre-emphasis
|
// Create the low-pass FIR filter, with pre-emphasis
|
||||||
double window, firlowpass, firpreemph , sincpos;
|
double window, firlowpass, firpreemph , sincpos;
|
||||||
|
double taup, deltap, bp, ap, a0, a1, b1;
|
||||||
|
if(preemphasis != 0) {
|
||||||
// IIR pre-emphasis filter
|
// IIR pre-emphasis filter
|
||||||
// Reference material: http://jontio.zapto.org/hda1/preempiir.pdf
|
// Reference material: http://jontio.zapto.org/hda1/preempiir.pdf
|
||||||
double tau=preemphasis;
|
double tau=preemphasis; //why? well im gonna listen to rule: "if it works dont touch it"
|
||||||
double delta=1/(2*PI*20000);//double delta=1.96e-6;
|
double delta=1/(2*PI*20000);//double delta=1.96e-6;
|
||||||
double taup, deltap, bp, ap, a0, a1, b1;
|
|
||||||
taup=1.0/(2.0*(in_samplerate*FIR_PHASES))/tan( 1.0/(2*tau*(in_samplerate*FIR_PHASES) ));
|
taup=1.0/(2.0*(in_samplerate*FIR_PHASES))/tan( 1.0/(2*tau*(in_samplerate*FIR_PHASES) ));
|
||||||
deltap=1.0/(2.0*(in_samplerate*FIR_PHASES))/tan( 1.0/(2*delta*(in_samplerate*FIR_PHASES) ));
|
deltap=1.0/(2.0*(in_samplerate*FIR_PHASES))/tan( 1.0/(2*delta*(in_samplerate*FIR_PHASES) ));
|
||||||
bp=sqrt( -taup*taup + sqrt(taup*taup*taup*taup + 8.0*taup*taup*deltap*deltap) ) / 2.0 ;
|
bp=sqrt( -taup*taup + sqrt(taup*taup*taup*taup + 8.0*taup*taup*deltap*deltap) ) / 2.0 ;
|
||||||
ap=sqrt( 2*bp*bp + taup*taup );
|
ap=sqrt( 2*bp*bp + taup*taup );
|
||||||
a0=( 2.0*ap + 1.0/(in_samplerate*FIR_PHASES) )/(2.0*bp + 1.0/(in_samplerate*FIR_PHASES) );
|
a0=( 2.0*ap + 1.0/(in_samplerate*FIR_PHASES) )/(2.0*bp + 1.0/(in_samplerate*FIR_PHASES) );
|
||||||
// a1=(-2.0*ap + 1/(in_samplerate*FIR_PHASES) )/(2.0*bp + 1/(in_samplerate*FIR_PHASES) ); //ORI
|
|
||||||
// b1=( 2.0*bp + 1/(in_samplerate*FIR_PHASES) )/(2.0*bp + 1/(in_samplerate*FIR_PHASES) ); //ORI
|
|
||||||
a1=(-2.0*ap + 1.0/(in_samplerate*FIR_PHASES) )/(2.0*bp + 1.0/(in_samplerate*FIR_PHASES) );
|
a1=(-2.0*ap + 1.0/(in_samplerate*FIR_PHASES) )/(2.0*bp + 1.0/(in_samplerate*FIR_PHASES) );
|
||||||
b1=( 2.0*bp - 1.0/(in_samplerate*FIR_PHASES) )/(2.0*bp + 1.0/(in_samplerate*FIR_PHASES) );
|
b1=( 2.0*bp - 1.0/(in_samplerate*FIR_PHASES) )/(2.0*bp + 1.0/(in_samplerate*FIR_PHASES) );
|
||||||
|
}
|
||||||
double x=0,y=0;
|
double x=0,y=0;
|
||||||
|
|
||||||
for(int i=0; i<FIR_TAPS; i++) {
|
for(int i=0; i<FIR_TAPS; i++) {
|
||||||
|
|
@ -156,12 +155,17 @@ int fm_mpx_open(char *filename, size_t len, int raw, double preemphasis, int raw
|
||||||
sincpos = (mi)-(((FIR_TAPS*FIR_PHASES)+1.0)/2.0); // offset by 0.5 so sincpos!=0 (causes NaN x/0 )
|
sincpos = (mi)-(((FIR_TAPS*FIR_PHASES)+1.0)/2.0); // offset by 0.5 so sincpos!=0 (causes NaN x/0 )
|
||||||
//printf("%d=%f \n",mi ,sincpos);
|
//printf("%d=%f \n",mi ,sincpos);
|
||||||
firlowpass = sin(2 * PI * cutoff_freq * sincpos / (in_samplerate*FIR_PHASES) ) / (PI * sincpos) ;
|
firlowpass = sin(2 * PI * cutoff_freq * sincpos / (in_samplerate*FIR_PHASES) ) / (PI * sincpos) ;
|
||||||
|
// Find the combined impulse response
|
||||||
y=a0*firlowpass + a1*x + b1*y ; // Find the combined impulse response
|
if(preemphasis != 0) {
|
||||||
|
y=a0*firlowpass + a1*x + b1*y;
|
||||||
|
} else {
|
||||||
|
y=firlowpass;
|
||||||
|
}
|
||||||
x=firlowpass; // of FIR low-pass and IIR pre-emphasis
|
x=firlowpass; // of FIR low-pass and IIR pre-emphasis
|
||||||
firpreemph=y; // y could be replaced by firpreemph but this
|
firpreemph=y; // y could be replaced by firpreemph but this
|
||||||
// matches the example in the reference material
|
// matches the example in the reference material
|
||||||
|
|
||||||
|
|
||||||
window = (.54 - .46 * cos(2*PI * (mi) / (double) FIR_TAPS*FIR_PHASES )) ; // Hamming window
|
window = (.54 - .46 * cos(2*PI * (mi) / (double) FIR_TAPS*FIR_PHASES )) ; // Hamming window
|
||||||
low_pass_fir[j][i] = firpreemph * window;
|
low_pass_fir[j][i] = firpreemph * window;
|
||||||
}
|
}
|
||||||
|
|
@ -325,7 +329,7 @@ int fm_mpx_get_samples(float *mpx_buffer, int drds, float compressor_decay, floa
|
||||||
if(1) {
|
if(1) {
|
||||||
mpx_buffer[i] += 4.05*(out_left+out_right) + // Stereo sum signal
|
mpx_buffer[i] += 4.05*(out_left+out_right) + // Stereo sum signal
|
||||||
4.05 * carrier_38[phase_38] * (out_left-out_right) + // Stereo difference signal
|
4.05 * carrier_38[phase_38] * (out_left-out_right) + // Stereo difference signal
|
||||||
pilot_volume*carrier_19[phase_19]; // Stereo pilot tone (doing 0.1 minus to balance it out, as by default its 0.9, but to make the 1.0 the normal value of the volume)
|
pilot_volume*carrier_19[phase_19]; // Stereo pilot tone
|
||||||
|
|
||||||
phase_19++;
|
phase_19++;
|
||||||
phase_38++;
|
phase_38++;
|
||||||
|
|
|
||||||
|
|
@ -274,7 +274,7 @@ int main(int argc, char **argv) {
|
||||||
double preemp = 50e-6; //eu
|
double preemp = 50e-6; //eu
|
||||||
int deviation = 75000;
|
int deviation = 75000;
|
||||||
int alternative_freq[100] = {};
|
int alternative_freq[100] = {};
|
||||||
float ppm = 0;
|
// float ppm = 0; this is useless as the ppm isnt used anywhere anyway
|
||||||
int bypassfreqrange = 0;
|
int bypassfreqrange = 0;
|
||||||
int ct = 1;
|
int ct = 1;
|
||||||
float cutofffreq = 15700;
|
float cutofffreq = 15700;
|
||||||
|
|
@ -300,9 +300,6 @@ int main(int argc, char **argv) {
|
||||||
} else if(strcmp("-rt", arg)==0 && param != NULL) {
|
} else if(strcmp("-rt", arg)==0 && param != NULL) {
|
||||||
i++;
|
i++;
|
||||||
rt = param;
|
rt = param;
|
||||||
} else if(strcmp("-ppm", arg)==0 && param != NULL) {
|
|
||||||
i++;
|
|
||||||
ppm = atof(param);
|
|
||||||
} else if(strcmp("-compressordecay", arg)==0 && param != NULL) {
|
} else if(strcmp("-compressordecay", arg)==0 && param != NULL) {
|
||||||
i++;
|
i++;
|
||||||
compressor_decay = atof(param);
|
compressor_decay = atof(param);
|
||||||
|
|
@ -326,12 +323,13 @@ int main(int argc, char **argv) {
|
||||||
pty = atoi(param);
|
pty = atoi(param);
|
||||||
} else if(strcmp("-gpiopin", arg)==0 && param != NULL) {
|
} else if(strcmp("-gpiopin", arg)==0 && param != NULL) {
|
||||||
i++;
|
i++;
|
||||||
int pinnum = atoi(param);
|
printf("GPIO pin setting disabled, mod librpitx and pifmsa (pifm simply advanced) for this");
|
||||||
if (!(pinnum == 4 || pinnum == 20 || pinnum == 32 || pinnum == 34 || pinnum == 6)) {
|
// int pinnum = atoi(param);
|
||||||
fatal("Invalid gpio pin, allowed: 4, 20, 32, 34, 6");
|
// if (!(pinnum == 4 || pinnum == 20 || pinnum == 32 || pinnum == 34 || pinnum == 6)) {
|
||||||
} else {
|
// fatal("Invalid gpio pin, allowed: 4, 20, 32, 34, 6");
|
||||||
gpiopin = pinnum;
|
// } else {
|
||||||
}
|
// gpiopin = pinnum;
|
||||||
|
// }
|
||||||
} else if(strcmp("-ta", arg)==0) {
|
} else if(strcmp("-ta", arg)==0) {
|
||||||
i++;
|
i++;
|
||||||
ta = 1;
|
ta = 1;
|
||||||
|
|
@ -391,7 +389,9 @@ int main(int argc, char **argv) {
|
||||||
if(strcmp("us", param)==0) {
|
if(strcmp("us", param)==0) {
|
||||||
preemp = 75e-6; //usa
|
preemp = 75e-6; //usa
|
||||||
} else if(strcmp("22", param)==0) {
|
} else if(strcmp("22", param)==0) {
|
||||||
preemp = 22e-6; //22
|
preemp = 22e-6; //22, why is it here? ask sdr++ creator
|
||||||
|
} else if(strcmp("off", param)==0) {
|
||||||
|
preemp = 0; //disabled
|
||||||
}
|
}
|
||||||
} else if(strcmp("-af", arg)==0 && param != NULL) {
|
} else if(strcmp("-af", arg)==0 && param != NULL) {
|
||||||
i++;
|
i++;
|
||||||
|
|
@ -402,7 +402,7 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fatal("Unrecognised argument: %s.\n"
|
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] [-audio file] [-pi pi_code]\n"
|
||||||
" [-ps ps_text] [-rt rt_text] [-ctl control_pipe] [-pty program_type] [-raw play raw audio from stdin] [-disablerds] [-af alt freq] [-preemphasis us] [-rawchannels when using the raw option you can change this] [-rawsamplerate same business] [-deviation the deviation, default is 75000, there are 2 predefined other cases: ukf (for old radios such as the UNITRA Jowita), nfm] [-tp] [-ta]\n", arg);
|
" [-ps ps_text] [-rt rt_text] [-ctl control_pipe] [-pty program_type] [-raw play raw audio from stdin] [-disablerds] [-af alt freq] [-preemphasis us] [-rawchannels when using the raw option you can change this] [-rawsamplerate same business] [-deviation the deviation, default is 75000, there are 2 predefined other cases: ukf (for old radios such as the UNITRA Jowita), nfm] [-tp] [-ta]\n", arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -416,6 +416,6 @@ int main(int argc, char **argv) {
|
||||||
int FifoSize=DATA_SIZE*2;
|
int FifoSize=DATA_SIZE*2;
|
||||||
//fmmod=new ngfmdmasync(carrier_freq,228000,14,FifoSize, false, gpiopin); //you can mod
|
//fmmod=new ngfmdmasync(carrier_freq,228000,14,FifoSize, false, gpiopin); //you can mod
|
||||||
fmmod=new ngfmdmasync(carrier_freq,228000,14,FifoSize, false);
|
fmmod=new ngfmdmasync(carrier_freq,228000,14,FifoSize, false);
|
||||||
int errcode = tx(carrier_freq, audio_file, pi, ps, rt, ppm, control_pipe, pty, alternative_freq, raw, drds, preemp, power, rawSampleRate, rawChannels, deviation, ta, tp, cutofffreq, gain, compressor_decay, compressor_attack, compressor_max_gain_recip, enable_compressor, ct, rds_volume, pilot_volume);
|
int errcode = tx(carrier_freq, audio_file, pi, ps, rt, control_pipe, pty, alternative_freq, raw, drds, preemp, power, rawSampleRate, rawChannels, deviation, ta, tp, cutofffreq, gain, compressor_decay, compressor_attack, compressor_max_gain_recip, enable_compressor, ct, rds_volume, pilot_volume);
|
||||||
terminate(errcode);
|
terminate(errcode);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue