Skip to content

Commit 59cc535

Browse files
Merge pull request #121 from jyrkialakuijala/tabuli
quality fix
2 parents a3dbc16 + a933744 commit 59cc535

File tree

3 files changed

+39
-24
lines changed

3 files changed

+39
-24
lines changed

cpp/zimt/fourier_bank.cc

+37-22
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ float SimpleDb(float energy) {
7373

7474
void FinalizeDb(hwy::AlignedNDArray<float, 2>& channels, float mul,
7575
size_t out_ix) {
76+
float masker_down[kNumRotators];
77+
for (int k = 0; k < kNumRotators; ++k) {
78+
float v = SimpleDb(mul * channels[{out_ix}][k]);
79+
channels[{out_ix}][k] = Loudness(k, v);
80+
}
7681
double masker = 0.0;
7782
static const double octaves_in_20_to_20000 = log(20000/20.)/log(2);
7883
static const double octaves_per_rot =
@@ -100,19 +105,18 @@ void FinalizeDb(hwy::AlignedNDArray<float, 2>& channels, float mul,
100105
static const float temporal0 = 0.09979167061501665;
101106
static const float temporal1 = 0.14429505133534495;
102107
static const float temporal2 = 0.009228598592129168;
103-
static float weightp = 0.1792443302507868;
104-
static float weightm = 0.7954490998745948;
108+
static const float weightp = 0.1792443302507868;
109+
static const float weightm = 0.7954490998745948;
105110

106-
static float mask_k = 0.08709005149742773;
111+
static const float mask_k = 0.08709005149742773;
107112

108113
// Scan frequencies from bottom to top, let lower frequencies to mask higher frequencies.
109114
// 'masker' maintains the masking envelope from one bin to next.
110-
static const float temporal_masker0 = 0.13104546362447728;
111-
static const float temporal_masker1 = 0.09719740670406614;
112-
static const float temporal_masker2 = -0.03085233735225447;
113-
114115
for (int k = 0; k < kNumRotators; ++k) {
115-
float v = SimpleDb(mul * channels[{out_ix}][k]);
116+
float v = channels[{out_ix}][k];
117+
if (out_ix != 0) {
118+
v = (1.0 - mask_k) * v + mask_k * channels[{out_ix - 1}][k];
119+
}
116120
if (v < min_limit) {
117121
v = min_limit;
118122
}
@@ -123,12 +127,10 @@ void FinalizeDb(hwy::AlignedNDArray<float, 2>& channels, float mul,
123127
if (masker < v2) {
124128
masker = v2;
125129
}
126-
float mask = masker - masker_gap_up;
127-
130+
float mask = fraction_up * masker - masker_gap_up;
128131
if (v < mask) {
129132
v = maskingStrengthUp * mask + (1.0 - maskingStrengthUp) * v;
130133
}
131-
132134
channels[{out_ix}][k] = v;
133135
if (3 * k < kNumRotators) {
134136
masker -= masker_step_per_rot_up_0;
@@ -143,33 +145,46 @@ void FinalizeDb(hwy::AlignedNDArray<float, 2>& channels, float mul,
143145
masker = 0.0;
144146
for (int k = kNumRotators - 1; k >= 0; --k) {
145147
float v = channels[{out_ix}][k];
148+
if (out_ix != 0) {
149+
v = (1.0 - mask_k) * v + mask_k * channels[{out_ix - 1}][k];
150+
}
146151
float v2 = (1 - down_blur) * v2 + down_blur * v;
147152
if (k == kNumRotators - 1) {
148153
v2 = v;
149154
}
150155
if (masker < v) {
151156
masker = v;
152157
}
153-
float mask = masker - masker_gap_down;
158+
float mask = fraction_down * masker - masker_gap_down;
154159
if (v < mask) {
155160
v = maskingStrengthDown * mask + (1.0 - maskingStrengthDown) * v;
156161
}
157162
channels[{out_ix}][k] = v;
158163
masker -= masker_step_per_rot_down;
159164
}
160-
for (int k = 0; k < kNumRotators; ++k) {
161-
channels[{out_ix}][k] = Loudness(k, channels[{out_ix}][k]);
162-
}
163165
// temporal masker
164166
if (out_ix >= 3) {
165167
for (int k = 0; k < kNumRotators; ++k) {
166-
float v0 = (channels[{out_ix - 1}][k] - channels[{out_ix}][k]);
167-
float v1 = (channels[{out_ix - 2}][k] - channels[{out_ix}][k]);
168-
float v2 = (channels[{out_ix - 3}][k] - channels[{out_ix}][k]);
169-
170-
channels[{out_ix}][k] -= temporal_masker0 * v0 +
171-
temporal_masker1 * v1 +
172-
temporal_masker2 * v2;
168+
float m = (temporal0 * channels[{out_ix - 1}][k] +
169+
temporal1 * channels[{out_ix - 2}][k] +
170+
temporal2 * channels[{out_ix - 3}][k]) / (temporal0 + temporal1 + temporal2);
171+
if (m > channels[{out_ix}][k]) {
172+
channels[{out_ix}][k] -= weightp * (m - channels[{out_ix}][k]);
173+
} else {
174+
channels[{out_ix}][k] -= weightm * (m - channels[{out_ix}][k]);
175+
}
176+
/*
177+
// todo(jyrki): explore with this
178+
static const float temporal_masker0 = 0.1387454636244773;
179+
channels[{out_ix}][k] -=
180+
temporal_masker0 * (channels[{out_ix - 1}][k] - channels[{out_ix}][k]);
181+
static const float temporal_masker1 = 0.08715440670406614;
182+
channels[{out_ix}][k] -=
183+
temporal_masker1 * (channels[{out_ix - 2}][k] - channels[{out_ix}][k]);
184+
static const float temporal_masker2 = -0.03785233735225447;
185+
channels[{out_ix}][k] -=
186+
temporal_masker2 * (channels[{out_ix - 3}][k] - channels[{out_ix}][k]);
187+
*/
173188
}
174189
}
175190
}

cpp/zimt/nsim.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ float HwyNSIM(const hwy::AlignedNDArray<float, 2>& a,
199199
return Mul(delta_a, delta_b);
200200
});
201201
const Vec two = Set(d, 2.0);
202-
const Vec C1 = Set(d, 0.17973327786546683);
203-
const Vec C3 = Set(d, 0.18526360286546675);
202+
const Vec C1 = Set(d, 0.19863327786546683);
203+
const Vec C3 = Set(d, 0.17538360286546675);
204204
float nsim_sum = 0.0;
205205
const Vec num_channels_vec = Set(d, num_channels);
206206
const Vec zero = Zero(d);

go/goohrli/goohrli.a

1.85 KB
Binary file not shown.

0 commit comments

Comments
 (0)