-
Notifications
You must be signed in to change notification settings - Fork 2
/
postaud.m
executable file
·61 lines (49 loc) · 1.54 KB
/
postaud.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function [y,eql] = postaud(x,fmax,fbtype,broaden)
%y = postaud(x, fmax, fbtype)
%
% do loudness equalization and cube root compression
% x = critical band filters
% rows = critical bands
% cols = frames
% Adapted from Dan Ellis's code
if nargin < 3
fbtype = 'bark';
end
if nargin < 4
% By default, don't add extra flanking bands
broaden = 0;
end
[nbands,nframes] = size(x);
% equal loundness weights stolen from rasta code
%eql = [0.000479 0.005949 0.021117 0.044806 0.073345 0.104417 0.137717 ...
% 0.174255 0.215590 0.263260 0.318302 0.380844 0.449798 0.522813
% 0.596597];
% Include frequency points at extremes, discard later
nfpts = nbands+2*broaden;
if strcmp(fbtype, 'bark')
bandcfhz = bark2hz(linspace(0, hz2bark(fmax), nfpts));
elseif strcmp(fbtype, 'mel')
bandcfhz = mel2hz(linspace(0, hz2mel(fmax), nfpts));
elseif strcmp(fbtype, 'htkmel') || strcmp(fbtype, 'fcmel')
bandcfhz = mel2hz(linspace(0, hz2mel(fmax,1), nfpts),1);
else
disp(['unknown fbtype', fbtype]);
error;
end
% Remove extremal bands (the ones that will be duplicated)
bandcfhz = bandcfhz((1+broaden):(nfpts-broaden));
% Hynek's magic equal-loudness-curve formula
fsq = bandcfhz.^2;
ftmp = fsq + 1.6e5;
eql = ((fsq./ftmp).^2) .* ((fsq + 1.44e6)./(fsq + 9.61e6));
% weight the critical bands
z = repmat(eql',1,nframes).*x;
% cube root compress
z = z .^ (.33);
% replicate first and last band (because they are unreliable as calculated)
if (broaden)
y = z([1,1:nbands,nbands],:);
else
y = z([2,2:(nbands-1),nbands-1],:);
end
%y = z([1,1:nbands-2,nbands-2],:);