From: drowe67 Date: Mon, 19 Sep 2016 19:35:05 +0000 (+0000) Subject: Danilo starting to rename some constants to make integration with 3rd party FFT libra... X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=5d030d8ee8d085f3664467bed6608335d99388f0;p=freetel-svn-tracking.git Danilo starting to rename some constants to make integration with 3rd party FFT libraries easier git-svn-id: https://svn.code.sf.net/p/freetel/code@2880 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/src/c2sim.c b/codec2-dev/src/c2sim.c index 8262634b..6cb5d7d5 100644 --- a/codec2-dev/src/c2sim.c +++ b/codec2-dev/src/c2sim.c @@ -65,20 +65,19 @@ int main(int argc, char *argv[]) { FILE *fout = NULL; /* output speech file */ FILE *fin; /* input speech file */ - short buf[N]; /* input/output buffer */ - float buf_float[N]; - float buf_float_bpf[N]; + short buf[N_SAMP]; /* input/output buffer */ + float buf_float[N_SAMP]; + float buf_float_bpf[N_SAMP]; float Sn[M]; /* float input speech samples */ - float Sn_pre[N]; /* pre-emphasised input speech samples */ + float Sn_pre[N_SAMP]; /* pre-emphasised input speech samples */ COMP Sw[FFT_ENC]; /* DFT of Sn[] */ kiss_fft_cfg fft_fwd_cfg; - kiss_fftr_cfg fftr_fwd_cfg; kiss_fft_cfg fft_inv_cfg; float w[M]; /* time domain hamming window */ COMP W[FFT_ENC]; /* DFT of w[] */ MODEL model; - float Pn[2*N]; /* trapezoidal synthesis window */ - float Sn_[2*N]; /* synthesised speech */ + float Pn[2*N_SAMP]; /* trapezoidal synthesis window */ + float Sn_[2*N_SAMP]; /* synthesised speech */ int i,m; /* loop variable */ int frames; float prev_Wo, prev__Wo, prev_uq_Wo; @@ -141,7 +140,7 @@ int main(int argc, char *argv[]) float gain = 1.0; int bpf_en = 0; int bpfb_en = 0; - float bpf_buf[BPF_N+N]; + float bpf_buf[BPF_N+N_SAMP]; float lspmelvq_mse = 0.0; int amread, Woread; FILE *fam, *fWo; @@ -197,7 +196,7 @@ int main(int argc, char *argv[]) Sn[i] = 1.0; Sn_pre[i] = 1.0; } - for(i=0; i<2*N; i++) + for(i=0; i<2*N_SAMP; i++) Sn_[i] = 0; prev_uq_Wo = prev_Wo = prev__Wo = TWO_PI/P_MAX; @@ -399,7 +398,6 @@ int main(int argc, char *argv[]) /* Initialise ------------------------------------------------------------*/ fft_fwd_cfg = kiss_fft_alloc(FFT_ENC, 0, NULL, NULL); /* fwd FFT,used in several places */ - fftr_fwd_cfg = kiss_fftr_alloc(FFT_ENC, 0, NULL, NULL); /* fwd FFT,used in several places */ fft_inv_cfg = kiss_fft_alloc(FFT_DEC, 1, NULL, NULL); /* inverse FFT, used just for synth */ make_analysis_window(fft_fwd_cfg, w, W); make_synthesis_window(Pn); @@ -434,17 +432,17 @@ int main(int argc, char *argv[]) frames = 0; sum_snr = 0; - while(fread(buf,sizeof(short),N,fin)) { + while(fread(buf,sizeof(short),N_SAMP,fin)) { frames++; - for(i=0; i 32767.0) buf[i] = 32767; diff --git a/codec2-dev/src/codec2.c b/codec2-dev/src/codec2.c index 6cbb0037..0111f7f0 100644 --- a/codec2-dev/src/codec2.c +++ b/codec2-dev/src/codec2.c @@ -120,7 +120,7 @@ struct CODEC2 * codec2_create(int mode) for(i=0; iSn[i] = 1.0; c2->hpf_states[0] = c2->hpf_states[1] = 0.0; - for(i=0; i<2*N; i++) + for(i=0; i<2*N_SAMP; i++) c2->Sn_[i] = 0; c2->fft_fwd_cfg = kiss_fft_alloc(FFT_ENC, 0, NULL, NULL); c2->fftr_fwd_cfg = kiss_fftr_alloc(FFT_ENC, 0, NULL, NULL); @@ -161,9 +161,9 @@ struct CODEC2 * codec2_create(int mode) c2->smoothing = 0; - c2->bpf_buf = (float*)malloc(sizeof(float)*(BPF_N+4*N)); + c2->bpf_buf = (float*)malloc(sizeof(float)*(BPF_N+4*N_SAMP)); assert(c2->bpf_buf != NULL); - for(i=0; ibpf_buf[i] = 0.0; c2->softdec = NULL; @@ -377,7 +377,7 @@ void codec2_encode_3200(struct CODEC2 *c2, unsigned char * bits, short speech[]) /* second 10ms analysis frame */ - analyse_one_frame(c2, &model, &speech[N]); + analyse_one_frame(c2, &model, &speech[N_SAMP]); pack(bits, &nbit, model.voiced, 1); Wo_index = encode_Wo(model.Wo, WO_BITS); pack(bits, &nbit, Wo_index, WO_BITS); @@ -463,7 +463,7 @@ void codec2_decode_3200(struct CODEC2 *c2, short speech[], const unsigned char * aks_to_M2(c2->fftr_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 0, 0, c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); apply_lpc_correction(&model[i]); - synthesise_one_frame(c2, &speech[N*i], &model[i], Aw); + synthesise_one_frame(c2, &speech[N_SAMP*i], &model[i], Aw); } /* update memories for next frame ----------------------------*/ @@ -523,7 +523,7 @@ void codec2_encode_2400(struct CODEC2 *c2, unsigned char * bits, short speech[]) /* second 10ms analysis frame */ - analyse_one_frame(c2, &model, &speech[N]); + analyse_one_frame(c2, &model, &speech[N_SAMP]); pack(bits, &nbit, model.voiced, 1); e = speech_to_uq_lsps(lsps, ak, c2->Sn, c2->w, LPC_ORD); @@ -606,7 +606,7 @@ void codec2_decode_2400(struct CODEC2 *c2, short speech[], const unsigned char * aks_to_M2(c2->fftr_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 0, 0, c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); apply_lpc_correction(&model[i]); - synthesise_one_frame(c2, &speech[N*i], &model[i], Aw); + synthesise_one_frame(c2, &speech[N_SAMP*i], &model[i], Aw); } /* update memories for next frame ----------------------------*/ @@ -668,7 +668,7 @@ void codec2_encode_1600(struct CODEC2 *c2, unsigned char * bits, short speech[]) /* frame 2: - voicing, scalar Wo & E -------------------------------*/ - analyse_one_frame(c2, &model, &speech[N]); + analyse_one_frame(c2, &model, &speech[N_SAMP]); pack(bits, &nbit, model.voiced, 1); Wo_index = encode_Wo(model.Wo, WO_BITS); @@ -681,12 +681,12 @@ void codec2_encode_1600(struct CODEC2 *c2, unsigned char * bits, short speech[]) /* frame 3: - voicing ---------------------------------------------*/ - analyse_one_frame(c2, &model, &speech[2*N]); + analyse_one_frame(c2, &model, &speech[2*N_SAMP]); pack(bits, &nbit, model.voiced, 1); /* frame 4: - voicing, scalar Wo & E, scalar LSPs ------------------*/ - analyse_one_frame(c2, &model, &speech[3*N]); + analyse_one_frame(c2, &model, &speech[3*N_SAMP]); pack(bits, &nbit, model.voiced, 1); Wo_index = encode_Wo(model.Wo, WO_BITS); @@ -790,7 +790,7 @@ void codec2_decode_1600(struct CODEC2 *c2, short speech[], const unsigned char * aks_to_M2(c2->fftr_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 0, 0, c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); apply_lpc_correction(&model[i]); - synthesise_one_frame(c2, &speech[N*i], &model[i], Aw); + synthesise_one_frame(c2, &speech[N_SAMP*i], &model[i], Aw); } /* update memories for next frame ----------------------------*/ @@ -851,7 +851,7 @@ void codec2_encode_1400(struct CODEC2 *c2, unsigned char * bits, short speech[]) /* frame 2: - voicing, joint Wo & E -------------------------------*/ - analyse_one_frame(c2, &model, &speech[N]); + analyse_one_frame(c2, &model, &speech[N_SAMP]); pack(bits, &nbit, model.voiced, 1); /* need to run this just to get LPC energy */ @@ -862,12 +862,12 @@ void codec2_encode_1400(struct CODEC2 *c2, unsigned char * bits, short speech[]) /* frame 3: - voicing ---------------------------------------------*/ - analyse_one_frame(c2, &model, &speech[2*N]); + analyse_one_frame(c2, &model, &speech[2*N_SAMP]); pack(bits, &nbit, model.voiced, 1); /* frame 4: - voicing, joint Wo & E, scalar LSPs ------------------*/ - analyse_one_frame(c2, &model, &speech[3*N]); + analyse_one_frame(c2, &model, &speech[3*N_SAMP]); pack(bits, &nbit, model.voiced, 1); e = speech_to_uq_lsps(lsps, ak, c2->Sn, c2->w, LPC_ORD); @@ -960,7 +960,7 @@ void codec2_decode_1400(struct CODEC2 *c2, short speech[], const unsigned char * aks_to_M2(c2->fftr_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 0, 0, c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); apply_lpc_correction(&model[i]); - synthesise_one_frame(c2, &speech[N*i], &model[i], Aw); + synthesise_one_frame(c2, &speech[N_SAMP*i], &model[i], Aw); } /* update memories for next frame ----------------------------*/ @@ -1025,17 +1025,17 @@ void codec2_encode_1300(struct CODEC2 *c2, unsigned char * bits, short speech[]) /* frame 2: - voicing ---------------------------------------------*/ - analyse_one_frame(c2, &model, &speech[N]); + analyse_one_frame(c2, &model, &speech[N_SAMP]); pack_natural_or_gray(bits, &nbit, model.voiced, 1, c2->gray); /* frame 3: - voicing ---------------------------------------------*/ - analyse_one_frame(c2, &model, &speech[2*N]); + analyse_one_frame(c2, &model, &speech[2*N_SAMP]); pack_natural_or_gray(bits, &nbit, model.voiced, 1, c2->gray); /* frame 4: - voicing, scalar Wo & E, scalar LSPs ------------------*/ - analyse_one_frame(c2, &model, &speech[3*N]); + analyse_one_frame(c2, &model, &speech[3*N_SAMP]); pack_natural_or_gray(bits, &nbit, model.voiced, 1, c2->gray); Wo_index = encode_Wo(model.Wo, WO_BITS); @@ -1143,7 +1143,7 @@ void codec2_decode_1300(struct CODEC2 *c2, short speech[], const unsigned char * aks_to_M2(c2->fftr_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 0, 0, c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); apply_lpc_correction(&model[i]); - synthesise_one_frame(c2, &speech[N*i], &model[i], Aw); + synthesise_one_frame(c2, &speech[N_SAMP*i], &model[i], Aw); } /* for(i=0; i<4; i++) { @@ -1220,7 +1220,7 @@ void codec2_encode_1200(struct CODEC2 *c2, unsigned char * bits, short speech[]) /* frame 2: - voicing, joint Wo & E -------------------------------*/ - analyse_one_frame(c2, &model, &speech[N]); + analyse_one_frame(c2, &model, &speech[N_SAMP]); pack(bits, &nbit, model.voiced, 1); /* need to run this just to get LPC energy */ @@ -1231,12 +1231,12 @@ void codec2_encode_1200(struct CODEC2 *c2, unsigned char * bits, short speech[]) /* frame 3: - voicing ---------------------------------------------*/ - analyse_one_frame(c2, &model, &speech[2*N]); + analyse_one_frame(c2, &model, &speech[2*N_SAMP]); pack(bits, &nbit, model.voiced, 1); /* frame 4: - voicing, joint Wo & E, scalar LSPs ------------------*/ - analyse_one_frame(c2, &model, &speech[3*N]); + analyse_one_frame(c2, &model, &speech[3*N_SAMP]); pack(bits, &nbit, model.voiced, 1); e = speech_to_uq_lsps(lsps, ak, c2->Sn, c2->w, LPC_ORD); @@ -1330,7 +1330,7 @@ void codec2_decode_1200(struct CODEC2 *c2, short speech[], const unsigned char * aks_to_M2(c2->fftr_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 0, 0, c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); apply_lpc_correction(&model[i]); - synthesise_one_frame(c2, &speech[N*i], &model[i], Aw); + synthesise_one_frame(c2, &speech[N_SAMP*i], &model[i], Aw); } /* update memories for next frame ----------------------------*/ @@ -1382,8 +1382,8 @@ void codec2_encode_700(struct CODEC2 *c2, unsigned char * bits, short speech[]) int indexes[LPC_ORD_LOW]; int Wo_index, e_index, i; unsigned int nbit = 0; - float bpf_out[4*N]; - short bpf_speech[4*N]; + float bpf_out[4*N_SAMP]; + short bpf_speech[4*N_SAMP]; int spare = 0; assert(c2 != NULL); @@ -1393,11 +1393,11 @@ void codec2_encode_700(struct CODEC2 *c2, unsigned char * bits, short speech[]) /* band pass filter */ for(i=0; ibpf_buf[i] = c2->bpf_buf[4*N+i]; - for(i=0; i<4*N; i++) + c2->bpf_buf[i] = c2->bpf_buf[4*N_SAMP+i]; + for(i=0; i<4*N_SAMP; i++) c2->bpf_buf[BPF_N+i] = speech[i]; - inverse_filter(&c2->bpf_buf[BPF_N], bpf, 4*N, bpf_out, BPF_N-1); - for(i=0; i<4*N; i++) + inverse_filter(&c2->bpf_buf[BPF_N], bpf, 4*N_SAMP, bpf_out, BPF_N-1); + for(i=0; i<4*N_SAMP; i++) bpf_speech[i] = bpf_out[i]; /* frame 1 --------------------------------------------------------*/ @@ -1406,15 +1406,15 @@ void codec2_encode_700(struct CODEC2 *c2, unsigned char * bits, short speech[]) /* frame 2 --------------------------------------------------------*/ - analyse_one_frame(c2, &model, &bpf_speech[N]); + analyse_one_frame(c2, &model, &bpf_speech[N_SAMP]); /* frame 3 --------------------------------------------------------*/ - analyse_one_frame(c2, &model, &bpf_speech[2*N]); + analyse_one_frame(c2, &model, &bpf_speech[2*N_SAMP]); /* frame 4: - voicing, scalar Wo & E, scalar LSPs -----------------*/ - analyse_one_frame(c2, &model, &bpf_speech[3*N]); + analyse_one_frame(c2, &model, &bpf_speech[3*N_SAMP]); pack(bits, &nbit, model.voiced, 1); Wo_index = encode_log_Wo(model.Wo, 5); pack_natural_or_gray(bits, &nbit, Wo_index, 5, c2->gray); @@ -1528,7 +1528,7 @@ void codec2_decode_700(struct CODEC2 *c2, short speech[], const unsigned char * aks_to_M2(c2->fftr_fwd_cfg, &ak[i][0], LPC_ORD_LOW, &model[i], e[i], &snr, 0, 0, c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); apply_lpc_correction(&model[i]); - synthesise_one_frame(c2, &speech[N*i], &model[i], Aw); + synthesise_one_frame(c2, &speech[N_SAMP*i], &model[i], Aw); } #ifdef DUMP @@ -1594,8 +1594,8 @@ void codec2_encode_700b(struct CODEC2 *c2, unsigned char * bits, short speech[]) int indexes[3]; int Wo_index, e_index, i; unsigned int nbit = 0; - float bpf_out[4*N]; - short bpf_speech[4*N]; + float bpf_out[4*N_SAMP]; + short bpf_speech[4*N_SAMP]; int spare = 0; assert(c2 != NULL); @@ -1605,11 +1605,11 @@ void codec2_encode_700b(struct CODEC2 *c2, unsigned char * bits, short speech[]) /* band pass filter */ for(i=0; ibpf_buf[i] = c2->bpf_buf[4*N+i]; - for(i=0; i<4*N; i++) + c2->bpf_buf[i] = c2->bpf_buf[4*N_SAMP+i]; + for(i=0; i<4*N_SAMP; i++) c2->bpf_buf[BPF_N+i] = speech[i]; - inverse_filter(&c2->bpf_buf[BPF_N], bpfb, 4*N, bpf_out, BPF_N-1); - for(i=0; i<4*N; i++) + inverse_filter(&c2->bpf_buf[BPF_N], bpfb, 4*N_SAMP, bpf_out, BPF_N-1); + for(i=0; i<4*N_SAMP; i++) bpf_speech[i] = bpf_out[i]; /* frame 1 --------------------------------------------------------*/ @@ -1618,15 +1618,15 @@ void codec2_encode_700b(struct CODEC2 *c2, unsigned char * bits, short speech[]) /* frame 2 --------------------------------------------------------*/ - analyse_one_frame(c2, &model, &bpf_speech[N]); + analyse_one_frame(c2, &model, &bpf_speech[N_SAMP]); /* frame 3 --------------------------------------------------------*/ - analyse_one_frame(c2, &model, &bpf_speech[2*N]); + analyse_one_frame(c2, &model, &bpf_speech[2*N_SAMP]); /* frame 4: - voicing, scalar Wo & E, VQ mel LSPs -----------------*/ - analyse_one_frame(c2, &model, &bpf_speech[3*N]); + analyse_one_frame(c2, &model, &bpf_speech[3*N_SAMP]); pack(bits, &nbit, model.voiced, 1); Wo_index = encode_log_Wo(model.Wo, 5); pack_natural_or_gray(bits, &nbit, Wo_index, 5, c2->gray); @@ -1732,7 +1732,7 @@ void codec2_decode_700b(struct CODEC2 *c2, short speech[], const unsigned char * aks_to_M2(c2->fftr_fwd_cfg, &ak[i][0], LPC_ORD_LOW, &model[i], e[i], &snr, 0, 0, c2->lpc_pf, c2->bass_boost, c2->beta, c2->gamma, Aw); apply_lpc_correction(&model[i]); - synthesise_one_frame(c2, &speech[N*i], &model[i], Aw); + synthesise_one_frame(c2, &speech[N_SAMP*i], &model[i], Aw); } #ifdef DUMP @@ -1859,9 +1859,9 @@ void synthesise_one_frame(struct CODEC2 *c2, short speech[], MODEL *model, COMP PROFILE_SAMPLE_AND_LOG2(synth_start, " synth"); - ear_protection(c2->Sn_, N); + ear_protection(c2->Sn_, N_SAMP); - for(i=0; iSn_[i] > 32767.0) speech[i] = 32767; else if (c2->Sn_[i] < -32767.0) @@ -1894,10 +1894,10 @@ void analyse_one_frame(struct CODEC2 *c2, MODEL *model, short speech[]) /* Read input speech */ - for(i=0; iSn[i] = c2->Sn[i+N]; - for(i=0; iSn[i+M-N] = speech[i]; + for(i=0; iSn[i] = c2->Sn[i+N_SAMP]; + for(i=0; iSn[i+M-N_SAMP] = speech[i]; PROFILE_SAMPLE(dft_start); dft_speech(c2->fft_fwd_cfg, Sw, c2->Sn, c2->w); @@ -1905,7 +1905,7 @@ void analyse_one_frame(struct CODEC2 *c2, MODEL *model, short speech[]) /* Estimate pitch */ - nlp(c2->nlp,c2->Sn,N,P_MIN,P_MAX,&pitch,Sw, c2->W, &c2->prev_Wo_enc); + nlp(c2->nlp,c2->Sn,N_SAMP,P_MIN,P_MAX,&pitch,Sw, c2->W, &c2->prev_Wo_enc); PROFILE_SAMPLE_AND_LOG(model_start, nlp_start, " nlp"); model->Wo = TWO_PI/pitch; diff --git a/codec2-dev/src/codec2_internal.h b/codec2-dev/src/codec2_internal.h index 5fb94324..57f27cbc 100644 --- a/codec2-dev/src/codec2_internal.h +++ b/codec2-dev/src/codec2_internal.h @@ -35,7 +35,7 @@ struct CODEC2 { kiss_fftr_cfg fftr_fwd_cfg; /* forward real FFT config */ float w[M]; /* time domain hamming window */ COMP W[FFT_ENC]; /* DFT of w[] */ - float Pn[2*N]; /* trapezoidal synthesis window */ + float Pn[2*N_SAMP]; /* trapezoidal synthesis window */ float *bpf_buf; /* buffer for band pass filter */ float Sn[M]; /* input speech */ float hpf_states[2]; /* high pass filter states */ @@ -43,7 +43,7 @@ struct CODEC2 { int gray; /* non-zero for gray encoding */ kiss_fft_cfg fft_inv_cfg; /* inverse FFT config */ - float Sn_[2*N]; /* synthesised output speech */ + float Sn_[2*N_SAMP]; /* synthesised output speech */ float ex_phase; /* excitation model phase track */ float bg_est; /* background noise estimate for post filter */ float prev_Wo_enc; /* previous frame's pitch estimate */ diff --git a/codec2-dev/src/defines.h b/codec2-dev/src/defines.h index 7b43b773..67e65c4b 100644 --- a/codec2-dev/src/defines.h +++ b/codec2-dev/src/defines.h @@ -36,9 +36,11 @@ /* General defines */ -#define N 80 /* number of samples per frame */ +#define N_SAMP 80 /* number of samples per frame */ #define MAX_AMP 80 /* maximum number of harmonics */ +#ifndef PI #define PI 3.141592654 /* mathematical constant */ +#endif #define TWO_PI 6.283185307 /* mathematical constant */ #define FS 8000 /* sample rate in Hz */ #define MAX_STR 256 /* maximum string size */ diff --git a/codec2-dev/src/fdmdv.c b/codec2-dev/src/fdmdv.c index 64c615dd..eb2774fd 100644 --- a/codec2-dev/src/fdmdv.c +++ b/codec2-dev/src/fdmdv.c @@ -91,8 +91,8 @@ struct FDMDV * fdmdv_create(int Nc) assert(NC == FDMDV_NC_MAX); /* check public and private #defines match */ assert(Nc <= NC); - assert(FDMDV_NOM_SAMPLES_PER_FRAME == M); - assert(FDMDV_MAX_SAMPLES_PER_FRAME == (M+M/P)); + assert(FDMDV_NOM_SAMPLES_PER_FRAME == M_FAC); + assert(FDMDV_MAX_SAMPLES_PER_FRAME == (M_FAC+M_FAC/P)); f = (struct FDMDV*)malloc(sizeof(struct FDMDV)); if (f == NULL) @@ -167,9 +167,9 @@ struct FDMDV * fdmdv_create(int Nc) f->pilot_baseband1[i].imag = f->pilot_baseband2[i].imag = 0.0; } f->pilot_lut_index = 0; - f->prev_pilot_lut_index = 3*M; + f->prev_pilot_lut_index = 3*M_FAC; - for(i=0; irxdec_lpf_mem[i].real = 0.0; f->rxdec_lpf_mem[i].imag = 0.0; } @@ -183,7 +183,7 @@ struct FDMDV * fdmdv_create(int Nc) f->foff_phase_rect.real = 1.0; f->foff_phase_rect.imag = 0.0; - for(i=0; irx_fdm_mem[i].real = 0.0; f->rx_fdm_mem[i].imag = 0.0; } @@ -350,12 +350,12 @@ void bits_to_dqpsk_symbols(COMP tx_symbols[], int Nc, COMP prev_tx_symbols[], in AUTHOR......: David Rowe DATE CREATED: 17/4/2012 - Given Nc*NB bits construct M samples (1 symbol) of Nc+1 filtered + Given Nc*NB bits construct M_FAC samples (1 symbol) of Nc+1 filtered symbols streams. \*---------------------------------------------------------------------------*/ -void tx_filter(COMP tx_baseband[NC+1][M], int Nc, COMP tx_symbols[], COMP tx_filter_memory[NC+1][NSYM]) +void tx_filter(COMP tx_baseband[NC+1][M_FAC], int Nc, COMP tx_symbols[], COMP tx_filter_memory[NC+1][NSYM]) { int c; int i,j,k; @@ -369,25 +369,25 @@ void tx_filter(COMP tx_baseband[NC+1][M], int Nc, COMP tx_symbols[], COMP tx_fil tx_filter_memory[c][NSYM-1] = cmult(tx_symbols[c], gain); /* - tx filter each symbol, generate M filtered output samples for each symbol. + tx filter each symbol, generate M_FAC filtered output samples for each symbol. Efficient polyphase filter techniques used as tx_filter_memory is sparse */ - for(i=0; ireal; pilot_fdm[i].imag = sqrtf(2)*2*tx_baseband[i] * phase->imag; @@ -679,7 +679,7 @@ void generate_pilot_lut(COMP pilot_lut[], COMP *pilot_freq) float pilot_symbol = sqrtf(2.0); COMP pilot_phase = {1.0, 0.0}; float pilot_filter_mem[NFILTER]; - COMP pilot[M]; + COMP pilot[M_FAC]; int i,f; for(i=0; i= 4) - memcpy(&pilot_lut[M*(f-4)], pilot, M*sizeof(COMP)); + memcpy(&pilot_lut[M_FAC*(f-4)], pilot, M_FAC*sizeof(COMP)); } // create complex conjugate since we need this and only this later on - for (f=0;f<4*M;f++) + for (f=0;f<4*M_FAC;f++) { pilot_lut[f] = cconj(pilot_lut[f]); } @@ -822,29 +822,29 @@ float rx_est_freq_offset(struct FDMDV *f, COMP rx_fdm[], int nin, int do_fft) #ifndef ARM_MATH_CM4 int j; #endif - COMP pilot[M+M/P]; - COMP prev_pilot[M+M/P]; + COMP pilot[M_FAC+M_FAC/P]; + COMP prev_pilot[M_FAC+M_FAC/P]; float foff, foff1, foff2; float max1, max2; - assert(nin <= M+M/P); + assert(nin <= M_FAC+M_FAC/P); /* get pilot samples used for correlation/down conversion of rx signal */ for (i=0; ipilot_lut[f->pilot_lut_index]; f->pilot_lut_index++; - if (f->pilot_lut_index >= 4*M) + if (f->pilot_lut_index >= 4*M_FAC) f->pilot_lut_index = 0; prev_pilot[i] = f->pilot_lut[f->prev_pilot_lut_index]; f->prev_pilot_lut_index++; - if (f->prev_pilot_lut_index >= 4*M) + if (f->prev_pilot_lut_index >= 4*M_FAC) f->prev_pilot_lut_index = 0; } /* - Down convert latest M samples of pilot by multiplying by ideal + Down convert latest M_FAC samples of pilot by multiplying by ideal BPSK pilot signal we have generated locally. The peak of the resulting signal is sensitive to the time shift between the received and local version of the pilot, so we do it twice at @@ -922,14 +922,14 @@ void fdmdv_freq_shift(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, \*---------------------------------------------------------------------------*/ -void fdm_downconvert(COMP rx_baseband[NC+1][M+M/P], int Nc, COMP rx_fdm[], COMP phase_rx[], COMP freq[], int nin) +void fdm_downconvert(COMP rx_baseband[NC+1][M_FAC+M_FAC/P], int Nc, COMP rx_fdm[], COMP phase_rx[], COMP freq[], int nin) { int i,c; float mag; /* maximum number of input samples to demod */ - assert(nin <= (M+M/P)); + assert(nin <= (M_FAC+M_FAC/P)); /* downconvert */ @@ -955,7 +955,7 @@ void fdm_downconvert(COMP rx_baseband[NC+1][M+M/P], int Nc, COMP rx_fdm[], COMP DATE CREATED: 22/4/2012 Receive filter each baseband signal at oversample rate P. Filtering at - rate P lowers CPU compared to rate M. + rate P lowers CPU compared to rate M_FAC. Depending on the number of input samples to the demod nin, we produce P-1, P (usually), or P+1 filtered samples at rate P. nin is @@ -964,13 +964,13 @@ void fdm_downconvert(COMP rx_baseband[NC+1][M+M/P], int Nc, COMP rx_fdm[], COMP \*---------------------------------------------------------------------------*/ -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) +void rx_filter(COMP rx_filt[NC+1][P+1], int Nc, COMP rx_baseband[NC+1][M_FAC+M_FAC/P], COMP rx_filter_memory[NC+1][NFILTER], int nin) { int c, i,j,k,l; - int n=M/P; + int n=M_FAC/P; /* rx filter each symbol, generate P filtered output samples for - each symbol. Note we keep filter memory at rate M, it's just + each symbol. Note we keep filter memory at rate M_FAC, it's just the filter output at rate P */ for(i=0, j=0; irxdec_lpf_mem, *nin); down_convert_and_rx_filter(rx_filt, fdmdv->Nc, rx_fdm_filter, fdmdv->rx_fdm_mem, fdmdv->phase_rx, fdmdv->freq, - fdmdv->freq_pol, *nin, M/Q); + fdmdv->freq_pol, *nin, M_FAC/Q); PROFILE_SAMPLE_AND_LOG(rx_est_timing_start, down_convert_and_rx_filter_start, " down_convert_and_rx_filter"); - fdmdv->rx_timing = rx_est_timing(rx_symbols, fdmdv->Nc, rx_filt, fdmdv->rx_filter_mem_timing, env, *nin, M); + fdmdv->rx_timing = rx_est_timing(rx_symbols, fdmdv->Nc, rx_filt, fdmdv->rx_filter_mem_timing, env, *nin, M_FAC); PROFILE_SAMPLE_AND_LOG(qpsk_to_bits_start, rx_est_timing_start, " rx_est_timing"); /* Adjust number of input samples to keep timing within bounds */ - *nin = M; + *nin = M_FAC; - if (fdmdv->rx_timing > 2*M/P) - *nin += M/P; + if (fdmdv->rx_timing > 2*M_FAC/P) + *nin += M_FAC/P; if (fdmdv->rx_timing < 0) - *nin -= M/P; + *nin -= M_FAC/P; foff_fine = qpsk_to_bits(rx_bits, &sync_bit, fdmdv->Nc, fdmdv->phase_difference, fdmdv->prev_rx_symbols, rx_symbols, fdmdv->old_qpsk_mapping); diff --git a/codec2-dev/src/fdmdv_internal.h b/codec2-dev/src/fdmdv_internal.h index 317a3b9d..0946db9e 100644 --- a/codec2-dev/src/fdmdv_internal.h +++ b/codec2-dev/src/fdmdv_internal.h @@ -48,21 +48,21 @@ #define NC 20 /* max number of data carriers (plus one pilot in the centre) */ #define NB 2 /* Bits/symbol for QPSK modulation */ #define RB (NC*RS*NB) /* bit rate */ -#define M (FS/RS) /* oversampling factor */ +#define M_FAC (FS/RS) /* oversampling factor */ #define NSYM 6 /* number of symbols to filter over */ -#define NFILTER (NSYM*M) /* size of tx/rx filters at sample rate M */ +#define NFILTER (NSYM*M_FAC) /* size of tx/rx filters at sample rate M */ #define FSEP 75 /* Default separation between carriers (Hz) */ #define NT 5 /* number of symbols we estimate timing over */ #define P 4 /* oversample factor used for initial rx symbol filtering output */ -#define Q (M/4) /* oversample factor used for initial rx symbol filtering input */ +#define Q (M_FAC/4) /* oversample factor used for initial rx symbol filtering input */ #define NRXDEC 31 /* number of taps in the rx decimation filter */ -#define NPILOT_LUT (4*M) /* number of pilot look up table samples */ +#define NPILOT_LUT (4*M_FAC) /* number of pilot look up table samples */ #define NPILOTCOEFF 30 /* number of FIR filter coeffs in LP filter */ -#define NPILOTBASEBAND (NPILOTCOEFF+M+M/P) /* number of pilot baseband samples reqd for pilot LPF */ -#define NPILOTLPF (4*M) /* number of samples we DFT pilot over, pilot est window */ +#define NPILOTBASEBAND (NPILOTCOEFF+M_FAC+M_FAC/P) /* number of pilot baseband samples reqd for pilot LPF */ +#define NPILOTLPF (4*M_FAC) /* number of samples we DFT pilot over, pilot est window */ #define MPILOTFFT 256 #define NSYNC_MEM 6 @@ -130,8 +130,8 @@ struct FDMDV { /* Demodulator */ - COMP rxdec_lpf_mem[NRXDEC-1+M]; - COMP rx_fdm_mem[NFILTER+M]; + COMP rxdec_lpf_mem[NRXDEC-1+M_FAC]; + COMP rx_fdm_mem[NFILTER+M_FAC]; COMP phase_rx[NC+1]; COMP rx_filter_mem_timing[NC+1][NT*P]; float rx_timing; @@ -162,8 +162,8 @@ struct FDMDV { \*---------------------------------------------------------------------------*/ void bits_to_dqpsk_symbols(COMP tx_symbols[], int Nc, COMP prev_tx_symbols[], int tx_bits[], int *pilot_bit, int old_qpsk_mapping); -void tx_filter(COMP tx_baseband[NC+1][M], int Nc, COMP tx_symbols[], COMP tx_filter_memory[NC+1][NSYM]); -void fdm_upconvert(COMP tx_fdm[], int Nc, COMP tx_baseband[NC+1][M], COMP phase_tx[], COMP freq_tx[], +void tx_filter(COMP tx_baseband[NC+1][M_FAC], int Nc, COMP tx_symbols[], COMP tx_filter_memory[NC+1][NSYM]); +void fdm_upconvert(COMP tx_fdm[], int Nc, COMP tx_baseband[NC+1][M_FAC], COMP phase_tx[], COMP freq_tx[], COMP *fbb_phase, COMP fbb_rect); void tx_filter_and_upconvert(COMP tx_fdm[], int Nc, COMP tx_symbols[], COMP tx_filter_memory[NC+1][NSYM], @@ -172,9 +172,9 @@ void generate_pilot_fdm(COMP *pilot_fdm, int *bit, float *symbol, float *filter_ void generate_pilot_lut(COMP pilot_lut[], COMP *pilot_freq); 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 fdm_downconvert(COMP rx_baseband[NC+1][M_FAC+M_FAC/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); +void rx_filter(COMP rx_filt[NC+1][P+1], int Nc, COMP rx_baseband[NC+1][M_FAC+M_FAC/P], COMP rx_filter_memory[NC+1][NFILTER], int nin); void down_convert_and_rx_filter(COMP rx_filt[NC+1][P+1], int Nc, COMP rx_fdm[], COMP rx_fdm_mem[], COMP phase_rx[], COMP freq[], float freq_pol[], int nin, int dec_rate); diff --git a/codec2-dev/src/phase.c b/codec2-dev/src/phase.c index dcdf6b66..60037e18 100644 --- a/codec2-dev/src/phase.c +++ b/codec2-dev/src/phase.c @@ -72,16 +72,16 @@ As we don't transmit the pulse position for this model, we need to synthesise it. Now the excitation pulses occur at a rate of Wo. - This means the phase of the first harmonic advances by N samples - over a synthesis frame of N samples. For example if Wo is pi/20 - (200 Hz), then over a 10ms frame (N=80 samples), the phase of the + This means the phase of the first harmonic advances by N_SAMP samples + over a synthesis frame of N_SAMP samples. For example if Wo is pi/20 + (200 Hz), then over a 10ms frame (N_SAMP=80 samples), the phase of the first harmonic would advance (pi/20)*80 = 4*pi or two complete cycles. We generate the excitation phase of the fundamental (first harmonic): - arg[E[1]] = Wo*N; + arg[E[1]] = Wo*N_SAMP; We then relate the phase of the m-th excitation harmonic to the phase of the fundamental as: @@ -158,10 +158,10 @@ void phase_synth_zero_order( 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_SAMP/2; */ - ex_phase[0] += (model->Wo)*N; + ex_phase[0] += (model->Wo)*N_SAMP; ex_phase[0] -= TWO_PI*floorf(ex_phase[0]/TWO_PI + 0.5); for(m=1; m<=model->L; m++) { diff --git a/codec2-dev/src/phaseexp.c b/codec2-dev/src/phaseexp.c index 61b240df..80361162 100644 --- a/codec2-dev/src/phaseexp.c +++ b/codec2-dev/src/phaseexp.c @@ -248,7 +248,7 @@ static void print_pred_error(struct PEXP *pexp, MODEL *model, int start, int end if (mag > mag_thresh) { for(i=start; i<=end; i++) { - float pred = pexp->phi_prev[i] + N*i*(model->Wo + pexp->Wo_prev)/2.0; + float pred = pexp->phi_prev[i] + N_SAMP*i*(model->Wo + pexp->Wo_prev)/2.0; float err = pred - model->phi[i]; err = atan2(sin(err),cos(err)); printf("%f\n",err); @@ -263,7 +263,7 @@ static void predict_phases(struct PEXP *pexp, MODEL *model, int start, int end) int i; for(i=start; i<=end; i++) { - model->phi[i] = pexp->phi_prev[i] + N*i*model->Wo; + model->phi[i] = pexp->phi_prev[i] + N_SAMP*i*model->Wo; } } @@ -311,7 +311,7 @@ static void predict_phases_state(struct PEXP *pexp, MODEL *model, int start, int } else for(i=start; i<=end; i++) { - model->phi[i] = pexp->phi_prev[i] + N*i*best_Wo; + model->phi[i] = pexp->phi_prev[i] + N_SAMP*i*best_Wo; } printf("state %d\n", pexp->state); } @@ -330,7 +330,7 @@ static void predict_phases2(struct PEXP *pexp, MODEL *model, int start, int end) float pred, str, diff; for(i=start; i<=end; i++) { - pred = pexp->phi_prev[i] + N*i*model->Wo; + pred = pexp->phi_prev[i] + N_SAMP*i*model->Wo; str = pexp->phi1*i; diff = str - pred; diff = atan2(sin(diff), cos(diff)); @@ -533,7 +533,7 @@ static void top_amp(struct PEXP *pexp, MODEL *model, int start, int end, int n_h if (!top) { model->phi[i] = 0.0; /* make sure */ if (pred) { - //model->phi[i] = pexp->phi_prev[i] + i*N*(model->Wo + pexp->Wo_prev)/2.0; + //model->phi[i] = pexp->phi_prev[i] + i*N_SAMP*(model->Wo + pexp->Wo_prev)/2.0; model->phi[i] = i*model->phi[1]; } else @@ -558,7 +558,7 @@ static void limit_prediction_error(struct PEXP *pexp, MODEL *model, int start, i float pred, pred_error, error; for(i=start; i<=end; i++) { - pred = pexp->phi_prev[i] + N*i*(model->Wo + pexp->Wo_prev)/2.0; + pred = pexp->phi_prev[i] + N_SAMP*i*(model->Wo + pexp->Wo_prev)/2.0; pred_error = pred - model->phi[i]; pred_error -= TWO_PI*floor((pred_error+PI)/TWO_PI); quant_phase(&pred_error, -limit, limit, 2); @@ -577,7 +577,7 @@ static void quant_prediction_error(struct PEXP *pexp, MODEL *model, int start, i float pred, pred_error; for(i=start; i<=end; i++) { - pred = pexp->phi_prev[i] + N*i*(model->Wo + pexp->Wo_prev)/2.0; + pred = pexp->phi_prev[i] + N_SAMP*i*(model->Wo + pexp->Wo_prev)/2.0; pred_error = pred - model->phi[i]; pred_error -= TWO_PI*floor((pred_error+PI)/TWO_PI); @@ -604,7 +604,7 @@ static void print_sparse_pred_error(struct PEXP *pexp, MODEL *model, int start, } for(i=start; i<=end; i++) { - pred = pexp->phi_prev[i] + N*i*(model->Wo + pexp->Wo_prev)/2.0; + pred = pexp->phi_prev[i] + N_SAMP*i*(model->Wo + pexp->Wo_prev)/2.0; error = pred - model->phi[i]; error = atan2(sin(error),cos(error)); @@ -756,7 +756,7 @@ static float refine_Wo(struct PEXP *pexp, var = 0.0; for(i=start; i<=end; i++) { - pred = pexp->phi_prev[i] + N*i*Wo; + pred = pexp->phi_prev[i] + N_SAMP*i*Wo; error = pred - model->phi[i]; error = atan2(sin(error),cos(error)); var += error*error; @@ -816,7 +816,7 @@ static void sparse_vq_pred_error(struct PEXP *pexp, //printf("\n"); for(i=1; i<=model->L; i++) { - pred = pexp->phi_prev[i] + N*i*best_Wo; + pred = pexp->phi_prev[i] + N_SAMP*i*best_Wo; error = pred - model->phi[i]; index = MAX_AMP*i*model->Wo/PI; @@ -839,7 +839,7 @@ static void sparse_vq_pred_error(struct PEXP *pexp, /* transform quantised phases back */ for(i=1; i<=model->L; i++) { - pred = pexp->phi_prev[i] + N*i*best_Wo; + pred = pexp->phi_prev[i] + N_SAMP*i*best_Wo; index = MAX_AMP*i*model->Wo/PI; assert(index < MAX_AMP); @@ -858,7 +858,7 @@ static void predict_phases1(struct PEXP *pexp, MODEL *model, int start, int end) best_Wo = refine_Wo(pexp, model, 1, model->L); for(i=start; i<=end; i++) { - model->phi[i] = pexp->phi_prev[i] + N*i*best_Wo; + model->phi[i] = pexp->phi_prev[i] + N_SAMP*i*best_Wo; } } @@ -890,7 +890,7 @@ void smooth_phase(struct PEXP *pexp, MODEL *model, int mode) /* set up sparse array */ for(m=1; m<=model->L; m++) { - pred = pexp->phi_prev[m] + N*m*best_Wo; + pred = pexp->phi_prev[m] + N_SAMP*m*best_Wo; err = model->phi[m] - pred; err = atan2(sin(err),cos(err)); @@ -958,7 +958,7 @@ void smooth_phase(struct PEXP *pexp, MODEL *model, int mode) for(m=1; m<=model->L; m++) { index = MAX_AMP*m*model->Wo/PI; assert(index < MAX_AMP); - pred = pexp->phi_prev[m] + N*m*best_Wo; + pred = pexp->phi_prev[m] + N_SAMP*m*best_Wo; err = atan2(sparse_pe_out[index].imag, sparse_pe_out[index].real); model->phi[m] = pred + err; } @@ -992,13 +992,13 @@ void smooth_phase2(struct PEXP *pexp, MODEL *model) { c = s = 0.0; if (h>1) { for(i=a; iphi_prev[i] + N*i*best_Wo; + pred = pexp->phi_prev[i] + N_SAMP*i*best_Wo; err = model->phi[i] - pred; c += cos(err); s += sin(err); } phi1_ = atan2(s,c); for(i=a; iphi_prev[i] + N*i*best_Wo; + pred = pexp->phi_prev[i] + N_SAMP*i*best_Wo; printf("%d: %4.3f -> ", i, model->phi[i]); model->phi[i] = pred + phi1_; model->phi[i] = atan2(sin(model->phi[i]),cos(model->phi[i])); @@ -1051,7 +1051,7 @@ void smooth_phase3(struct PEXP *pexp, MODEL *model) { /* est predicted phase from average */ - pred = pexp->phi_prev[m] + N*m*best_Wo; + pred = pexp->phi_prev[m] + N_SAMP*m*best_Wo; err = model->phi[m] - pred; av[b].real += cos(err); av[b].imag += sin(err); } @@ -1075,7 +1075,7 @@ void smooth_phase3(struct PEXP *pexp, MODEL *model) { printf("L %d m %d f %4.f b %d\n", model->L, m, f, b); - pred = pexp->phi_prev[m] + N*m*best_Wo; + pred = pexp->phi_prev[m] + N_SAMP*m*best_Wo; err = atan2(av[b].imag, av[b].real); printf(" %d: %4.3f -> ", m, model->phi[m]); model->phi[m] = pred + err; @@ -1142,7 +1142,7 @@ void cb_phase1(struct PEXP *pexp, MODEL *model) { assert(b < MAX_BINS); if (m != max_ind[b]) - model->phi[m] = pexp->phi_prev[m] + N*m*best_Wo; + model->phi[m] = pexp->phi_prev[m] + N_SAMP*m*best_Wo; } } } @@ -1166,7 +1166,7 @@ void cb_phase2(struct PEXP *pexp, MODEL *model) { st = 2*model->L/4; step = 3; - model->phi[1] = pexp->phi_prev[1] + (pexp->Wo_prev+model->Wo)*N/2.0; + model->phi[1] = pexp->phi_prev[1] + (pexp->Wo_prev+model->Wo)*N_SAMP/2.0; printf("L=%d ", model->L); for(m=st; mphi[i] = i*phi1_; //model->phi[i] = i*model->phi[1]; - //model->phi[i] = m*(pexp->Wo_prev+model->Wo)*N/2.0; + //model->phi[i] = m*(pexp->Wo_prev+model->Wo)*N_SAMP/2.0; model->A[m] = A[m]; printf("%d ", i); } @@ -1223,7 +1223,7 @@ static void repeat_phases(struct PEXP *pexp, MODEL *model) { *model = pexp->prev_model; for(m=1; m<=model->L; m++) - model->phi[m] += N*m*model->Wo; + model->phi[m] += N_SAMP*m*model->Wo; } @@ -1347,7 +1347,7 @@ void phase_experiment(struct PEXP *pexp, MODEL *model, char *arg) { /* update states */ //best_Wo = refine_Wo(pexp, model, model->L/2, model->L); - pexp->phi1 += N*model->Wo; + pexp->phi1 += N_SAMP*model->Wo; for(m=1; m<=model->L; m++) pexp->phi_prev[m] = model->phi[m]; diff --git a/codec2-dev/src/sine.c b/codec2-dev/src/sine.c index 86d28ffd..138486da 100644 --- a/codec2-dev/src/sine.c +++ b/codec2-dev/src/sine.c @@ -522,17 +522,17 @@ void make_synthesis_window(float Pn[]) /* Generate Parzen window in time domain */ win = 0.0; - for(i=0; iL; l++) { - for(i=0,j=-N+1; iA[l]*cosf(j*model->Wo*l + model->phi[l]); + for(i=0,j=-N_SAMP+1; iA[l]*cosf(j*model->Wo*l + model->phi[l]); } - for(i=N-1,j=0; i<2*N; i++,j++) + for(i=N_SAMP-1,j=0; i<2*N_SAMP; i++,j++) Sw_[j].real += 2.0*model->A[l]*cosf(j*model->Wo*l + model->phi[l]); } #endif /* Overlap add to previous samples */ - for(i=0; irxdec_lpf_mem, nin); down_convert_and_rx_filter(rx_filt, fdmdv->Nc, rx_fdm_filter, fdmdv->rx_fdm_mem, fdmdv->phase_rx, fdmdv->freq, - fdmdv->freq_pol, nin, M/Q); - rx_timing = rx_est_timing(rx_symbols, FDMDV_NC, rx_filt, fdmdv->rx_filter_mem_timing, env, nin, M); + fdmdv->freq_pol, nin, M_FAC/Q); + rx_timing = rx_est_timing(rx_symbols, FDMDV_NC, rx_filt, fdmdv->rx_filter_mem_timing, env, nin, M_FAC); foff_fine = qpsk_to_bits(rx_bits, &sync_bit, FDMDV_NC, fdmdv->phase_difference, fdmdv->prev_rx_symbols, rx_symbols, 0); //for(i=0; isig_est, fdmdv->noise_est, FDMDV_NC, fdmdv->phase_difference); memcpy(fdmdv->prev_rx_symbols, rx_symbols, sizeof(COMP)*(FDMDV_NC+1)); - next_nin = M; + next_nin = M_FAC; - if (rx_timing > 2*M/P) - next_nin += M/P; + if (rx_timing > 2*M_FAC/P) + next_nin += M_FAC/P; if (rx_timing < 0) - next_nin -= M/P; + next_nin -= M_FAC/P; fdmdv->sync = freq_state(&reliable_sync_bit, sync_bit, &fdmdv->fest_state, &fdmdv->timer, fdmdv->sync_mem); fdmdv->foff -= TRACK_COEFF*foff_fine; @@ -196,7 +196,7 @@ int main(int argc, char *argv[]) memcpy(&tx_bits_log[FDMDV_BITS_PER_FRAME*f], tx_bits, sizeof(int)*FDMDV_BITS_PER_FRAME); memcpy(&tx_symbols_log[(FDMDV_NC+1)*f], tx_symbols, sizeof(COMP)*(FDMDV_NC+1)); - memcpy(&tx_fdm_log[M*f], tx_fdm, sizeof(COMP)*M); + memcpy(&tx_fdm_log[M_FAC*f], tx_fdm, sizeof(COMP)*M_FAC); memcpy(&pilot_baseband1_log[f*NPILOTBASEBAND], fdmdv->pilot_baseband1, sizeof(COMP)*NPILOTBASEBAND); memcpy(&pilot_baseband2_log[f*NPILOTBASEBAND], fdmdv->pilot_baseband2, sizeof(COMP)*NPILOTBASEBAND); @@ -214,10 +214,10 @@ int main(int argc, char *argv[]) rx_fdm_filter_log_index += nin; for(c=0; cpilot_lut, 1, NPILOT_LUT, NPILOT_LUT); octave_save_complex(fout, "pilot_baseband1_log_c", pilot_baseband1_log, 1, NPILOTBASEBAND*FRAMES, NPILOTBASEBAND*FRAMES); octave_save_complex(fout, "pilot_baseband2_log_c", pilot_baseband2_log, 1, NPILOTBASEBAND*FRAMES, NPILOTBASEBAND*FRAMES); diff --git a/codec2-dev/unittest/tlspsens.c b/codec2-dev/unittest/tlspsens.c index da4f82e9..f25b7fc2 100644 --- a/codec2-dev/unittest/tlspsens.c +++ b/codec2-dev/unittest/tlspsens.c @@ -41,7 +41,7 @@ float run_a_test(char raw_file_name[], int bit_to_corrupt) { FILE *fin; - short buf[N]; + short buf[N_SAMP]; struct CODEC2 *c2; kiss_fft_cfg fft_fwd_cfg; MODEL model; @@ -79,7 +79,7 @@ float run_a_test(char raw_file_name[], int bit_to_corrupt) snr_sum = 0.0; frames = 0; - while(fread(buf, sizeof(short), N, fin) == N) { + while(fread(buf, sizeof(short), N_SAMP, fin) == N_SAMP) { analyse_one_frame(c2, &model, buf); e = speech_to_uq_lsps(lsps, ak, c2->Sn, c2->w, LPC_ORD); encode_lsps_scalar(lsp_indexes, lsps, LPC_ORD);