added mel resampling option to c2sim
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 5 Jun 2017 03:15:51 +0000 (03:15 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 5 Jun 2017 03:15:51 +0000 (03:15 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@3155 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/c2sim.c
codec2-dev/src/codec2.c
codec2-dev/src/newamp1.c
codec2-dev/src/newamp1.h

index ee667ee46141ad309df21d0ac8316532b9440e34..e25450e5c5d65c2b413345349a2e84e5a161cf35 100644 (file)
@@ -107,10 +107,13 @@ int main(int argc, char *argv[])
     char  phaseexp_arg[MAX_STR];
     char  out_file[MAX_STR];
     FILE *fout = NULL; /* output speech file */
+    int   mel_resampling = 0;
+    int   K = 20;
 
     char* opt_string = "ho:";
     struct option long_options[] = {
         { "Fs", required_argument, &set_fs, 1 },
+        { "mel", required_argument, &mel_resampling, 1 },
         { "lpc", required_argument, &lpc_model, 1 },
         { "lspjnd", no_argument, &lspjnd, 1 },
         { "lspmel", no_argument, &lspmel, 1 },
@@ -160,6 +163,10 @@ int main(int argc, char *argv[])
 
     \*----------------------------------------------------------------*/
 
+    if (argc < 2) {
+        print_help(long_options, num_opts, argv);
+    }
+
     while(1) {
         int option_index = 0;
         int opt = getopt_long(argc, argv, opt_string,
@@ -174,6 +181,8 @@ int main(int argc, char *argv[])
                     fprintf(stderr, "Error Fs must be 8000 or 16000\n");
                     exit(1);
                 }
+            } else if(strcmp(long_options[option_index].name, "mel") == 0) {
+                K = atoi(optarg);
             } else if(strcmp(long_options[option_index].name, "lpc") == 0) {
                 orderi = atoi(optarg);
                 if((orderi < 4) || (orderi > order)) {
@@ -415,11 +424,6 @@ int main(int argc, char *argv[])
 
     nlp_states = nlp_create(&c2const);
 
-    if (argc < 2) {
-        print_help(long_options, num_opts, argv);
-    }
-
-
     ex_phase[0] = 0;
     Woe_[0] = Woe_[1] = 1.0;
 
@@ -466,6 +470,17 @@ int main(int argc, char *argv[])
     prev_model_dec.L = PI/prev_model_dec.Wo;
     prev_model_dec.voiced = 0;
 
+    /* mel resampling experiments */
+
+    float rate_K_sample_freqs_kHz[K];
+    if (mel_resampling) {
+        float mel_start = ftomel(100); 
+        float mel_end = ftomel(0.95*Fs/2);
+        mel_sample_freqs_kHz(rate_K_sample_freqs_kHz, K, mel_start, mel_end);
+        //for(i=0; i<K; i++)
+        //    fprintf(stderr, "%d %f\n", i, rate_K_sample_freqs_kHz[i]);
+    }
+
     /*----------------------------------------------------------------* \
 
                             Main Loop
@@ -554,6 +569,18 @@ int main(int argc, char *argv[])
                model.A[m] = 0.0;
        }
 
+       /*------------------------------------------------------------*\
+
+                            Mel scale resampling
+
+       \*------------------------------------------------------------*/
+
+        if (mel_resampling) {
+            float rate_K_vec[K];
+            resample_const_rate_f(&c2const, &model, rate_K_vec, rate_K_sample_freqs_kHz, K);
+            resample_rate_L(&c2const, &model, rate_K_vec, rate_K_sample_freqs_kHz, K);
+        }
+
        /*------------------------------------------------------------*\
 
                             Zero-phase modelling
@@ -561,21 +588,10 @@ int main(int argc, char *argv[])
        \*------------------------------------------------------------*/
 
        if (phase0) {
-           float Wn[m_pitch];                  /* windowed speech samples */
-           float Rk[order+1];                  /* autocorrelation coeffs  */
-            COMP a[FFT_ENC];
-
             #ifdef DUMP
            dump_phase(&model.phi[0], model.L);
             #endif
 
-           /* find aks here, these are overwritten if LPC modelling is enabled */
-
-            for(i=0; i<m_pitch; i++)
-                Wn[i] = Sn[i]*w[i];
-           autocorrelate(Wn,Rk,m_pitch,order);
-           levinson_durbin(Rk,ak,order);
-
            /* determine voicing */
 
            #if 0
@@ -600,18 +616,6 @@ int main(int argc, char *argv[])
            for(i=0; i<=MAX_AMP; i++)
                model.phi[i] = 0;
 
-            /* Determine DFT of A(exp(jw)), which is needed for phase0 model when
-               LPC is not used, e.g. indecimate=1 (10ms) frames with no LPC */
-
-            for(i=0; i<FFT_ENC; i++) {
-                a[i].real = 0.0;
-                a[i].imag = 0.0;
-            }
-
-            for(i=0; i<=order; i++)
-                a[i].real = ak[i];
-            codec2_fft(fft_fwd_cfg, a, Aw);
-
            if (hand_voicing) {
                int ret = fscanf(fvoicing,"%d\n",&model.voiced);
                 assert(ret == 1);
index 8de9ec7beaeaaba8bff140377a29a6381fe4b021..de79710ca7a6df6d4617e010f553f52bf7f62c37 100644 (file)
@@ -191,7 +191,7 @@ struct CODEC2 * codec2_create(int mode)
     /* newamp1 initialisation */
 
     if (c2->mode == CODEC2_MODE_700C) {
-        mel_sample_freqs_kHz(c2->rate_K_sample_freqs_kHz, NEWAMP1_K);
+        mel_sample_freqs_kHz(c2->rate_K_sample_freqs_kHz, NEWAMP1_K, ftomel(200.0), ftomel(3700.0) );
         int k;
         for(k=0; k<NEWAMP1_K; k++) {
             c2->prev_rate_K_vec_[k] = 0.0;
index 45c39f48ce68b1c36481b6a227970d58a87a5b3c..b2e443732fc8caf41fb8fd33225392c58d29ca76 100644 (file)
@@ -98,9 +98,8 @@ float ftomel(float fHz) {
     return mel;
 }
 
-void mel_sample_freqs_kHz(float rate_K_sample_freqs_kHz[], int K)
+void mel_sample_freqs_kHz(float rate_K_sample_freqs_kHz[], int K, float mel_start, float mel_end)
 {
-    float mel_start = ftomel(200.0); float mel_end = ftomel(3700.0); 
     float step = (mel_end-mel_start)/(K-1);
     float mel;
     int k;
@@ -123,7 +122,7 @@ void mel_sample_freqs_kHz(float rate_K_sample_freqs_kHz[], int K)
 
 \*---------------------------------------------------------------------------*/
 
-void resample_const_rate_f(MODEL *model, float rate_K_vec[], float rate_K_sample_freqs_kHz[], int K)
+void resample_const_rate_f(C2CONST *c2const, MODEL *model, float rate_K_vec[], float rate_K_sample_freqs_kHz[], int K)
 {
     int m;
     float AmdB[MAX_AMP+1], rate_L_sample_freqs_kHz[MAX_AMP+1], AmdB_peak;
@@ -136,7 +135,7 @@ void resample_const_rate_f(MODEL *model, float rate_K_vec[], float rate_K_sample
         if (AmdB[m] > AmdB_peak) {
             AmdB_peak = AmdB[m];
         }
-        rate_L_sample_freqs_kHz[m] = m*model->Wo*4.0/M_PI;
+        rate_L_sample_freqs_kHz[m] = m*model->Wo*(c2const->Fs/2000.0)/M_PI;
         //printf("m: %d AmdB: %f AmdB_peak: %f  sf: %f\n", m, AmdB[m], AmdB_peak, rate_L_sample_freqs_kHz[m]);
     }
     
@@ -327,7 +326,7 @@ void interp_Wo_v(float Wo_[], int L_[], int voicing_[], float Wo1, float Wo2, in
 
 \*---------------------------------------------------------------------------*/
 
-void resample_rate_L(MODEL *model, float rate_K_vec[], float rate_K_sample_freqs_kHz[], int K)
+void resample_rate_L(C2CONST *c2const, MODEL *model, float rate_K_vec[], float rate_K_sample_freqs_kHz[], int K)
 {
    float rate_K_vec_term[K+2], rate_K_sample_freqs_kHz_term[K+2];
    float AmdB[MAX_AMP+1], rate_L_sample_freqs_kHz[MAX_AMP+1];
@@ -347,7 +346,7 @@ void resample_rate_L(MODEL *model, float rate_K_vec[], float rate_K_sample_freqs
    }
 
    for(m=1; m<=model->L; m++) {
-       rate_L_sample_freqs_kHz[m] = m*model->Wo*4.0/M_PI;
+       rate_L_sample_freqs_kHz[m] = m*model->Wo*(c2const->Fs/2000.0)/M_PI;
    }
 
    interp_para(&AmdB[1], rate_K_sample_freqs_kHz_term, rate_K_vec_term, K+2, &rate_L_sample_freqs_kHz[1], model->L);    
@@ -422,7 +421,7 @@ void newamp1_model_to_indexes(C2CONST *c2const,
 
     /* convert variable rate L to fixed rate K */
 
-    resample_const_rate_f(model, rate_K_vec, rate_K_sample_freqs_kHz, K);
+    resample_const_rate_f(c2const, model, rate_K_vec, rate_K_sample_freqs_kHz, K);
 
     /* remove mean and two stage VQ */
 
@@ -592,7 +591,7 @@ void newamp1_indexes_to_model(C2CONST *c2const,
         model_[i].L  = aL_[i];
         model_[i].voiced = avoicing_[i];
 
-        resample_rate_L(&model_[i], &interpolated_surface_[K*i], rate_K_sample_freqs_kHz, K);
+        resample_rate_L(c2const, &model_[i], &interpolated_surface_[K*i], rate_K_sample_freqs_kHz, K);
         determine_phase(c2const, &H[(MAX_AMP+1)*i], &model_[i], NEWAMP1_PHASE_NFFT, fwd_cfg, inv_cfg);
     }
 
index ec9d0f1352e129b8b334b1fc3110ae7449fe6760..e3d526a241a0592fa127d6b730ded36caa90f5ed 100644 (file)
 
 void interp_para(float y[], float xp[], float yp[], int np, float x[], int n);
 float ftomel(float fHz);
-void mel_sample_freqs_kHz(float rate_K_sample_freqs_kHz[], int K);
-void resample_const_rate_f(MODEL *model, float rate_K_vec[], float rate_K_sample_freqs_kHz[], int K);
+void mel_sample_freqs_kHz(float rate_K_sample_freqs_kHz[], int K, float mel_start, float mel_end);
+void resample_const_rate_f(C2CONST *c2const, MODEL *model, float rate_K_vec[], float rate_K_sample_freqs_kHz[], int K);
 float rate_K_mbest_encode(int *indexes, float *x, float *xq, int ndim, int mbest_entries);
 void post_filter_newamp1(float vec[], float sample_freq_kHz[], int K, float pf_gain);
 void interp_Wo_v(float Wo_[], int L_[], int voicing_[], float Wo1, float Wo2, int voicing1, int voicing2);
-void resample_rate_L(MODEL *model, float rate_K_vec[], float rate_K_sample_freqs_kHz[], int K);
+void resample_rate_L(C2CONST *c2const, MODEL *model, float rate_K_vec[], float rate_K_sample_freqs_kHz[], int K);
 void determine_phase(C2CONST *c2const, COMP H[], MODEL *model, int Nfft, codec2_fft_cfg fwd_cfg, codec2_fft_cfg inv_cfg);
 void newamp1_model_to_indexes(C2CONST *c2const,
                               int    indexes[],