From: drowe67 Date: Sun, 3 Apr 2016 01:45:11 +0000 (+0000) Subject: working on combination of dec in time and pf X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=6f540905f666aaecdadec3556de2dae774d91b32;p=freetel-svn-tracking.git working on combination of dec in time and pf git-svn-id: https://svn.code.sf.net/p/freetel/code@2767 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/octave/newamp.m b/codec2-dev/octave/newamp.m index f1dd6ae9..782222fe 100644 --- a/codec2-dev/octave/newamp.m +++ b/codec2-dev/octave/newamp.m @@ -56,13 +56,6 @@ function [maskdB_ maskdB_cyclic Dabs dk_] = decimate_in_freq(maskdB, cyclic=1, k end Dabs = abs(D); % this returned for plotting -if 0 - D_ = D; % + 10*randn(1,L) + 10*j*randn(1,L); - D_(Nkeep+1:L-Nkeep) = 0; % truncate - d = ifft(D_); % back to spectrum at rate L - maskdB_ = real(d); -end - % truncate D to rate k, convert to 2k length real vector for quantisation and transmission Dk = [0 D(2:k-1) real(D(k)) D(L-k+1:L)]; @@ -97,6 +90,20 @@ end endfunction +function tp = est_pf_locations(maskdB_) + % find turning points - used for finding PF freqs when we decimate in time + + L = length(maskdB_); + d = maskdB_(2:L) - maskdB_(1:L-1); + tp = []; + for m=1:L-2 + if (d(m) > 0) && (d(m+1) < 0) + tp = [tp m+1]; + end + end +endfunction + + % Create a "decimated mask" model using just a few samples of % critical band filter centre frequencies. For voiced speech, % we fit the amplitude of these samples to a straight line. diff --git a/codec2-dev/octave/newamp_batch.m b/codec2-dev/octave/newamp_batch.m index 0659d66d..5258d01b 100644 --- a/codec2-dev/octave/newamp_batch.m +++ b/codec2-dev/octave/newamp_batch.m @@ -21,18 +21,18 @@ function dk_log = newamp_batch(samname, optional_Am_out_name, optional_Aw_out_na more off; max_amp = 80; - dec_in_freq = 1; - postfilter = 1; - dec_in_time = 0; - synth_phase = 0; - vq_en = 1; + dec_in_freq = 0; + postfilter = 3; + dec_in_time = 1; + synth_phase = 1; + vq_en = 0; dk_log = []; model_name = strcat(samname,"_model.txt"); model = load(model_name); [frames nc] = size(model); model_ = zeros(frames, nc); - nom_masked_m = zeros(frames,max_amp); + non_masked_m = zeros(frames,max_amp); if nargin == 1 Am_out_name = sprintf("%s_am.out", samname); @@ -57,7 +57,6 @@ function dk_log = newamp_batch(samname, optional_Am_out_name, optional_Aw_out_na % encoder loop ------------------------------------------------------ - sd_sum = 0; for f=1:frames printf("%d ", f); @@ -75,18 +74,31 @@ function dk_log = newamp_batch(samname, optional_Am_out_name, optional_Aw_out_na % save post filter positions for decode maskdB_ = maskdB; - a_non_masked_m = find(AmdB > maskdB); - non_masked_m(f,1:length(a_non_masked_m)) = a_non_masked_m; + if (postfilter == 1) || (postfilter == 3) + a_non_masked_m = find(AmdB > maskdB); + end + 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; + end + + if postfilter == 3 + maskdB_ = maskdB_ - 9; + maskdB_(a_non_masked_m) = maskdB_(a_non_masked_m) + 9; + end if dec_in_freq if vq_en - [maskdB_ tmp1 D dk_] = decimate_in_freq(maskdB, 1, 7, vq); + [maskdB_ tmp1 D dk_] = decimate_in_freq(maskdB_, 1, 7, vq); else - [maskdB_ tmp1 D dk_] = decimate_in_freq(maskdB, 1); + [maskdB_ tmp1 D dk_] = decimate_in_freq(maskdB_, 1); end dk_log = [dk_log; dk_]; + sd_sum += sum(maskdB - maskdB_); end - sd_sum += sum(maskdB - maskdB_); + Am_ = zeros(1,max_amp); Am_ = 10 .^ (maskdB_(1:L-1)/20); @@ -107,18 +119,27 @@ function dk_log = newamp_batch(samname, optional_Am_out_name, optional_Aw_out_na if dec_in_time % decimate mask samples in time - maskdB_ = decimate_frame_rate(model_, 4, f, frames, mask_sample_freqs_kHz); - % find turning points - prototype for finding PF freqs when we decimate in time + decimate = 4; + maskdB_ = decimate_frame_rate(model_, decimate, f, frames, mask_sample_freqs_kHz); + + if 0 + a_non_masked_m = est_pf_locations(maskdB_); + end + + if 0 + + left_f = decimate*floor((f-1)/decimate)+1; + right_f = left_f + decimate; + + m = max(find(non_masked_m(left_f,:) > 0)); + a_non_masked_m = non_masked_m(left_f,1:m); + + % now convert these to m on current frame - d = maskdB_(2:L) - maskdB_(1:L-1); - tp = []; - for m=1:L-2 - if (d(m) > 0) && (d(m+1) < 0) - tp = [tp m+1]; - end + left_L = min([model_(left_f,2) max_amp-1]); + a_non_masked_m = round(a_non_masked_m*L/left_L); end - a_non_masked_m = tp; else % read non-masked (PF freqs) from analysis stage % number of non-masked samples is variable when not using AbyS, @@ -130,7 +151,7 @@ function dk_log = newamp_batch(samname, optional_Am_out_name, optional_Aw_out_na % post filter - bump up samples by 6dB, reduce mask by same level to normalise gain - if postfilter + if (postfilter == 1) || (postfilter == 2) % Apply post filter - enhances formants, suppresses others, as pe Part 1 blog % Pretty simple but makes a big difference diff --git a/codec2-dev/octave/newamp_fbf.m b/codec2-dev/octave/newamp_fbf.m index 64f9ebf7..6a775481 100644 --- a/codec2-dev/octave/newamp_fbf.m +++ b/codec2-dev/octave/newamp_fbf.m @@ -20,7 +20,7 @@ function newamp_fbf(samname, f=10) newamp; more off; plot_spectrum = 1; - vq_en = 1; + vq_en = 0; % load up text files dumped from c2sim --------------------------------------- @@ -32,9 +32,7 @@ function newamp_fbf(samname, f=10) model = load(model_name); [frames tmp] = size(model); - if vq_en - load vq; - end + load vq; % Keyboard loop -------------------------------------------------------------- @@ -69,10 +67,34 @@ function newamp_fbf(samname, f=10) [maskdB_ maskdB_cyclic D_cyclic dk_] = decimate_in_freq(maskdB, 1); 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;g'); + %plot(Am_freqs_kHz*1000, maskdB_cyclic, ';mask cyclic;b'); plot(Am_freqs_kHz*1000, maskdB_, ';mask trunated;c'); + % 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 @@ -117,4 +139,47 @@ function newamp_fbf(samname, f=10) endfunction + +function model_ = set_up_model_(model, f, decimate, vq_en, vq) + [frames nc] = size(model); + model_ = zeros(frames, nc); + left_f = decimate*floor((f-1)/decimate)+1; + right_f = left_f + decimate; + + model_(left_f,:) = set_up_maskdB_(model, left_f, vq_en, vq); + model_(right_f,:) = set_up_maskdB_(model, right_f, vq_en, vq); + model_(f,1) = model(f,1); % Wo + model_(f,2) = model(f,2); % L +endfunction + + +function amodel_row = set_up_maskdB_(model, f, vq_en, vq) + [frames nc] = size(model); + max_amp = 80; + + Wo = model(f,1); + L = model(f,2); + Am = model(f,3:(L+2)); + AmdB = 20*log10(Am); + [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; + + if vq_en + maskdB_ = decimate_in_freq(maskdB, 1, 7, vq); + else + maskdB_ = decimate_in_freq(maskdB, 1); + end + maskdB_ = maskdB; + + amodel_row = zeros(1,nc); + amodel_row(1) = Wo; + amodel_row(2) = L; + Am_ = zeros(1,max_amp); + Am_ = 10 .^ (maskdB_(1:L)/20); + amodel_row(3:(L+2)) = Am_; +endfunction