about to refactor for a mbest search
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 23 Mar 2016 23:42:03 +0000 (23:42 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 23 Mar 2016 23:42:03 +0000 (23:42 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2757 01035d8c-6547-0410-b346-abe4f91aad63

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

index def043813264f6e635509748b1e11708af117742..bb657753faffadb78ee5db8cc29aa15e00f83df9 100644 (file)
@@ -29,6 +29,7 @@
 %   [ ] phase model?  Fit LPC, just swing phase at peaks? Try no phase tweaks
 
 1;
+melvq;
 
 % Create a "decimated mask" model using just a few samples of
 % critical band filter centre frequencies.  For voiced speech,
@@ -147,25 +148,29 @@ end
 % Ahh, takes me back to when I was a slip of a speech coder, playing
 % with my first CELP codec!
 
-function [decmaskdB masker_freqs_kHz min_error mse_log1 mse_log2] = make_decmask_abys(maskdB, AmdB, Wo, L, mask_sample_freqs_kHz, freq_quant, amp_quant, pp_bw)
+function [decmaskdB masker_freqs_kHz masker_amps_dB min_error mse_log1 ] = make_decmask_abys(maskdB, AmdB, Wo, L, mask_sample_freqs_kHz, freq_quant, amp_quant)
 
     Nsamples = 4;
 
     % search range
 
-    m_st = 1;
+    f_min = 0;
+    f0 = Wo*4000/pi;
+    m_st = max(1, round(f_min/f0));
     m_en = L;
 
     target = maskdB;
     dec_samples = [];
-    mse_log1 = mse_log2 = zeros(Nsamples, L);
+    mse_log1 = zeros(Nsamples, L);
 
-    % This step quite important.  Set noise floor to avoid washing machine/tinkling
-    % sounds with bg noise as chunks of spectrum come and go.  The masking model
-    % basis functions are not gd at representing continuous spectra, especially at 
-    % LF.  Fortunately rather gd at voiced speech, which is a much tougher job.
+    % load VQ file if necc
+
+    if (freq_quant == 2) || (amp_quant == 3)
+      load newamp_vq;
+    end
+
+    % set some sort of noise floor
 
-    % decmaskdB = 20*ones(1,L);
     decmaskdB = zeros(1,L);
 
     for sample=1:Nsamples
@@ -177,10 +182,10 @@ function [decmaskdB masker_freqs_kHz min_error mse_log1 mse_log2] = make_decmask
       min_mse = 1E32;
 
       for m=m_st:m_en
-        %single_mask_m = schroeder(m*Wo*4/pi, mask_sample_freqs_kHz,0) + AmdB(m);
+        single_mask_m = schroeder(m*Wo*4/pi, mask_sample_freqs_kHz,1) + AmdB(m);
         %single_mask_m = resonator_fast(pp_bw, m*Wo*4/pi, mask_sample_freqs_kHz) + AmdB(m);
         %single_mask_m = resonator( m*Wo*4/pi, mask_sample_freqs_kHz) + AmdB(m);
-        single_mask_m = parabolic_resonator(m*Wo*4/pi, mask_sample_freqs_kHz) + AmdB(m);
+        %single_mask_m = parabolic_resonator(m*Wo*4/pi, mask_sample_freqs_kHz) + AmdB(m);
         candidate = max(decmaskdB, single_mask_m);
         error = target - candidate;
         mse_log1(sample,m) = mse = sum(abs(error)); % MSE in log domain
@@ -221,7 +226,7 @@ function [decmaskdB masker_freqs_kHz min_error mse_log1 mse_log2] = make_decmask
 
     % Differential Freq Quantisers - sounds acceptable
 
-    if freq_quant
+    if freq_quant == 1
            
       % first freq quant to harmonic number m=1:8
 
@@ -241,11 +246,21 @@ function [decmaskdB masker_freqs_kHz min_error mse_log1 mse_log2] = make_decmask
        decmaskdB = determine_mask(masker_amps_dB,  masker_freqs_kHz, mask_sample_freqs_kHz);
     end
 
+
+    % Freq Vector Quantiser
+
+    if freq_quant == 2
+      [res masker_freqs_kHz ind] = mbest(fvq, masker_freqs_kHz', 2);
+      std(res)
+      decmaskdB = determine_mask(masker_amps_dB,  masker_freqs_kHz, mask_sample_freqs_kHz);
+    end
+
+
     % Amplitude quantisation by fitting a straight line -------------------------
     % amp_quant == 1: high rate, quantise deltas
     % amp_quant == 2: low rate, don't quantise deltas
 
-    if amp_quant > 0
+    if (amp_quant == 1) || (amp_quant == 2)
 
       % Fit straight line
 
@@ -301,6 +316,15 @@ function [decmaskdB masker_freqs_kHz min_error mse_log1 mse_log2] = make_decmask
       decmaskdB = determine_mask(masker_amps_dB,  masker_freqs_kHz, mask_sample_freqs_kHz);
     end
 
+
+    % Amplitude vector quantiser
+
+    if amp_quant == 3
+      [res masker_amps_dB ind] = mbest(avq, masker_amps_dB', 2);
+      std(res)
+      decmaskdB = determine_mask(masker_amps_dB,  masker_freqs_kHz, mask_sample_freqs_kHz);
+    end
+
     if 0
     printf("\n");
     for i=1:Nsamples
@@ -518,7 +542,7 @@ function maskdB = parabolic_resonator(freq_tone_kHz, mask_sample_freqs_kHz)
   m1 = 2*delta/Fs;
 
   maskdB_par  = a*((mask_sample_freqs_kHz - freq_tone_kHz).^2);
-  maskdB_line = m1*abs(mask_sample_freqs_kHz - freq_tone_kHz) - 20;
+  maskdB_line = m1*abs(mask_sample_freqs_kHz - freq_tone_kHz) - 10;
 
   maskdB = max(maskdB_par, maskdB_line);
 endfunction
index 04da8ba67010ef48e530a206ab1faf56ea25b529..1ec2b4a93fee5f4f902d063d475e4379010bee14 100644 (file)
@@ -25,8 +25,8 @@ function [non_masked_f_log non_masked_amp_log] = newamp_batch(samname, optional_
   postfilter = 1;
   decimate_in_time = 1;
   synth_phase = 1;
-  freq_quant = 0;
-  amp_quant = 0;
+  freq_quant = 2;
+  amp_quant = 3;
   non_masked_f_log = [];
   non_masked_m_log = [];
   non_masked_amp_log = [];
@@ -56,7 +56,7 @@ function [non_masked_f_log non_masked_amp_log] = newamp_batch(samname, optional_
 
   % encoder loop ------------------------------------------------------
 
-  pp_bw = gen_pp_bw;
+  %pp_bw = gen_pp_bw;
 
   for f=1:frames
     printf("%d ", f);   
@@ -73,17 +73,17 @@ function [non_masked_f_log non_masked_amp_log] = newamp_batch(samname, optional_
 
     if decimate_in_freq
       % decimate mask samples in frequency
-      [decmaskdB masker_freqs_kHz] = make_decmask_abys(maskdB, AmdB, Wo, L, mask_sample_freqs_kHz, freq_quant, amp_quant, pp_bw);
-      non_masked_amp = decmaskdB;
+      [decmaskdB masker_freqs_kHz masker_amps_dB ] = make_decmask_abys(maskdB, AmdB, Wo, L, mask_sample_freqs_kHz, freq_quant, amp_quant);
+      non_masked_amp = masker_amps_dB ;
       non_masked_amp_log = [non_masked_amp_log; non_masked_amp'];
 
       % Save this for decoder, so it knows where to apply post filter
       % Basically the frequencies of the AbyS samples
 
       non_masked_m(f,:) = min(round(masker_freqs_kHz/(Wo*4/pi)),L);
-
       non_masked_m_log = [non_masked_m_log; non_masked_m(f,:)'];
-      non_masked_f_log = [non_masked_f_log; masker_freqs_kHz];
+
+      non_masked_f_log = [non_masked_f_log; masker_freqs_kHz'];
       maskdB_ = decmaskdB;
     else
       % just approximate decimation in freq by using those mask samples we can hear
@@ -97,7 +97,6 @@ function [non_masked_f_log non_masked_amp_log] = newamp_batch(samname, optional_
     model_(f,3:(L+1)) = Am_;
   end
 
   % decoder loop -----------------------------------------------------
 
   for f=1:frames
index 9b6ac79685764cb389cd72f49b825163d6edbdd6..cf98b806c2f2201ed1d62538152b8a5d29bf0929 100644 (file)
@@ -39,7 +39,7 @@ function newamp_fbf(samname, f=10)
     ak = load(ak_name);
   end
 
-  pp_bw = gen_pp_bw;
+  pp_bw = gen_pp_bw;
 
   plot_all_masks = 0;
   k = ' ';
@@ -86,7 +86,7 @@ function newamp_fbf(samname, f=10)
     % decimate in frequency
 
     mask_sample_freqs_kHz = (1:L)*Wo*4/pi;
-    [decmaskdB masker_freqs_kHz min_error mse_log1 mse_log2] = make_decmask_abys(maskdB, AmdB, Wo, L, mask_sample_freqs_kHz, freq_quant, amp_quant, pp_bw);
+    [decmaskdB masker_freqs_kHz masker_amps_dB min_error mse_log1] = make_decmask_abys(maskdB, AmdB, Wo, L, mask_sample_freqs_kHz, freq_quant, amp_quant);
 
     % find turning points - prototype for finding PF freqs when we decimate in time