From ba37cdbb2f2cac36f9ba61692cdae2ea5ac01505 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 2 Jun 2017 07:36:15 +0000 Subject: [PATCH] TW and NW worked out at run time, c2sim c2enc/dec 1300/700C ok git-svn-id: https://svn.code.sf.net/p/freetel/code@3151 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/src/defines.h | 20 +++++++++------ codec2-dev/src/sine.c | 53 ++++++++++++++++++++++++---------------- 2 files changed, 44 insertions(+), 29 deletions(-) diff --git a/codec2-dev/src/defines.h b/codec2-dev/src/defines.h index f23ebadc..968c0bbe 100644 --- a/codec2-dev/src/defines.h +++ b/codec2-dev/src/defines.h @@ -36,6 +36,8 @@ /* General defines */ +#define N_S 0.010 /* buffer size in s */ +#define TW_S 0.005 /* trapezoidal synth window overlap */ #define MAX_AMP 160 /* maximum number of harmonics */ #ifndef PI #define PI 3.141592654 /* mathematical constant */ @@ -43,10 +45,8 @@ #define TWO_PI 6.283185307 /* mathematical constant */ #define MAX_STR 256 /* maximum string size */ -#define NW 279 /* analysis window size */ #define FFT_ENC 512 /* size of FFT used for encoder */ #define FFT_DEC 512 /* size of FFT used in decoder */ -#define TW 40 /* Trapezoidal synthesis window overlap */ #define V_THRESH 6.0 /* voicing threshold in dB */ #define LPC_ORD 10 /* LPC order */ #define LPC_ORD_LOW 6 /* LPC order for lower rates */ @@ -63,6 +63,8 @@ \*---------------------------------------------------------------------------*/ +/* Structure to hold constants calculated at run time based on sample rate */ + typedef struct { int Fs; /* sample rate of this instance */ int n_samp; /* number of samples per 10ms frame at Fs */ @@ -71,17 +73,19 @@ typedef struct { int p_min; /* minimum pitch period in samples */ int p_max; /* maximum pitch period in samples */ float Wo_min; - float Wo_max; + float Wo_max; + int nw; /* analysis window size in samples */ + int tw; /* trapezoidal synthesis window overlap */ } C2CONST; /* Structure to hold model parameters for one frame */ typedef struct { - float Wo; /* fundamental frequency estimate in radians */ - int L; /* number of harmonics */ - float A[MAX_AMP+1]; /* amplitiude of each harmonic */ - float phi[MAX_AMP+1]; /* phase of each harmonic */ - int voiced; /* non-zero if this frame is voiced */ + float Wo; /* fundamental frequency estimate in radians */ + int L; /* number of harmonics */ + float A[MAX_AMP+1]; /* amplitiude of each harmonic */ + float phi[MAX_AMP+1]; /* phase of each harmonic */ + int voiced; /* non-zero if this frame is voiced */ } MODEL; /* describes each codebook */ diff --git a/codec2-dev/src/sine.c b/codec2-dev/src/sine.c index f1225200..f22b8995 100644 --- a/codec2-dev/src/sine.c +++ b/codec2-dev/src/sine.c @@ -61,7 +61,7 @@ C2CONST c2const_create(int Fs) { assert((Fs == 8000) || (Fs = 16000)); c2const.Fs = Fs; - c2const.n_samp = Fs*0.01; + c2const.n_samp = Fs*N_S; c2const.max_amp = floor(Fs*P_MIN_S/2); c2const.p_min = floor(Fs*P_MIN_S); c2const.p_max = floor(Fs*P_MAX_S); @@ -69,6 +69,14 @@ C2CONST c2const_create(int Fs) { c2const.Wo_min = TWO_PI/c2const.p_max; c2const.Wo_max = TWO_PI/c2const.p_min; + if (Fs == 8000) { + c2const.nw = 279; + } else { + c2const.nw = 511; /* actually a bit shorter in time but lets us maintain constant FFT size */ + } + + c2const.tw = Fs*TW_S; + fprintf(stderr, "max_amp: %d m_pitch: %d\n", c2const.n_samp, c2const.m_pitch); fprintf(stderr, "p_min: %d p_max: %d\n", c2const.p_min, c2const.p_max); fprintf(stderr, "Wo_min: %f Wo_max: %f\n", c2const.Wo_min, c2const.Wo_max); @@ -93,6 +101,7 @@ void make_analysis_window(C2CONST *c2const, codec2_fft_cfg fft_fwd_cfg, float w[ COMP temp; int i,j; int m_pitch = c2const->m_pitch; + int nw = c2const->nw; /* Generate Hamming window centered on M-sample pitch analysis window @@ -100,19 +109,19 @@ void make_analysis_window(C2CONST *c2const, codec2_fft_cfg fft_fwd_cfg, float w[ 0 M/2 M-1 |-------------|-------------| |-------|-------| - NW samples + nw samples All our analysis/synthsis is centred on the M/2 sample. */ m = 0.0; - for(i=0; im_pitch; + int nw = c2const->nw; for(i=0; in_samp; + int tw = c2const->tw; /* Generate Parzen window in time domain */ win = 0.0; - for(i=0; i