Skip to content

Commit

Permalink
filters.c: fix max_val calculation to be bipolar.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpwe committed Mar 30, 2024
1 parent fedd46b commit 76f90f9
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/filters.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,13 @@ SAMPLE dsps_biquad_f32_ansi_split_fb_twice(const SAMPLE *input, SAMPLE *output,
y1 = y0;
output[i] = y0;
if (y0 < 0) y0 = -y0;
if (y0 > max_out) max_out = y0;
if (y0 > 0) {
if (y0 > max_out)
max_out = y0;
} else {
if (-y0 > max_out)
max_out = -y0;
}
}
w[0] = x1;
w[1] = x2;
Expand Down Expand Up @@ -633,15 +639,27 @@ SAMPLE block_norm(SAMPLE* block, int len, int bits) {
// do this even if bits == 0 to ensure max_val is set.
while(len--) {
*block = SHIFTL(*block, bits);
if (*block > max_val) max_val = *block;
if (*block > 0) {
if (*block > max_val)
max_val = *block;
} else {
if (-*block > max_val)
max_val = -*block;
}
++block;
}
} else {
// bits is negative - right-shift.
bits = -bits;
while(len--) {
*block = SHIFTR(*block, bits);
if (*block > max_val) max_val = *block;
if (*block > 0) {
if (*block > max_val)
max_val = *block;
} else {
if (-*block > max_val)
max_val = -*block;
}
++block;
}
}
Expand Down

0 comments on commit 76f90f9

Please sign in to comment.