From 4cc250cfe2fbaee9e4a9b9f1ef18251c25480898 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Sat, 16 Aug 2014 22:31:22 +0000 Subject: [PATCH] Codec 2 optimised so that one less FFT is rqd, fdmdv C and Octave optimised so freq est ffts are only performed when reqd. Codec 2 working OK, tfddmdv modem tests pass git-svn-id: https://svn.code.sf.net/p/freetel/code@1806 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/octave/fdmdv.m | 42 +++++---- codec2-dev/octave/pl2.m | 3 + codec2-dev/octave/tfdmdv.m | 2 +- codec2-dev/src/c2sim.c | 17 ++-- codec2-dev/src/codec2.c | 36 ++++---- codec2-dev/src/fdmdv.c | 69 ++++++++------ codec2-dev/src/fdmdv_internal.h | 4 +- codec2-dev/src/interp.c | 4 +- codec2-dev/src/phase.c | 154 +++++++++++--------------------- codec2-dev/src/phase.h | 6 +- codec2-dev/src/quantise.c | 20 +++-- codec2-dev/src/quantise.h | 3 +- codec2-dev/unittest/tfdmdv.c | 4 +- codec2-dev/unittest/tlspsens.c | 3 +- 14 files changed, 177 insertions(+), 190 deletions(-) diff --git a/codec2-dev/octave/fdmdv.m b/codec2-dev/octave/fdmdv.m index 0f650eec..c6aaf866 100644 --- a/codec2-dev/octave/fdmdv.m +++ b/codec2-dev/octave/fdmdv.m @@ -391,7 +391,7 @@ endfunction % LPF and peak pick part of freq est, put in a function as we call it twice -function [foff imax pilot_lpf_out S] = lpf_peak_pick(pilot_baseband, pilot_lpf, nin) +function [foff imax pilot_lpf_out S] = lpf_peak_pick(pilot_baseband, pilot_lpf, nin, do_fft) global M; global Npilotlpf; global Npilotbaseband; @@ -409,24 +409,30 @@ function [foff imax pilot_lpf_out S] = lpf_peak_pick(pilot_baseband, pilot_lpf, k++; end - % decimate to improve DFT resolution, window and DFT + imax = 0; + foff = 0; + S = zeros(1, Mpilotfft); - Mpilot = Fs/(2*200); % calc decimation rate given new sample rate is twice LPF freq - h = hanning(Npilotlpf); - s = pilot_lpf(1:Mpilot:Npilotlpf) .* h(1:Mpilot:Npilotlpf)'; - s = [s zeros(1,Mpilotfft-Npilotlpf/Mpilot)]; - S = fft(s, Mpilotfft); + if do_fft + % decimate to improve DFT resolution, window and DFT + + Mpilot = Fs/(2*200); % calc decimation rate given new sample rate is twice LPF freq + h = hanning(Npilotlpf); + s = pilot_lpf(1:Mpilot:Npilotlpf) .* h(1:Mpilot:Npilotlpf)'; + s = [s zeros(1,Mpilotfft-Npilotlpf/Mpilot)]; + S = fft(s, Mpilotfft); - % peak pick and convert to Hz + % peak pick and convert to Hz - [imax ix] = max(abs(S)); - r = 2*200/Mpilotfft; % maps FFT bin to frequency in Hz + [imax ix] = max(abs(S)); + r = 2*200/Mpilotfft; % maps FFT bin to frequency in Hz - if ix > Mpilotfft/2 - foff = (ix - Mpilotfft - 1)*r; - else - foff = (ix - 1)*r; - endif + if ix > Mpilotfft/2 + foff = (ix - Mpilotfft - 1)*r; + else + foff = (ix - 1)*r; + endif + end pilot_lpf_out = pilot_lpf; @@ -436,7 +442,7 @@ endfunction % Estimate frequency offset of FDM signal using BPSK pilot. This is quite % sensitive to pilot tone level wrt other carriers -function [foff S1 S2] = rx_est_freq_offset(rx_fdm, pilot, pilot_prev, nin) +function [foff S1 S2] = rx_est_freq_offset(rx_fdm, pilot, pilot_prev, nin, do_fft) global M; global Npilotbaseband; global pilot_baseband1; @@ -457,8 +463,8 @@ function [foff S1 S2] = rx_est_freq_offset(rx_fdm, pilot, pilot_prev, nin) pilot_baseband2(Npilotbaseband-nin+i) = rx_fdm(i) * conj(pilot_prev(i)); end - [foff1 max1 pilot_lpf1 S1] = lpf_peak_pick(pilot_baseband1, pilot_lpf1, nin); - [foff2 max2 pilot_lpf2 S2] = lpf_peak_pick(pilot_baseband2, pilot_lpf2, nin); + [foff1 max1 pilot_lpf1 S1] = lpf_peak_pick(pilot_baseband1, pilot_lpf1, nin, do_fft); + [foff2 max2 pilot_lpf2 S2] = lpf_peak_pick(pilot_baseband2, pilot_lpf2, nin, do_fft); if max1 > max2 foff = foff1; diff --git a/codec2-dev/octave/pl2.m b/codec2-dev/octave/pl2.m index 17671c08..c7af10cc 100644 --- a/codec2-dev/octave/pl2.m +++ b/codec2-dev/octave/pl2.m @@ -37,5 +37,8 @@ function pl2(samname1, samname2, start_sam, end_sam, offset) figure(2) plot(s1(st1:en1)-s2(st2:en2)); + f=fopen("diff.raw","wb"); + d = s1(st1:en1)-s2(st2:en2); + fwrite(f,d,"short"); endfunction diff --git a/codec2-dev/octave/tfdmdv.m b/codec2-dev/octave/tfdmdv.m index e570416b..1ea15a46 100644 --- a/codec2-dev/octave/tfdmdv.m +++ b/codec2-dev/octave/tfdmdv.m @@ -104,7 +104,7 @@ for f=1:frames fbb_phase_rx /= mag; [pilot prev_pilot pilot_lut_index prev_pilot_lut_index] = get_pilot(pilot_lut_index, prev_pilot_lut_index, nin); - [foff_coarse S1 S2] = rx_est_freq_offset(rx_fdm, pilot, prev_pilot, nin); + [foff_coarse S1 S2] = rx_est_freq_offset(rx_fdm, pilot, prev_pilot, nin, !sync); %sync = 0; % when debugging good idea to uncomment this to "open loop" diff --git a/codec2-dev/src/c2sim.c b/codec2-dev/src/c2sim.c index 20993204..dc258ea1 100644 --- a/codec2-dev/src/c2sim.c +++ b/codec2-dev/src/c2sim.c @@ -171,7 +171,8 @@ int main(int argc, char *argv[]) { NULL, no_argument, NULL, 0 } }; int num_opts=sizeof(long_options)/sizeof(struct option); - + COMP Aw[FFT_ENC]; + for(i=0; ifft_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 0, 0, - c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma); + c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, &Aw[i][0]); apply_lpc_correction(&model[i]); } /* synthesise ------------------------------------------------*/ for(i=0; i<2; i++) - synthesise_one_frame(c2, &speech[N*i], &model[i], &ak[i][0]); + synthesise_one_frame(c2, &speech[N*i], &model[i], &Aw[i][0]); /* update memories for next frame ----------------------------*/ @@ -516,6 +517,7 @@ void codec2_decode_2400(struct CODEC2 *c2, short speech[], const unsigned char * float ak[2][LPC_ORD+1]; int i,j; unsigned int nbit = 0; + COMP Aw[2][FFT_ENC]; assert(c2 != NULL); @@ -558,14 +560,14 @@ void codec2_decode_2400(struct CODEC2 *c2, short speech[], const unsigned char * for(i=0; i<2; i++) { lsp_to_lpc(&lsps[i][0], &ak[i][0], LPC_ORD); aks_to_M2(c2->fft_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 0, 0, - c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma); + c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, &Aw[i][0]); apply_lpc_correction(&model[i]); } /* synthesise ------------------------------------------------*/ for(i=0; i<2; i++) - synthesise_one_frame(c2, &speech[N*i], &model[i], &ak[i][0]); + synthesise_one_frame(c2, &speech[N*i], &model[i], &Aw[i][0]); /* update memories for next frame ----------------------------*/ @@ -685,6 +687,7 @@ void codec2_decode_1600(struct CODEC2 *c2, short speech[], const unsigned char * int i,j; unsigned int nbit = 0; float weight; + COMP Aw[4][FFT_ENC]; assert(c2 != NULL); @@ -745,14 +748,14 @@ void codec2_decode_1600(struct CODEC2 *c2, short speech[], const unsigned char * for(i=0; i<4; i++) { lsp_to_lpc(&lsps[i][0], &ak[i][0], LPC_ORD); aks_to_M2(c2->fft_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 0, 0, - c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma); + c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, &Aw[i][0]); apply_lpc_correction(&model[i]); } /* synthesise ------------------------------------------------*/ for(i=0; i<4; i++) - synthesise_one_frame(c2, &speech[N*i], &model[i], &ak[i][0]); + synthesise_one_frame(c2, &speech[N*i], &model[i], &Aw[i][0]); /* update memories for next frame ----------------------------*/ @@ -866,6 +869,7 @@ void codec2_decode_1400(struct CODEC2 *c2, short speech[], const unsigned char * int i,j; unsigned int nbit = 0; float weight; + COMP Aw[4][FFT_ENC]; assert(c2 != NULL); @@ -918,14 +922,14 @@ void codec2_decode_1400(struct CODEC2 *c2, short speech[], const unsigned char * for(i=0; i<4; i++) { lsp_to_lpc(&lsps[i][0], &ak[i][0], LPC_ORD); aks_to_M2(c2->fft_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 0, 0, - c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma); + c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, &Aw[i][0]); apply_lpc_correction(&model[i]); } /* synthesise ------------------------------------------------*/ for(i=0; i<4; i++) - synthesise_one_frame(c2, &speech[N*i], &model[i], &ak[i][0]); + synthesise_one_frame(c2, &speech[N*i], &model[i], &Aw[i][0]); /* update memories for next frame ----------------------------*/ @@ -1046,6 +1050,7 @@ void codec2_decode_1300(struct CODEC2 *c2, short speech[], const unsigned char * int i,j; unsigned int nbit = 0; float weight; + COMP Aw[4][FFT_ENC]; PROFILE_VAR(recover_start); assert(c2 != NULL); @@ -1104,7 +1109,7 @@ void codec2_decode_1300(struct CODEC2 *c2, short speech[], const unsigned char * for(i=0; i<4; i++) { lsp_to_lpc(&lsps[i][0], &ak[i][0], LPC_ORD); aks_to_M2(c2->fft_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 0, 0, - c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma); + c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, &Aw[i][0]); apply_lpc_correction(&model[i]); } PROFILE_SAMPLE_AND_LOG2(recover_start, " recover"); @@ -1116,7 +1121,7 @@ void codec2_decode_1300(struct CODEC2 *c2, short speech[], const unsigned char * /* synthesise ------------------------------------------------*/ for(i=0; i<4; i++) - synthesise_one_frame(c2, &speech[N*i], &model[i], &ak[i][0]); + synthesise_one_frame(c2, &speech[N*i], &model[i], &Aw[i][0]); /* update memories for next frame ----------------------------*/ @@ -1235,6 +1240,7 @@ void codec2_decode_1200(struct CODEC2 *c2, short speech[], const unsigned char * int i,j; unsigned int nbit = 0; float weight; + COMP Aw[4][FFT_ENC]; assert(c2 != NULL); @@ -1287,14 +1293,14 @@ void codec2_decode_1200(struct CODEC2 *c2, short speech[], const unsigned char * for(i=0; i<4; i++) { lsp_to_lpc(&lsps[i][0], &ak[i][0], LPC_ORD); aks_to_M2(c2->fft_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 0, 0, - c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma); + c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, &Aw[i][0]); apply_lpc_correction(&model[i]); } /* synthesise ------------------------------------------------*/ for(i=0; i<4; i++) - synthesise_one_frame(c2, &speech[N*i], &model[i], &ak[i][0]); + synthesise_one_frame(c2, &speech[N*i], &model[i], &Aw[i][0]); /* update memories for next frame ----------------------------*/ @@ -1315,7 +1321,7 @@ void codec2_decode_1200(struct CODEC2 *c2, short speech[], const unsigned char * \*---------------------------------------------------------------------------*/ -void synthesise_one_frame(struct CODEC2 *c2, short speech[], MODEL *model, float ak[]) +void synthesise_one_frame(struct CODEC2 *c2, short speech[], MODEL *model, COMP Aw[]) { int i; PROFILE_VAR(phase_start, pf_start, synth_start); @@ -1326,7 +1332,7 @@ void synthesise_one_frame(struct CODEC2 *c2, short speech[], MODEL *model, float PROFILE_SAMPLE(phase_start); - phase_synth_zero_order(c2->fft_fwd_cfg, model, ak, &c2->ex_phase, LPC_ORD); + phase_synth_zero_order(c2->fft_fwd_cfg, model, &c2->ex_phase, Aw); PROFILE_SAMPLE_AND_LOG(pf_start, phase_start, " phase_synth"); diff --git a/codec2-dev/src/fdmdv.c b/codec2-dev/src/fdmdv.c index 3090aa28..238abd3f 100644 --- a/codec2-dev/src/fdmdv.c +++ b/codec2-dev/src/fdmdv.c @@ -756,7 +756,8 @@ void generate_pilot_lut(COMP pilot_lut[], COMP *pilot_freq) \*---------------------------------------------------------------------------*/ void lpf_peak_pick(float *foff, float *max, COMP pilot_baseband[], - COMP pilot_lpf[], kiss_fft_cfg fft_pilot_cfg, COMP S[], int nin) + COMP pilot_lpf[], kiss_fft_cfg fft_pilot_cfg, COMP S[], int nin, + int do_fft) { int i,j,k; int mpilot; @@ -775,35 +776,49 @@ void lpf_peak_pick(float *foff, float *max, COMP pilot_baseband[], pilot_lpf[i] = cadd(pilot_lpf[i], fcmult(pilot_coeff[k], pilot_baseband[j-NPILOTCOEFF+1+k])); } - /* decimate to improve DFT resolution, window and DFT */ + /* We only need to do FFTs if we are out of sync. Making them optional saves CPU in sync, which is when + we need to run the codec */ - mpilot = FS/(2*200); /* calc decimation rate given new sample rate is twice LPF freq */ + imax = 0.0; + *foff = 0.0; for(i=0; i imax) { - imax = mag; - ix = i; - } - } - r = 2.0*200.0/MPILOTFFT; /* maps FFT bin to frequency in Hz */ + kiss_fft(fft_pilot_cfg, (kiss_fft_cpx *)s, (kiss_fft_cpx *)S); + + /* peak pick and convert to Hz */ + + imax = 0.0; + ix = 0; + for(i=0; i imax) { + imax = mag; + ix = i; + } + } + r = 2.0*200.0/MPILOTFFT; /* maps FFT bin to frequency in Hz */ - if (ix >= MPILOTFFT/2) - *foff = (ix - MPILOTFFT)*r; - else - *foff = (ix)*r; + if (ix >= MPILOTFFT/2) + *foff = (ix - MPILOTFFT)*r; + else + *foff = (ix)*r; + } + *max = imax; } @@ -820,7 +835,7 @@ void lpf_peak_pick(float *foff, float *max, COMP pilot_baseband[], \*---------------------------------------------------------------------------*/ -float rx_est_freq_offset(struct FDMDV *f, COMP rx_fdm[], int nin) +float rx_est_freq_offset(struct FDMDV *f, COMP rx_fdm[], int nin, int do_fft) { int i,j; COMP pilot[M+M/P]; @@ -862,8 +877,8 @@ float rx_est_freq_offset(struct FDMDV *f, COMP rx_fdm[], int nin) f->pilot_baseband2[j] = cmult(rx_fdm[i], cconj(prev_pilot[i])); } - lpf_peak_pick(&foff1, &max1, f->pilot_baseband1, f->pilot_lpf1, f->fft_pilot_cfg, f->S1, nin); - lpf_peak_pick(&foff2, &max2, f->pilot_baseband2, f->pilot_lpf2, f->fft_pilot_cfg, f->S2, nin); + lpf_peak_pick(&foff1, &max1, f->pilot_baseband1, f->pilot_lpf1, f->fft_pilot_cfg, f->S1, nin, do_fft); + lpf_peak_pick(&foff2, &max2, f->pilot_baseband2, f->pilot_lpf2, f->fft_pilot_cfg, f->S2, nin, do_fft); if (max1 > max2) foff = foff1; @@ -1577,7 +1592,7 @@ void fdmdv_demod(struct FDMDV *fdmdv, int rx_bits[], /* freq offset estimation and correction */ PROFILE_SAMPLE(demod_start); - foff_coarse = rx_est_freq_offset(fdmdv, rx_fdm_bb, *nin); + foff_coarse = rx_est_freq_offset(fdmdv, rx_fdm_bb, *nin, !fdmdv->sync); PROFILE_SAMPLE_AND_LOG(fdmdv_freq_shift_start, demod_start, " rx_est_freq_offset"); if (fdmdv->sync == 0) diff --git a/codec2-dev/src/fdmdv_internal.h b/codec2-dev/src/fdmdv_internal.h index bf1c3a17..97011e8d 100644 --- a/codec2-dev/src/fdmdv_internal.h +++ b/codec2-dev/src/fdmdv_internal.h @@ -172,8 +172,8 @@ void tx_filter_and_upconvert(COMP tx_fdm[], int Nc, COMP tx_symbols[], COMP phase_tx[], COMP freq[], COMP *fbb_phase, COMP fbb_rect); void generate_pilot_fdm(COMP *pilot_fdm, int *bit, float *symbol, float *filter_mem, COMP *phase, COMP *freq); void generate_pilot_lut(COMP pilot_lut[], COMP *pilot_freq); -float rx_est_freq_offset(struct FDMDV *f, COMP rx_fdm[], int nin); -void lpf_peak_pick(float *foff, float *max, COMP pilot_baseband[], COMP pilot_lpf[], kiss_fft_cfg fft_pilot_cfg, COMP S[], int nin); +float rx_est_freq_offset(struct FDMDV *f, COMP rx_fdm[], int nin, int do_fft); +void lpf_peak_pick(float *foff, float *max, COMP pilot_baseband[], COMP pilot_lpf[], kiss_fft_cfg fft_pilot_cfg, COMP S[], int nin, int do_fft); void fdm_downconvert(COMP rx_baseband[NC+1][M+M/P], int Nc, COMP rx_fdm[], COMP phase_rx[], COMP freq[], int nin); void rxdec_filter(COMP rx_fdm_filter[], COMP rx_fdm[], COMP rxdec_lpf_mem[], int nin); void rx_filter(COMP rx_filt[NC+1][P+1], int Nc, COMP rx_baseband[NC+1][M+M/P], COMP rx_filter_memory[NC+1][NFILTER], int nin); diff --git a/codec2-dev/src/interp.c b/codec2-dev/src/interp.c index e712a46e..d2f1e7bb 100644 --- a/codec2-dev/src/interp.c +++ b/codec2-dev/src/interp.c @@ -129,6 +129,8 @@ float sample_log_amp(MODEL *model, float w) return log_amp; } +#ifdef NOT_NEEDED + /*---------------------------------------------------------------------------*\ FUNCTION....: interp_lsp() @@ -204,7 +206,7 @@ void interpolate_lsp( aks_to_M2(fft_fwd_cfg, ak_interp, LPC_ORD, interp, e, &snr, 0, 0, 1, 1, LPCPF_BETA, LPCPF_GAMMA); //printf(" interp: ak[1]: %f A[1] %f\n", ak_interp[1], interp->A[1]); } - +#endif /*---------------------------------------------------------------------------*\ diff --git a/codec2-dev/src/phase.c b/codec2-dev/src/phase.c index e1476862..08a2cf41 100644 --- a/codec2-dev/src/phase.c +++ b/codec2-dev/src/phase.c @@ -37,66 +37,6 @@ #include #include -/*---------------------------------------------------------------------------*\ - - aks_to_H() - - Samples the complex LPC synthesis filter spectrum at the harmonic - frequencies. - -\*---------------------------------------------------------------------------*/ - -void aks_to_H( - kiss_fft_cfg fft_fwd_cfg, - MODEL *model, /* model parameters */ - float aks[], /* LPC's */ - float G, /* energy term */ - COMP H[], /* complex LPC spectral samples */ - int order -) -{ - COMP pw[FFT_ENC]; /* power spectrum (input) */ - COMP Pw[FFT_ENC]; /* power spectrum (output) */ - int i,m; /* loop variables */ - int am,bm; /* limits of current band */ - float r; /* no. rads/bin */ - float Em; /* energy in band */ - float Am; /* spectral amplitude sample */ - int b; /* centre bin of harmonic */ - float phi_; /* phase of LPC spectra */ - - r = TWO_PI/(FFT_ENC); - - /* Determine DFT of A(exp(jw)) ------------------------------------------*/ - - for(i=0; iL; m++) { - am = (int)((m - 0.5)*model->Wo/r + 0.5); - bm = (int)((m + 0.5)*model->Wo/r + 0.5); - b = (int)(m*model->Wo/r + 0.5); - - Em = 0.0; - for(i=am; iL; m++) { + b = (int)(m*model->Wo/r + 0.5); + phi_ = -atan2f(A[b].imag, A[b].real); + H[m].real = cosf(phi_); + H[m].imag = sinf(phi_); + } + + /* + Update excitation fundamental phase track, this sets the position + of each pitch pulse during voiced speech. After much experiment + I found that using just this frame's Wo improved quality for UV + sounds compared to interpolating two frames Wo like this: - ex_phase[0] += (*prev_Wo+model->Wo)*N/2; - */ + ex_phase[0] += (*prev_Wo+model->Wo)*N/2; + */ - ex_phase[0] += (model->Wo)*N; - ex_phase[0] -= TWO_PI*floorf(ex_phase[0]/TWO_PI + 0.5); + ex_phase[0] += (model->Wo)*N; + ex_phase[0] -= TWO_PI*floorf(ex_phase[0]/TWO_PI + 0.5); - for(m=1; m<=model->L; m++) { + for(m=1; m<=model->L; m++) { - /* generate excitation */ + /* generate excitation */ - if (model->voiced) { + if (model->voiced) { - Ex[m].real = cosf(ex_phase[0]*m); - Ex[m].imag = sinf(ex_phase[0]*m); - } - else { - - /* When a few samples were tested I found that LPC filter - phase is not needed in the unvoiced case, but no harm in - keeping it. - */ - float phi = TWO_PI*(float)codec2_rand()/CODEC2_RAND_MAX; - Ex[m].real = cosf(phi); - Ex[m].imag = sinf(phi); - } + Ex[m].real = cosf(ex_phase[0]*m); + Ex[m].imag = sinf(ex_phase[0]*m); + } + else { + + /* When a few samples were tested I found that LPC filter + phase is not needed in the unvoiced case, but no harm in + keeping it. + */ + float phi = TWO_PI*(float)codec2_rand()/CODEC2_RAND_MAX; + Ex[m].real = cosf(phi); + Ex[m].imag = sinf(phi); + } - /* filter using LPC filter */ + /* filter using LPC filter */ - A_[m].real = H[m].real*Ex[m].real - H[m].imag*Ex[m].imag; - A_[m].imag = H[m].imag*Ex[m].real + H[m].real*Ex[m].imag; + A_[m].real = H[m].real*Ex[m].real - H[m].imag*Ex[m].imag; + A_[m].imag = H[m].imag*Ex[m].real + H[m].real*Ex[m].imag; - /* modify sinusoidal phase */ + /* modify sinusoidal phase */ - new_phi = atan2f(A_[m].imag, A_[m].real+1E-12); - model->phi[m] = new_phi; - } + new_phi = atan2f(A_[m].imag, A_[m].real+1E-12); + model->phi[m] = new_phi; + } } diff --git a/codec2-dev/src/phase.h b/codec2-dev/src/phase.h index 367948df..03e1c507 100644 --- a/codec2-dev/src/phase.h +++ b/codec2-dev/src/phase.h @@ -29,11 +29,11 @@ #define __PHASE__ #include "kiss_fft.h" +#include "comp.h" void phase_synth_zero_order(kiss_fft_cfg fft_dec_cfg, MODEL *model, - float aks[], - float *ex_phase, - int order); + float *ex_phase, + COMP A[]); #endif diff --git a/codec2-dev/src/quantise.c b/codec2-dev/src/quantise.c index b4d3b31b..23f2660e 100644 --- a/codec2-dev/src/quantise.c +++ b/codec2-dev/src/quantise.c @@ -789,7 +789,6 @@ void lpc_post_filter(kiss_fft_cfg fft_fwd_cfg, COMP Pw[], float ak[], { int i; COMP x[FFT_ENC]; /* input to FFTs */ - COMP Aw[FFT_ENC]; /* LPC analysis filter spectrum */ COMP Ww[FFT_ENC]; /* weighting spectrum */ float Rw[FFT_ENC]; /* R = WA */ float e_before, e_after, gain; @@ -907,10 +906,11 @@ void aks_to_M2( int pf, /* true to LPC post filter */ int bass_boost, /* enable LPC filter 0-1khz 3dB boost */ float beta, - float gamma /* LPC post filter parameters */ + float gamma, /* LPC post filter parameters */ + COMP Aw[] /* output power spectrum */ ) { - COMP pw[FFT_ENC]; /* input to FFT for power spectrum */ + COMP a[FFT_ENC]; /* input to FFT for power spectrum */ COMP Pw[FFT_ENC]; /* output power spectrum */ int i,m; /* loop variables */ int am,bm; /* limits of current band */ @@ -927,20 +927,22 @@ void aks_to_M2( /* Determine DFT of A(exp(jw)) --------------------------------------------*/ for(i=0; isync = 0; // when debugging good idea to uncomment this to "open loop" + foff_coarse = rx_est_freq_offset(fdmdv, rx_fdm, nin, !fdmdv->sync); + if (fdmdv->sync == 0) fdmdv->foff = foff_coarse; fdmdv_freq_shift(rx_fdm_fcorr, rx_fdm, -fdmdv->foff, &fdmdv->foff_phase_rect, nin); diff --git a/codec2-dev/unittest/tlspsens.c b/codec2-dev/unittest/tlspsens.c index a53a66cd..4200d570 100644 --- a/codec2-dev/unittest/tlspsens.c +++ b/codec2-dev/unittest/tlspsens.c @@ -50,6 +50,7 @@ float run_a_test(char raw_file_name[], int bit_to_corrupt) int lsp_indexes[LPC_ORD], found_bit; float snr, snr_sum; int frames, i, mask, index; + COMP Aw[FFT_ENC]; c2 = codec2_create(CODEC2_MODE_2400); fft_fwd_cfg = kiss_fft_alloc(FFT_ENC, 0, NULL, NULL); @@ -93,7 +94,7 @@ float run_a_test(char raw_file_name[], int bit_to_corrupt) check_lsp_order(lsps, LPC_ORD); bw_expand_lsps(lsps, LPC_ORD, 50.0, 100.0); lsp_to_lpc(lsps, ak, LPC_ORD); - aks_to_M2(fft_fwd_cfg, ak, LPC_ORD, &model, e, &snr, 0, 0, 1, 1, LPCPF_BETA, LPCPF_GAMMA); + aks_to_M2(fft_fwd_cfg, ak, LPC_ORD, &model, e, &snr, 0, 0, 1, 1, LPCPF_BETA, LPCPF_GAMMA, Aw); snr_sum += snr; frames++; } -- 2.25.1