end
endfunction
+function maskdB = resample_mask(model, f, mask_sample_freqs_kHz)
+ max_amp = 80;
+
+ Wo = model(f,1);
+ L = min([model(f,2) max_amp-1]);
+ Am = model(f,3:(L+2));
+ AmdB = 20*log10(Am);
+ masker_freqs_kHz = (1:L)*Wo*4/pi;
+ maskdB = determine_mask(AmdB, masker_freqs_kHz, mask_sample_freqs_kHz);
+endfunction
+
+
+% decimate frame rate of mask, use interpolation in the log domain
+
+function maskdB_ = decimate_frame_rate(maskdB, model, decimate, f, frames, mask_sample_freqs_kHz)
+ max_amp = 80;
+
+ Wo = model(f,1);
+ L = min([model(f,2) max_amp-1]);
+
+ if (mod(f-1,decimate) && (f < (frames-decimate)))
+
+ % determine frames that bracket the one we need to interp
+
+ left_f = decimate*floor(f/decimate)+1;
+ right_f = decimate*ceil(f/decimate)+1;
+
+ % determine fraction of each frame to use
+
+ right_fraction = mod(f-1,decimate)/decimate;
+ left_fraction = 1 - right_fraction;
+
+ printf("\nf: %d left_f: %d right_f: %d left_fraction: %f right_fraction: %f \n",f,left_f,right_f,left_fraction,right_fraction)
+
+ % determine mask for left and right frames, sampling at Wo for this frame
+
+ mask_sample_freqs_kHz = (1:L)*Wo*4/pi;
+ maskdB_left = resample_mask(model, left_f, mask_sample_freqs_kHz);
+ maskdB_right = resample_mask(model, right_f, mask_sample_freqs_kHz);
+
+ maskdB_ = left_fraction*maskdB_left + right_fraction*maskdB_right;
+ else
+ maskdB_ = maskdB;
+ printf("\n");
+ end
+endfunction
+
+
% plot some masking curves, used for working on masking filter changes
function plot_masking
% octave:14> newamp_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 -
+
% process a whole file and write results
function newamp_batch(samname, optional_Am_out_name)
more off;
max_amp = 80;
- use_decmask = 1;
+ use_decmask = 0;
postfilter_en = 1;
decimate = 1;
fam = fopen(Am_out_name,"wb");
for f=1:frames
- printf("\rframe: %d", f);
+ printf("frame: %d", f);
L = min([model(f,2) max_amp-1]);
Wo = model(f,1);
Am = model(f,3:(L+2));
AmdB = 20*log10(Am);
- % find mask and decimated mask
+ % find mask and decimate mask samples
mask_sample_freqs_kHz = (1:L)*Wo*4/pi;
maskdB = mask_model(AmdB, Wo, L);
non_masked_m = find(AmdB > maskdB);
end
+ maskdB_ = decimate_frame_rate(maskdB_, model, decimate, f, frames, mask_sample_freqs_kHz);
+
% post filter - bump up samples by 6dB, reduce mask by same level to normalise gain
if postfilter_en
maskdB_pf = maskdB_;
end
+
if 0
% Early work as per blog post part 1
% Attempt 1
endfunction
+
model_name = strcat(samname,"_model.txt");
model = load(model_name);
-
+ [frames tmp] = size(model);
+
plot_all_masks = 0;
k = ' ';
do
Wo = model(f,1);
L = model(f,2);
Am = model(f,3:(L+2));
+ %[h w] = freqz([1 -1],1,(1:L)*Wo); % pre-emphasise to reduce dynamic range
+ %Am = Am .* abs(h);
AmdB = 20*log10(Am);
% plotting
plot(Am_freqs_kHz*1000, AmdB_, 'g+');
end
- % estimate low rate samples
+ % decimate in frequency
mask_sample_freqs_kHz = (1:L)*Wo*4/pi;
[decmaskdB local_maxima error_log candidate_log target_log] = make_decmask_abys(maskdB, AmdB, Wo, L, mask_sample_freqs_kHz);
nlm = min(nlm,4);
tonef_kHz = local_maxima(1:nlm,2)*Wo*4/pi;
toneamp_dB = local_maxima(1:nlm,1);
- plot(tonef_kHz*1000, 70*ones(1,nlm), 'bk+');
- plot(mask_sample_freqs_kHz*1000, decmaskdB, 'm');
+ %plot(tonef_kHz*1000, 70*ones(1,nlm), 'bk+');
+ %plot(mask_sample_freqs_kHz*1000, decmaskdB, 'm');
% fit a line to amplitudes
%plot(tonef_kHz*1000, tonef_kHz*m + b, "bk");
%plot(tonef_kHz*1000, 60 + toneamp_dB - (tonef_kHz*m + b), "r+");
+ % decimated in time
+
+ maskdB = decimate_frame_rate(maskdB, model, 4, f, frames, mask_sample_freqs_kHz);
+ plot(mask_sample_freqs_kHz*1000, maskdB, 'k');
+
% optionally plot all masking curves
if plot_all_masks