% [ ] 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,
% 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
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
% Differential Freq Quantisers - sounds acceptable
- if freq_quant
+ if freq_quant == 1
% first freq quant to harmonic number m=1:8
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
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
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
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 = [];
% encoder loop ------------------------------------------------------
- pp_bw = gen_pp_bw;
+ %pp_bw = gen_pp_bw;
for f=1:frames
printf("%d ", f);
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
model_(f,3:(L+1)) = Am_;
end
-
% decoder loop -----------------------------------------------------
for f=1:frames