mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
filter-chain: simplify biquads
This commit is contained in:
parent
d5d8ebeaac
commit
c13696aca1
2 changed files with 26 additions and 38 deletions
|
|
@ -22,17 +22,16 @@ void lr4_set(struct lr4 *lr4, enum biquad_type type, float freq)
|
||||||
|
|
||||||
void lr4_process(struct lr4 *lr4, float *dst, const float *src, const float vol, int samples)
|
void lr4_process(struct lr4 *lr4, float *dst, const float *src, const float vol, int samples)
|
||||||
{
|
{
|
||||||
float lx1 = lr4->x1;
|
float x1 = lr4->x1;
|
||||||
float lx2 = lr4->x2;
|
float x2 = lr4->x2;
|
||||||
float ly1 = lr4->y1;
|
float y1 = lr4->y1;
|
||||||
float ly2 = lr4->y2;
|
float y2 = lr4->y2;
|
||||||
float lz1 = lr4->z1;
|
float b0 = lr4->bq.b0;
|
||||||
float lz2 = lr4->z2;
|
float b1 = lr4->bq.b1;
|
||||||
float lb0 = lr4->bq.b0;
|
float b2 = lr4->bq.b2;
|
||||||
float lb1 = lr4->bq.b1;
|
float a1 = lr4->bq.a1;
|
||||||
float lb2 = lr4->bq.b2;
|
float a2 = lr4->bq.a2;
|
||||||
float la1 = lr4->bq.a1;
|
float x, y, z;
|
||||||
float la2 = lr4->bq.a2;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (vol == 0.0f) {
|
if (vol == 0.0f) {
|
||||||
|
|
@ -47,24 +46,19 @@ void lr4_process(struct lr4 *lr4, float *dst, const float *src, const float vol,
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < samples; i++) {
|
for (i = 0; i < samples; i++) {
|
||||||
float x, y, z;
|
|
||||||
x = src[i];
|
x = src[i];
|
||||||
y = lb0*x + lb1*lx1 + lb2*lx2 - la1*ly1 - la2*ly2;
|
y = b0 * x + x1;
|
||||||
z = lb0*y + lb1*ly1 + lb2*ly2 - la1*lz1 - la2*lz2;
|
x1 = b1 * x - a1 * y + x2;
|
||||||
lx2 = lx1;
|
x2 = b2 * x - a2 * y;
|
||||||
lx1 = x;
|
z = b0 * y + y1;
|
||||||
ly2 = ly1;
|
y1 = b1 * y - a1 * z + y2;
|
||||||
ly1 = y;
|
y2 = b2 * y - a2 * z;
|
||||||
lz2 = lz1;
|
|
||||||
lz1 = z;
|
|
||||||
dst[i] = z * vol;
|
dst[i] = z * vol;
|
||||||
}
|
}
|
||||||
#define F(x) (-FLT_MIN < (x) && (x) < FLT_MIN ? 0.0f : (x))
|
#define F(x) (-FLT_MIN < (x) && (x) < FLT_MIN ? 0.0f : (x))
|
||||||
lr4->x1 = F(lx1);
|
lr4->x1 = F(x1);
|
||||||
lr4->x2 = F(lx2);
|
lr4->x2 = F(x2);
|
||||||
lr4->y1 = F(ly1);
|
lr4->y1 = F(y1);
|
||||||
lr4->y2 = F(ly2);
|
lr4->y2 = F(y2);
|
||||||
lr4->z1 = F(lz1);
|
|
||||||
lr4->z2 = F(lz2);
|
|
||||||
#undef F
|
#undef F
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -84,33 +84,27 @@ void dsp_mix_gain_c(struct dsp_ops *ops,
|
||||||
void dsp_biquad_run_c(struct dsp_ops *ops, struct biquad *bq,
|
void dsp_biquad_run_c(struct dsp_ops *ops, struct biquad *bq,
|
||||||
float *out, const float *in, uint32_t n_samples)
|
float *out, const float *in, uint32_t n_samples)
|
||||||
{
|
{
|
||||||
float x1, x2, y1, y2;
|
float x, y, x1, x2;
|
||||||
float b0, b1, b2, a1, a2;
|
float b0, b1, b2, a1, a2;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
x1 = bq->x1;
|
x1 = bq->x1;
|
||||||
x2 = bq->x2;
|
x2 = bq->x2;
|
||||||
y1 = bq->y1;
|
|
||||||
y2 = bq->y2;
|
|
||||||
b0 = bq->b0;
|
b0 = bq->b0;
|
||||||
b1 = bq->b1;
|
b1 = bq->b1;
|
||||||
b2 = bq->b2;
|
b2 = bq->b2;
|
||||||
a1 = bq->a1;
|
a1 = bq->a1;
|
||||||
a2 = bq->a2;
|
a2 = bq->a2;
|
||||||
for (i = 0; i < n_samples; i++) {
|
for (i = 0; i < n_samples; i++) {
|
||||||
float x = in[i];
|
x = in[i];
|
||||||
float y = b0 * x + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2;
|
y = b0 * x + x1;
|
||||||
|
x1 = b1 * x - a1 * y + x2;
|
||||||
|
x2 = b2 * x - a2 * y;
|
||||||
out[i] = y;
|
out[i] = y;
|
||||||
x2 = x1;
|
|
||||||
x1 = x;
|
|
||||||
y2 = y1;
|
|
||||||
y1 = y;
|
|
||||||
}
|
}
|
||||||
#define F(x) (-FLT_MIN < (x) && (x) < FLT_MIN ? 0.0f : (x))
|
#define F(x) (-FLT_MIN < (x) && (x) < FLT_MIN ? 0.0f : (x))
|
||||||
bq->x1 = F(x1);
|
bq->x1 = F(x1);
|
||||||
bq->x2 = F(x2);
|
bq->x2 = F(x2);
|
||||||
bq->y1 = F(y1);
|
|
||||||
bq->y2 = F(y2);
|
|
||||||
#undef F
|
#undef F
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue