74 lines
2.1 KiB
Matlab
74 lines
2.1 KiB
Matlab
## Copyright (C) 2020 Jens
|
|
##
|
|
## This program is free software: you can redistribute it and/or modify it
|
|
## under the terms of the GNU General Public License as published by
|
|
## the Free Software Foundation, either version 3 of the License, or
|
|
## (at your option) any later version.
|
|
##
|
|
## This program is distributed in the hope that it will be useful, but
|
|
## WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
## GNU General Public License for more details.
|
|
##
|
|
## You should have received a copy of the GNU General Public License
|
|
## along with this program. If not, see
|
|
## <https://www.gnu.org/licenses/>.
|
|
|
|
## -*- texinfo -*-
|
|
## @deftypefn {} {@var{retval} =} eq_eval (@var{input1}, @var{input2})
|
|
##
|
|
## @seealso{}
|
|
##
|
|
## Exapmple: cmp_eval("snip.wav", 0.25, -40, 18);
|
|
## @end deftypefn
|
|
|
|
## Author: Jens <jens@orion>
|
|
## Created: 2020-06-22
|
|
|
|
function cmp_eval (filename_in, R, lev_knee_dB, gain_makeup_dB)
|
|
|
|
fs = 48000
|
|
[x, fs] = audioread(filename_in);
|
|
N = size(x)(1)
|
|
num_channels = size(x)(2)
|
|
filename_out = to_filename_out(filename_in, "out");
|
|
|
|
time_look_ahead = 0.01;
|
|
time_attack = 0.01;
|
|
time_release = 1.0;
|
|
|
|
n_look_ahead = round(time_look_ahead*fs);
|
|
h_dly = [zeros(1, n_look_ahead-1) 1];
|
|
|
|
x_dly = filter(h_dly, 1, x);
|
|
|
|
alpha_a = 5/(time_attack*fs);
|
|
alpha_r = 5/(time_release*fs);
|
|
|
|
lev = level_detect(x, alpha_a, alpha_r);
|
|
lev_dB = max(-120, 20*log10(lev));
|
|
|
|
k_makeup_gain = 10^(gain_makeup_dB/20);
|
|
#gain1 = min(8, (1/8)./(lev+0.1));
|
|
[lev_out_dB, gain2_dB] = cmp_gain(R, lev_knee_dB, lev_dB);
|
|
gain2 = 10.^(gain2_dB/20);
|
|
#y1 = gain1.*x_dly * 2;
|
|
|
|
y2 = gain2.*x_dly * k_makeup_gain;
|
|
#audiowrite(to_filename_out(filename_in, "gain1"), gain1, fs)
|
|
audiowrite(to_filename_out(filename_in, "gain2"), gain2, fs)
|
|
#audiowrite(to_filename_out(filename_in, "out1"), y1, fs)
|
|
audiowrite(to_filename_out(filename_in, "out2"), y2, fs)
|
|
audiowrite(to_filename_out(filename_in, "lev"), lev, fs)
|
|
|
|
gain_out = [];
|
|
gain_in = [];
|
|
for g=0:0.1:1,
|
|
gain_out = [gain_out cmp_gain(R, g, 0.01)];
|
|
gain_in = [gain_in g];
|
|
endfor
|
|
plot(gain_in, gain_out); grid();
|
|
|
|
endfunction
|
|
|