Dk = [0 D(2:k-1) real(D(k)) D(L-k+1:L)];
dk = real(ifft(Dk));
-
+
% quantisation
if nargin == 4
% 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;
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
% 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;
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;
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);
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
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]);
end
printf("\n");
-
endfunction
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 ---------------------------------------
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
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);