removed debug printfs, starting to refactor rx functions
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 11 Jan 2017 03:17:45 +0000 (03:17 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 11 Jan 2017 03:17:45 +0000 (03:17 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2957 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/octave/mag_to_phase.m
codec2-dev/octave/newamp.m
codec2-dev/octave/tnewamp1.m
codec2-dev/src/newamp1.c
codec2-dev/src/newamp1.h
codec2-dev/src/phase.c
codec2-dev/unittest/tnewamp1.c

index 0eac133fc394a0507def21bebc238524e2d204b7..c81ed087cd0556979757c2117c193d2bca15fef7 100644 (file)
@@ -30,28 +30,8 @@ function [phase s] = mag_to_phase(Gdbfk, Nfft = 512, verbose_en = 0)
     end
   end
 
-  printf("  Sdb..: ");
-  for i=1:5
-      printf("%5.2f ", real(Sdb(i)));
-  end
-  printf("\n         ");
-  for i=1:5
-      printf("%5.2f ", imag(Sdb(i)));
-  end
-  printf("\n");
-
   c = ifft(Sdb); % compute real cepstrum from log magnitude spectrum
  
-  printf("  c....: ");
-  for i=1:5
-      printf("%5.2f ", real(c(i)));
-  end
-  printf("\n         ");
-  for i=1:5
-      printf("%5.2f ", imag(c(i)));
-  end
-  printf("\n");
-
   % Check aliasing of cepstrum (in theory there is always some):
 
   caliaserr = 100*norm(c(round(Ns*0.9:Ns*1.1)))/norm(c);
index 60b358ffbb407c1f7e990d87d604ca52a6386a02..010893425731489a11f703f6317d9462138a9e50 100644 (file)
@@ -149,17 +149,6 @@ function [phase Gdbfk s Aw] = determine_phase(model, f, Nfft=512, ak)
   rate_L_sample_freqs_kHz = (1:L)*Wo*4/pi;
   Gdbfk = interp_para(rate_L_sample_freqs_kHz, AmdB, sample_freqs_kHz);    
 
-  printf("  AmdB.: ");
-  for m=1:5
-    printf("%5.2f ", AmdB(m));
-  end
-  printf("\n");
-  printf("  Gdbfk: ");
-  for m=1:5
-    printf("%5.2f ", Gdbfk(m));
-  end
-  printf("\n");
-
   % Gdbfk = resample_mask(model, f, mask_sample_freqs_kHz);
 
   % optional input of aks for testing
index 10ee9be37bad8357ee17b0227bfc4be59cee4a0f..2f9ba7d9dffc01cfbb41bca7f117d3e87ce7bede 100644 (file)
@@ -126,33 +126,13 @@ function tnewamp1(input_prefix)
       
       for k=f-M:f-1
         model_(k,:) = resample_rate_L(model_(k,:), interpolated_surface_(k,:), sample_freqs_kHz);
-        printf("\n");
-        printf("frame: %d Wo: %4.3f L: %d\n", k, model_(k,1), model_(k,2));
         phase = determine_phase(model_, k, Nfft_phase);
-        printf("  phase: ");
-        for i=1:5
-          printf("%5.2f ", phase(i));
-        end
-        printf("\n");
-        printf("  b....: ");
         for m=1:model_(k,2)
           b = round(m*model_(k,1)*Nfft_phase/(2*pi));  % map harmonic centre to DFT bin
-          if m <= 5
-            printf("%5d ", b);
-          end
           phi(m) = phase(b+1);
           Hm(k,m) = exp(-j*phi(m));
         end  
-        printf("\n");
-        printf("  phi..: ");
-        for m=1:5
-          printf("%5.2f ", phi(m));
-        end
-        printf("\n");
-        %if k == 2
-        %  xx
-        %end
-     
+   
       end
     end
   end
@@ -168,10 +148,6 @@ function tnewamp1(input_prefix)
 
 
   %Hm(2,:) - Hm_c(2,:)
-  for f=1:frames
-    s = abs(sum(Hm(f,:) - Hm_c(f,:)));
-    printf("f: %d s: %f \n", f, s);
-  end
   
   figure(1);
   mesh(angle(Hm));
index 260255434132644da2f9ea003b086e422617f626..a1f1a397c4b87467ba0ecf205b63a6fbc210cdca 100644 (file)
@@ -41,7 +41,6 @@
 #include "newamp1.h"
 
 #define NEWAMP1_VQ_MBEST_DEPTH 5  /* how many candidates we keep for each stage of mbest search */
-#define NEWAMP1_VQ_STAGES   2     /* hard coded two stage VQ */
 
 /*---------------------------------------------------------------------------*\
 
@@ -373,15 +372,10 @@ void determine_phase(MODEL *model, int Nfft, codec2_fft_cfg fwd_cfg, codec2_fft_
     float Gdbfk[Ns], sample_freqs_kHz[Ns], phase[Ns];
     float AmdB[MAX_AMP+1], rate_L_sample_freqs_kHz[MAX_AMP+1];
 
-    printf("  AmdB.: ");
     for(m=1; m<=model->L; m++) {
         AmdB[m] = 20.0*log10(model->A[m]);
         rate_L_sample_freqs_kHz[m] = (float)m*model->Wo*4.0/M_PI;
-        if (m <=5) {
-            printf("%5.2f ", AmdB[m]);
-        }
     }
-    printf("\n");
     
     for(i=0; i<Ns; i++) {
         sample_freqs_kHz[i] = (FS/1000.0)*(float)i/Nfft;
@@ -389,28 +383,12 @@ void determine_phase(MODEL *model, int Nfft, codec2_fft_cfg fwd_cfg, codec2_fft_
 
     interp_para(Gdbfk, &rate_L_sample_freqs_kHz[1], &AmdB[1], model->L, sample_freqs_kHz, Ns);
 
-    printf("  Gdbfk: ");
-    for(i=0; i<5; i++) {
-        printf("%5.2f ", Gdbfk[i]);
-    }
-    printf("\n");
-
     mag_to_phase(phase, Gdbfk, Nfft, fwd_cfg, inv_cfg);
 
-    printf("  b....: ");
     for(m=1; m<=model->L; m++) {
         b = floorf(0.5+m*model->Wo*Nfft/(2.0*M_PI));
         model->phi[m] = phase[b];
-        if (m <= 5) {
-            printf("%5d ", b);
-        }
-    }
-    printf("\n");
-    printf("  phi..: ");
-    for(m=1; m<=5; m++) {
-        printf("% 5.2f ", model->phi[m]);
     }
-    printf("\n");
 }
 
 
@@ -455,12 +433,27 @@ void newamp1_model_to_indexes(int    indexes[],
 
     float w[1] = {1.0};
     float se;
-    indexes[NEWAMP1_VQ_STAGES] = quantise(newamp1_energy_cb[0].cb, 
-                                          mean, 
-                                          w, 
-                                          newamp1_energy_cb[0].k, 
-                                          newamp1_energy_cb[0].m, 
-                                          &se);
+    indexes[2] = quantise(newamp1_energy_cb[0].cb, 
+                          mean, 
+                          w, 
+                          newamp1_energy_cb[0].k, 
+                          newamp1_energy_cb[0].m, 
+                          &se);
+
+    /* scalar quantise Wo.  We steal the smallest Wo index to signal
+       an unvoiced frame */
+
+    if (model->voiced) {
+        int index = encode_log_Wo(model->Wo, 6);
+        if (index == 0) {
+            index = 1;
+        }
+        indexes[3] = index;
+    }
+    else {
+        indexes[3] = 0;
+    }
+
  }
 
 
@@ -494,7 +487,7 @@ void newamp1_indexes_to_model(float  rate_K_vec_[],
 
     post_filter_newamp1(rate_K_vec_no_mean_, rate_K_sample_freqs_kHz, K, 1.5);
 
-    *mean_ = newamp1_energy_cb[0].cb[indexes[NEWAMP1_VQ_STAGES]];
+    *mean_ = newamp1_energy_cb[0].cb[indexes[2]];
 
     for(k=0; k<K; k++) {
         rate_K_vec_[k] = rate_K_vec_no_mean_[k] + *mean_;
index fe59d8989c6c4895bf5718ec85d303ea86232453..058d0c5c34aecf34900bced0c14a570bbe3295e2 100644 (file)
@@ -30,6 +30,8 @@
 #ifndef __NEWAMP1__
 #define __NEWAMP1__
 
+#define NEWAMP1_N_INDEXES 4 /* Number of indexes to pack: vq1, vq2, energy, Wo */
+
 #include "codec2_fft.h"
 #include "comp.h"
 
index 0268bc3133086d44fd01f8890e1b640f48c265a8..4a4bee55d3d76bd2c62710bb408a006e844c4028 100644 (file)
@@ -250,16 +250,6 @@ void mag_to_phase(float phase[],             /* Nfft/2+1 output phase samples in
         Sdb[i].imag = Sdb[Nfft-i].imag = 0.0;
     }
 
-    printf("  Sdb..: ");
-    for(i=0; i<5; i++) {
-        printf("%5.2f ", Sdb[i].real);
-    }
-    printf("\n         ");
-    for(i=0; i<5; i++) {
-        printf("%5.2f ", Sdb[i].imag);
-    }
-    printf("\n");
-
     /* compute real cepstrum from log magnitude spectrum */
 
     codec2_fft(fft_inv_cfg, Sdb, c);
@@ -268,21 +258,6 @@ void mag_to_phase(float phase[],             /* Nfft/2+1 output phase samples in
         c[i].imag /= (float)Nfft;
     }
 
-    printf("  c....: ");
-    for(i=0; i<5; i++) {
-        printf("%5.2f ", c[i].real);
-    }
-    printf("\n         ");
-    for(i=0; i<5; i++) {
-        printf("%5.2f ", c[i].imag);
-    }
-    printf("\n");
-    /*
-    for(i=0; i<Nfft; i++) {
-        printf("i: %d c: %f %f\n", i, c[i].real, c[i].imag);
-    }
-    */
-
     /* Fold cepstrum to reflect non-min-phase zeros inside unit circle */
 
     cf[0] = c[0];
@@ -309,9 +284,4 @@ void mag_to_phase(float phase[],             /* Nfft/2+1 output phase samples in
         phase[i] = Cf[i].imag/scale;
     }
     
-    printf("  phase: ");
-    for(i=0; i<5; i++) {
-        printf("%5.2f ", phase[i]);
-    }
-    printf("\n");
 }
index 36fea32484761faaedc85d18a36bf0b7a95b49ca..ad5d52bd7f531c439209cd57f4651b33b8682fdb 100644 (file)
@@ -83,6 +83,7 @@ int main(int argc, char *argv[]) {
     int   voicing_[FRAMES];
     float model_octave_[FRAMES][MAX_AMP+2];
     COMP  Hm[FRAMES][MAX_AMP];
+    int indexes[FRAMES][NEWAMP1_N_INDEXES];
 
     for(f=0; f<FRAMES; f++) {
         for(m=0; m<MAX_AMP+2; m++) {
@@ -136,8 +137,7 @@ int main(int argc, char *argv[]) {
 
         /* newamp1 processing ----------------------------------------*/
 
-        int indexes[3];
-        newamp1_model_to_indexes(indexes, 
+        newamp1_model_to_indexes(&indexes[f][0], 
                                  &model, 
                                  &rate_K_surface[f][0], 
                                  rate_K_sample_freqs_kHz,
@@ -151,7 +151,7 @@ int main(int argc, char *argv[]) {
                                  rate_K_sample_freqs_kHz,
                                  K,
                                  &mean_[f],
-                                 indexes);
+                                 &indexes[f][0]);
 
         /* log vectors */
  
@@ -169,6 +169,7 @@ int main(int argc, char *argv[]) {
 
     for(f=0; f<FRAMES; f+=M) {
 
+#ifdef TMP1
         /* Quantise Wo. V/UV flag is coded using a zero index for Wo,
            this means we need to adjust Wo index slightly for the
            lowest Wo V frames */
@@ -183,7 +184,23 @@ int main(int argc, char *argv[]) {
         else {
             model_octave_[f][0] = 2.0*M_PI/100.0;
         }
+#endif
 
+        if (indexes[f][3]) {
+            model_octave_[f][0] = decode_log_Wo(indexes[f][3], 6);
+        }
+        else {
+            model_octave_[f][0] = 2.0*M_PI/100.0;
+        }
+
+        /*
+          pass in left and right rate K vectors, Wo, v
+          interpolate at rate K
+          convert to rate L
+          output 4 model parameters
+          ref indexes to 0...3
+          slowly change
+        */
         float c;
         if (f >= M) {
 
@@ -216,8 +233,8 @@ int main(int argc, char *argv[]) {
                 model_.Wo = model_octave_[i][0];
                 model_.L  = model_octave_[i][1];
                 resample_rate_L(&model_, &interpolated_surface_[i][0], rate_K_sample_freqs_kHz, K);
-                printf("\n");
-                printf("frame: %d Wo: %4.3f L: %d\n", i+1, model_.Wo, model_.L);
+                //printf("\n");
+                //printf("frame: %d Wo: %4.3f L: %d\n", i+1, model_.Wo, model_.L);
                 determine_phase(&model_, PHASE_NFFT, phase_fft_fwd_cfg, phase_fft_inv_cfg);
                 //if (i == 1) {
                 //    exit(0);