% Octave script to batch process model parameters using the new
% amplitude model. Used for generating samples we can listen to.
%
-% Usage:
-% ~/codec2-dev/build_linux/src$ ./c2sim ../../raw/hts1a.raw --dump hts1a
-% $ cd ~/codec2-dev/octave
-% octave:14> newamp1_batch("../build_linux/src/hts1a")
-% ~/codec2-dev/build_linux/src$ ./c2sim ../../raw/hts1a.raw --amread hts1a_am.out -o - | play -t raw -r 8000 -s -2 -
-% Or with a little more processing:
-% codec2-dev/build_linux/src$ ./c2sim ../../raw/hts2a.raw --amread hts2a_am.out --awread hts2a_aw.out --phase0 --postfilter --Woread hts2a_Wo.out -o - | play -q -t raw -r 8000 -s -2 -
+
+#{
+
+ Usage:
+
+ ~/codec2-dev/build_linux/src$ ./c2sim ../../raw/hts1a.raw --dump hts1a
+ $ cd ~/codec2-dev/octave
+ octave:14> newamp1_batch("../build_linux/src/hts1a")
+ ~/codec2-dev/build_linux/src$ ./c2sim ../../raw/hts1a.raw --amread hts1a_am.out -o - | play -t raw -r 8000 -s -2 -
+
+ Or with a little more processing, first dump energy and voicing, the import Wo, voicing, phase spectra:
+
+ $ ./c2sim ../../raw/vk5qi.raw --phase0 --postfilter --dump vk5qi --lpc 10 --dump_pitch_e vk5qi_pitche.txt
+ octave:14> newamp1_batch("../build_linux/src/vk5qi", "../build_linux/src/vk5qi_am_Wo.out");
+ $ ./c2sim ../../raw/vk5qi.raw --phase0 --postfilter --amread vk5qi_am_Wo.out --awread vk5qi_aw.out --Woread vk5qi_Wo.out --hand_voicing vk5qi_v.txt -o - | play -q -t raw -r 8000 -s -2 -
+
+#}
+
% process a whole file and write results
% TODO:
%[model_ surface] = experiment_mel_freq(model, 1, 1, voicing);
%model_ = experiment_dec_abys(model, 8, 1, 1, 1, voicing);
- [model_ voicing_] = experiment_rate_K_dec(model, voicing);
+ [model_ voicing_ indexes] = experiment_rate_K_dec(model, voicing);
+ indexes
%model_ = experiment_dec_linear(model_);
%model_ = experiment_energy_rate_linear(model, 1, 0);
% Linear decimator/interpolator that operates at rate K, includes VQ, post filter, and Wo/E
% quantisation. Evevoled from abys decimator below.
-function [model_ voicing_ ] = experiment_rate_K_dec(model, voicing)
+function [model_ voicing_ indexes] = experiment_rate_K_dec(model, voicing)
max_amp = 80;
[frames nc] = size(model);
model_ = zeros(frames, max_amp+3);
-
+ indexes = zeros(frames,4);
+
M = 8;
% create frames x K surface. TODO make all of this operate frame by
end
[res surface_no_mean_ ind] = mbest(train_120_vq, surface_no_mean, m);
+ indexes(:,1:2) = ind;
for f=1:frames
surface_no_mean_(f,:) = post_filter(surface_no_mean_(f,:), sample_freqs_kHz, 1.5);
end
surface_ = zeros(frames, K);
- for f=1:frames
- surface_(f,:) = surface_no_mean_(f,:) + mean_f(f);
+ energy_q = 10 + 40/16*(0:15)
+ for f=1:frames
+ [mean_f_ indx] = quantise(energy_q, mean_f(f));
+ indexes(f,3) = indx - 1;
+ %mean_f_ = mean_f(f);
+ surface_(f,:) = surface_no_mean_(f,:) + mean_f_;
end
% break into segments of M frames. We have 3 samples in M frame
% segment spaced M/2 apart and interpolate the rest. This evolved
% from AbyS scheme below but could be simplified to simple linear
% interpolation, or using 3 or 4 points but shift of M/2=4 frames.
-
+
interpolated_surface_ = zeros(frames, K);
for f=1:M:frames-M
left_vec = surface_(f,:);
voicing_ = zeros(1, frames);
for f=1:M/2:frames-M/2
+ % quantise Wo
+
+ index = encode_log_Wo(model(f,1), 6);
+ Wo1_ = decode_log_Wo(index, 6);
+ indexes(f,4) = index;
+ index = encode_log_Wo(model(f+M/2,1), 6);
+ Wo2_ = decode_log_Wo(index, 6);
+
+ % uncomment to use unquantised values
+ %Wo1_ = model(f,1);
+ %Wo2_ = model(f+M/2,1);
+
if !voicing(f) && !voicing(f+M/2)
model_(f:f+M/2-1,1) = 2*pi/100;
end
if voicing(f) && !voicing(f+M/2)
- model_(f:f+M/4-1,1) = model(f,1);
+ model_(f:f+M/4-1,1) = Wo1_;
model_(f+M/4:f+M/2-1,1) = 2*pi/100;
voicing_(f:f+M/4-1) = 1;
end
if !voicing(f) && voicing(f+M/2)
model_(f:f+M/4-1,1) = 2*pi/100;
- model_(f+M/4:f+M/2-1,1) = model(f+M/2,1);
+ model_(f+M/4:f+M/2-1,1) = Wo2_;
voicing_(f+M/4:f+M/2-1) = 1;
end
if voicing(f) && voicing(f+M/2)
- Wo_samples = [model(f,1) model(f+M/2,1)];
+ Wo_samples = [Wo1_ Wo2_];
model_(f:f+M/2-1,1) = interp1([f f+M/2], Wo_samples, f:f+M/2-1, "linear", 0);
voicing_(f:f+M/2-1) = 1;
end
- printf("f: %d f+M/2: %d Wo: %f %f (%f %%) v: %d %d \n", f, f+M/2, model(f,1), model(f+M/2,1), 100*abs(model(f,1) - model_(f+M/2,1))/model(f,1), voicing(f), voicing(f+M/2));
+ #{
+ printf("f: %d f+M/2: %d Wo: %f %f (%f %%) v: %d %d \n", f, f+M/2, model(f,1), model(f+M/2,1), 100*abs(model(f,1) - model(f+M/2,1))/model(f,1), voicing(f), voicing(f+M/2));
for i=f:f+M/2-1
printf(" f: %d v: %d v_: %d Wo: %f Wo_: %f\n", i, voicing(i), voicing_(i), model(i,1), model_(i,1));
end
+ #}
end
model_(frames-M/2:frames,1) = pi/100; % set end frames to something sensible
- voicing_ = voicing;
- model_(:,1) = model(:,1);
- %model_(221:225,1) = model(221:225,1);
- %model_(223:224,1) = model(223:224,1);
+ % enable these to use original (non interpolated) voicing and Wo
+ %voicing_ = voicing;
+ %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);