better naming conventions and framework for comparing output vectors as we refactor...
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 27 Dec 2016 00:01:48 +0000 (00:01 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 27 Dec 2016 00:01:48 +0000 (00:01 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2946 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/octave/newamp1_batch.m
codec2-dev/octave/newamp1_compare.m [new file with mode: 0644]

index 65da0ddfbf6016c904c9ec203c0c48542b6c3456..d72d62b6ee10992be0f6d6eb94fd9b68f89db292 100644 (file)
@@ -40,7 +40,7 @@
 % In general, this function processes a bunch of amplitudes, we then
 % use c2sim to hear the results.  Bunch of different experiments below
 
-function surface = newamp1_batch(samname, optional_Am_out_name, optional_Aw_out_name)
+function surface = newamp1_batch(input_prefix, output_prefix)
   newamp;
   more off;
 
@@ -48,11 +48,14 @@ function surface = newamp1_batch(samname, optional_Am_out_name, optional_Aw_out_
   postfilter = 0;   % optional postfiler that runs on Am, not used atm
   synth_phase = 1;
 
-  model_name = strcat(samname,"_model.txt");
+  if nargin == 1
+    output_prefix = input_prefix;
+  end
+  model_name = strcat(input_prefix,"_model.txt");
   model = load(model_name);
   [frames nc] = size(model);
 
-  voicing_name = strcat(samname,"_pitche.txt");
+  voicing_name = strcat(input_prefix,"_pitche.txt");
   voicing = zeros(1,frames);
   
   if exist(voicing_name, "file") == 2
@@ -79,19 +82,14 @@ function surface = newamp1_batch(samname, optional_Am_out_name, optional_Aw_out_
 
   % ----------------------------------------------------
 
-  if nargin == 2
-    Am_out_name = optional_Am_out_name;
-  else
-    Am_out_name = sprintf("%s_am.out", samname);
-  end
-
+  Am_out_name = sprintf("%s_am.out", output_prefix);
   fam  = fopen(Am_out_name,"wb"); 
 
-  Wo_out_name = sprintf("%s_Wo.out", samname);
+  Wo_out_name = sprintf("%s_Wo.out", output_prefix);
   fWo  = fopen(Wo_out_name,"wb"); 
   
   if synth_phase
-    Aw_out_name = sprintf("%s_aw.out", samname);
+    Aw_out_name = sprintf("%s_aw.out", output_prefix);
     faw = fopen(Aw_out_name,"wb"); 
   end
 
@@ -141,7 +139,7 @@ function surface = newamp1_batch(samname, optional_Am_out_name, optional_Aw_out_
   % save voicing file
   
   if exist("voicing_", "var")
-    v_out_name = sprintf("%s_v.txt", samname);
+    v_out_name = sprintf("%s_v.txt", output_prefix);
     fv  = fopen(v_out_name,"wt"); 
     for f=1:length(voicing_)
       fprintf(fv,"%d\n", voicing_(f));
@@ -408,7 +406,7 @@ function [model_ voicing_] = model_from_indexes(indexes)
 
   % enable these to use original (non interpolated) voicing and Wo
   %voicing_ = voicing;
-  %model_(:,1) = model(:,1);
+   %model_(:,1) = model(:,1);
 
   model_(:,2) = floor(pi ./ model_(:,1)); % calculate L for each interpolated Wo
   model_ = resample_rate_L(model_, interpolated_surface_, sample_freqs_kHz);
diff --git a/codec2-dev/octave/newamp1_compare.m b/codec2-dev/octave/newamp1_compare.m
new file mode 100644 (file)
index 0000000..497c7aa
--- /dev/null
@@ -0,0 +1,54 @@
+% newamp1_compare.m
+%
+% Copyright David Rowe 2016
+% This program is distributed under the terms of the GNU General Public License 
+% Version 2
+%
+% Compare model, Wo, and voicing files, used for checking refactoring and C port
+
+
+function newamp1_compare(prefixa, prefixb)
+  autotest;
+
+  frames = 100;
+  a = load_params(prefixa, frames);
+  b = load_params(prefixb, frames);
+  check(a.Am, b.Am, 'Am');
+  check(a.Aw, b.Aw, 'Aw');
+  check(a.Wo, b.Wo, 'Wo');
+  check(a.v, b.v, 'v');
+endfunction
+
+
+function params = load_params(prefix, frames)
+  max_amp = 80;
+  fft_enc = 512;
+
+  Am_out_name = sprintf("%s_am.out", prefix);
+  fam  = fopen(Am_out_name,"rb");
+  Wo_out_name = sprintf("%s_Wo.out", prefix);
+  fWo  = fopen(Wo_out_name,"rb"); 
+  Aw_out_name = sprintf("%s_aw.out", prefix);
+  faw = fopen(Aw_out_name,"rb"); 
+
+  % load up values from binary files
+
+  params.Am = zeros(frames, max_amp);
+  params.Wo = zeros(frames, 1);
+  params.v = zeros(frames, 1);
+  params.Aw = zeros(frames, fft_enc);
+  for f=1:frames
+    params.Am(f,:) = fread(fam, max_amp, "float32");
+    params.Wo(f)   = fread(fWo, 1, "float32");
+    params.Aw(f,:) = fread(faw, fft_enc, "float32");
+  end
+
+  fclose(fam); fclose(fWo); fclose(faw);
+
+  % voicing is a text file
+
+  v_out_name = sprintf("%s_v.txt", prefix);
+  params.v = load(v_out_name);
+
+endfunction