acceptable results some mild masking with dif, dit, 16 bit VQmmt1 and htst1a not...
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 4 Apr 2016 21:39:44 +0000 (21:39 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 4 Apr 2016 21:39:44 +0000 (21:39 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2769 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/octave/newamp.m
codec2-dev/octave/newamp_batch.m
codec2-dev/octave/newamp_fbf.m

index 782222fe6249cc313471d38f8f1d3a4d7cc04877..a3ec6b332b6b3b128aeb907e6acd3bc316daec30 100644 (file)
@@ -60,7 +60,7 @@ function [maskdB_ maskdB_cyclic Dabs dk_] = decimate_in_freq(maskdB, cyclic=1, k
 
     Dk = [0 D(2:k-1) real(D(k)) D(L-k+1:L)]; 
     dk = real(ifft(Dk));
-    
+        
     % quantisation
 
     if nargin == 4
@@ -593,8 +593,11 @@ function maskdB = schroeder(freq_tone_kHz, mask_sample_freqs_kHz, bark_model=1)
     % beneath 1.5kHz wider to match the width of F1 and
     % "fill in" the spectra better for UV sounds.
 
-    x1 = 0.5; x2 = 2;
-    y1 = 0.5; y2 = 1;
+    %x1 = 0.5; x2 = 2;
+    %y1 = 0.5; y2 = 1;
+    x1 = 0.5; x2 = 3;
+    y1 = 1; y2 = 3;
+
     grad  = (y2 - y1)/(x2 - x1);
     y_int = y1 - grad*x1;
 
@@ -735,7 +738,7 @@ function maskdB_ = decimate_frame_rate(model, decimate, f, frames, mask_sample_f
     max_amp = 80;
 
     Wo = model(f,1);
-    L = min([model(f,2) max_amp-1]);
+    L = min([model(f,2) max_amp]);
 
     % determine frames that bracket the one we need to interp
 
@@ -755,12 +758,12 @@ function maskdB_ = decimate_frame_rate(model, decimate, f, frames, mask_sample_f
     % fit splines to left and right masks
 
     left_Wo = model(left_f,1);
-    left_L = min([model(left_f,2) max_amp-1]);
+    left_L = min([model(left_f,2) max_amp]);
     left_AmdB = 20*log10(model(left_f,3:(left_L+2)));
     left_mask_sample_freqs_kHz = (1:left_L)*left_Wo*4/pi;
 
     right_Wo = model(right_f,1);
-    right_L = min([model(right_f,2) max_amp-1]);
+    right_L = min([model(right_f,2) max_amp]);
     right_AmdB = 20*log10(model(right_f,3:(right_L+2)));
     right_mask_sample_freqs_kHz = (1:right_L)*right_Wo*4/pi;
 
@@ -797,8 +800,8 @@ function plot_masking
     plot(mask_sample_freqs_kHz, maskdB_s0);
     maskdB_s1 = schroeder(f, mask_sample_freqs_kHz, 1);
     plot(mask_sample_freqs_kHz, maskdB_s1,'g');
-    maskdB_res = parabolic_resonator(f, mask_sample_freqs_kHz);
-    plot(mask_sample_freqs_kHz, maskdB_res,'r');
+    maskdB_res = parabolic_resonator(f, mask_sample_freqs_kHz);
+    plot(mask_sample_freqs_kHz, maskdB_res,'r');
   end
   hold off;
 
index 5258d01b5676d5ff51909ebfc776bc2d7ed52569..3c6db1ed9d9e0f61f305a089f38043f373468351 100644 (file)
@@ -21,12 +21,13 @@ function dk_log = newamp_batch(samname, optional_Am_out_name, optional_Aw_out_na
   more off;
 
   max_amp = 80;
-  dec_in_freq = 0;
-  postfilter = 3;
+  dec_in_freq = 1;
+  postfilter = 0;
   dec_in_time = 1;
   synth_phase = 1;
-  vq_en = 0;
+  vq_en = 1;
   dk_log = [];
+  train = 0;
 
   model_name = strcat(samname,"_model.txt");
   model = load(model_name);
@@ -80,8 +81,10 @@ function dk_log = newamp_batch(samname, optional_Am_out_name, optional_Aw_out_na
     if postfilter == 2
       a_non_masked_m = est_pf_locations(maskdB_);
     end
-    if length(a_non_masked_m)
-      non_masked_m(f,1:length(a_non_masked_m)) = a_non_masked_m;
+    if postfilter
+      if length(a_non_masked_m)
+        non_masked_m(f,1:length(a_non_masked_m)) = a_non_masked_m;
+      end
     end
 
     if postfilter == 3
@@ -89,25 +92,33 @@ function dk_log = newamp_batch(samname, optional_Am_out_name, optional_Aw_out_na
        maskdB_(a_non_masked_m) = maskdB_(a_non_masked_m) + 9;
     end
 
+    AmdB_ = maskdB;
     if dec_in_freq
       if vq_en
-        [maskdB_ tmp1 D dk_] = decimate_in_freq(maskdB_, 1, 7, vq);
+        [AmdB_ tmp1 D dk_] = decimate_in_freq(maskdB, 1, 10, vq);
       else
-        [maskdB_ tmp1 D dk_] = decimate_in_freq(maskdB_, 1);
+        [AmdB_ tmp1 D dk_] = decimate_in_freq(maskdB, 1, 10);
       end
       dk_log = [dk_log; dk_];
-      sd_sum += sum(maskdB - maskdB_);
     end
-
+    AmdB_pf = AmdB_*1.5;
+    AmdB_pf += max(AmdB_) - max(AmdB_pf);
+    %sd_sum += sum(maskdB - AmdB_pf);
+    %AmdB_pf = AmdB_;
 
     Am_ = zeros(1,max_amp);
-    Am_ = 10 .^ (maskdB_(1:L-1)/20); 
+    Am_ = 10 .^ (AmdB_pf(1:L-1)/20); 
     model_(f,3:(L+1)) = Am_;
   end
   printf("\nsd_sum: %5.2f\n", sd_sum/frames);
 
   % decoder loop -----------------------------------------------------
 
+  if train
+    % short circuit decoder
+    frames = 0;
+  end
+
   for f=1:frames
     %printf("frame: %d\n", f);
     L = min([model_(f,2) max_amp-1]);
@@ -192,7 +203,6 @@ function dk_log = newamp_batch(samname, optional_Am_out_name, optional_Aw_out_na
   end
 
   printf("\n");
-
 endfunction
 
 
index 6a7754818f2a66aa2cbc3d7e408c237056f189ac..c3d1bb63289078b24aae9725afc502f0dfabab3e 100644 (file)
@@ -20,7 +20,10 @@ function newamp_fbf(samname, f=10)
   newamp;
   more off;
   plot_spectrum = 1;
+  dec_in_freq = 1;
+  dec_in_time = 0;
   vq_en = 0;
+  mask_en = 0;
 
   % load up text files dumped from c2sim ---------------------------------------
 
@@ -60,74 +63,91 @@ function newamp_fbf(samname, f=10)
     end
 
     [maskdB Am_freqs_kHz] = mask_model(AmdB, Wo, L);
-    [tmp1 tmp2 D] = decimate_in_freq(maskdB, 0);
-    if vq_en
-      [maskdB_ maskdB_cyclic D_cyclic dk_] = decimate_in_freq(maskdB, 1, 7, vq);
+    %a_non_masked_m = find(AmdB > maskdB);
+    %maskdB = maskdB - 6;
+    %maskdB(a_non_masked_m) = maskdB(a_non_masked_m) + 6;
+    %plot(Am_freqs_kHz*1000, maskdB, ';mask;g');
+
+    if mask_en
+      AmdB_ = maskdB;
     else
-      [maskdB_ maskdB_cyclic D_cyclic dk_] = decimate_in_freq(maskdB, 1);
+      AmdB_ = AmdB;
+    end
+    if dec_in_freq
+      [tmp1 tmp2 D] = decimate_in_freq(AmdB, 0);
+      if vq_en
+        [AmdB_ AmdB_cyclic D_cyclic dk_] = decimate_in_freq(AmdB, 1, 10, vq);
+      else
+        [AmdB_ AmdB_cyclic D_cyclic dk_] = decimate_in_freq(AmdB_, 1, 10);
+      end
+
+      plot(Am_freqs_kHz*1000, AmdB_cyclic, ';mask cyclic;b');
+      plot(Am_freqs_kHz*1000, AmdB_, ';mask trunc;c');
+      AmdB_pf = AmdB_*(1.5);
+      AmdB_pf += mean(AmdB) - mean(AmdB_pf);
+      %max(AmdB_pf)-max(AmdB_)
+      %AmdB_pf -= max(AmdB_pf)-max(AmdB_);
     end
 
-    %plot(Am_freqs_kHz*1000, maskdB, ';mask;g');
-    %plot(Am_freqs_kHz*1000, maskdB_cyclic, ';mask cyclic;b');
-    plot(Am_freqs_kHz*1000, maskdB_, ';mask trunated;c');
+    %AmdB_pf = AmdB_*(1.5);
+    %AmdB_pf += mean(AmdB) - mean(AmdB_pf);
+    AmdB_pf = AmdB_;
+    plot(Am_freqs_kHz*1000, AmdB_pf, ';mask trunc pf;g');
 
     % Optional decimated parameters
     %   need to general model_ parameters either side
     
-    decimate = 4;
-    model_ = set_up_model_(model, f, decimate, vq_en, vq);    
-    maskdB_dit = decimate_frame_rate(model_, decimate, f, frames, Am_freqs_kHz);
-    plot(Am_freqs_kHz*1000, maskdB_dit, ';mask dit;b');
-
-    % post filter locations
-
-    a_non_masked_m = find(AmdB > maskdB);
-    nmf = a_non_masked_m*4000*Wo/pi;
-    plot(nmf, AmdB(a_non_masked_m)+3, ';pf mask;g+');
-
-    tp = est_pf_locations(maskdB_);
-    nmf = tp*4000*Wo/pi;
-    plot(nmf, AmdB(tp)+6, ';pf trunc;c+');
-
-    tp = est_pf_locations(maskdB_dit);
-    nmf = tp*4000*Wo/pi;
-    plot(nmf, AmdB(tp)+9, ';pf dit;b+');
-
-    hold off;
-
-    % lets get a feel for the "spectrum" of the smoothed spectral envelope
-    % this will give us a feel for how hard it is to code, ideally we would like
-    % just a few coefficents to be non-zero
-
-    figure(3)
-    clf
-
-    en = L/2+1;
-    stem(D(2:en),'g')
-    hold on;
-    stem(D_cyclic(2:en),'b')
-    hold off;
-
-    % let plot the cumulative amount of energy in each DFT
+    if dec_in_time
+      decimate = 4;
+      model_ = set_up_model_(model, f, decimate, vq_en, vq);    
+      maskdB_dit = decimate_frame_rate(model_, decimate, f, frames, Am_freqs_kHz);
+      plot(Am_freqs_kHz*1000, maskdB_dit, ';mask dit;b');
+    end
 
-    figure(4)
-    clf
-    plot(cumsum(D(2:en)/sum(D(2:en))),';cumsum;g');
-    hold on;
-    plot(cumsum(D_cyclic(2:en)/sum(D_cyclic(2:en))),';cumsum cyclic;b');
     hold off;
-    axis([1 L 0 1])
 
-    figure(5)
-    clf
-    stem(dk_)
+    if dec_in_freq
+      % lets get a feel for the "spectrum" of the smoothed spectral envelope
+      % this will give us a feel for how hard it is to code, ideally we would like
+      % just a few coefficents to be non-zero
+
+      figure(3)
+      clf
+
+      en = L/2+1;
+      stem(D(2:en),'g')
+      hold on;
+      stem(D_cyclic(2:en),'b')
+      hold off;
+
+      % let plot the cumulative amount of energy in each DFT
+
+      figure(4)
+      clf
+      plot(cumsum(D(2:en)/sum(D(2:en))),';cumsum;g');
+      hold on;
+      plot(cumsum(D_cyclic(2:en)/sum(D_cyclic(2:en))),';cumsum cyclic;b');
+      hold off;
+      axis([1 L 0 1])
+
+      figure(5)
+      clf
+      stem(dk_)
+    end
 
     % interactive menu ------------------------------------------
 
-    printf("\rframe: %d  menu: n-next  b-back q-quit", f);
+    printf("\rframe: %d  menu: n-next  b-back  q-quit  m-mask_en", f);
     fflush(stdout);
     k = kbhit();
 
+    if (k == 'm')
+      if mask_en
+        mask_en = 0;
+      else
+        mask_en = 1; 
+      end
+    endif
     if (k == 'n')
       f = f + 1;
     endif
@@ -162,18 +182,20 @@ function amodel_row = set_up_maskdB_(model, f, vq_en, vq)
   L = model(f,2);
   Am = model(f,3:(L+2));
   AmdB = 20*log10(Am);
-  [maskdB Am_freqs_kHz] = mask_model(AmdB, Wo, L);
 
+  [maskdB Am_freqs_kHz] = mask_model(AmdB, Wo, L);
   a_non_masked_m = find(AmdB > maskdB);
-  maskdB_pf = maskdB - 6;
-  maskdB_pf(a_non_masked_m) = maskdB_pf(a_non_masked_m) + 6;
-  maskdB = maskdB_pf;
+  maskdB = maskdB - 6;
+  maskdB(a_non_masked_m) = maskdB(a_non_masked_m) + 6;
 
+  if 0
   if vq_en
     maskdB_ = decimate_in_freq(maskdB, 1, 7, vq);
   else
     maskdB_ = decimate_in_freq(maskdB, 1);
   end
+  end
+
   maskdB_ = maskdB;
   
   amodel_row = zeros(1,nc);