diff options
-rw-r--r-- | Alc/filters/nfc.c | 136 | ||||
-rw-r--r-- | Alc/filters/nfc.h | 18 |
2 files changed, 77 insertions, 77 deletions
diff --git a/Alc/filters/nfc.c b/Alc/filters/nfc.c index fa130081..8869d1d0 100644 --- a/Alc/filters/nfc.c +++ b/Alc/filters/nfc.c @@ -58,25 +58,25 @@ static void NfcFilterCreate1(struct NfcFilter1 *nfc, const float w0, const float float b_00, g_0; float r; - nfc->g = 1.0f; - nfc->coeffs[0] = 1.0f; + nfc->base_gain = 1.0f; + nfc->gain = 1.0f; /* Calculate bass-boost coefficients. */ r = 0.5f * w0; b_00 = B[1][0] * r; g_0 = 1.0f + b_00; - nfc->coeffs[0] *= g_0; - nfc->coeffs[1] = (2.0f * b_00) / g_0; + nfc->gain *= g_0; + nfc->b1 = 2.0f * b_00 / g_0; /* Calculate bass-cut coefficients. */ r = 0.5f * w1; b_00 = B[1][0] * r; g_0 = 1.0f + b_00; - nfc->g /= g_0; - nfc->coeffs[0] /= g_0; - nfc->coeffs[1+1] = (2.0f * b_00) / g_0; + nfc->base_gain /= g_0; + nfc->gain /= g_0; + nfc->a1 = 2.0f * b_00 / g_0; } static void NfcFilterAdjust1(struct NfcFilter1 *nfc, const float w0) @@ -88,8 +88,8 @@ static void NfcFilterAdjust1(struct NfcFilter1 *nfc, const float w0) b_00 = B[1][0] * r; g_0 = 1.0f + b_00; - nfc->coeffs[0] = nfc->g * g_0; - nfc->coeffs[1] = (2.0f * b_00) / g_0; + nfc->gain = nfc->base_gain * g_0; + nfc->b1 = 2.0f * b_00 / g_0; } @@ -98,8 +98,8 @@ static void NfcFilterCreate2(struct NfcFilter2 *nfc, const float w0, const float float b_10, b_11, g_1; float r; - nfc->g = 1.0f; - nfc->coeffs[0] = 1.0f; + nfc->base_gain = 1.0f; + nfc->gain = 1.0f; /* Calculate bass-boost coefficients. */ r = 0.5f * w0; @@ -107,9 +107,9 @@ static void NfcFilterCreate2(struct NfcFilter2 *nfc, const float w0, const float b_11 = B[2][1] * r * r; g_1 = 1.0f + b_10 + b_11; - nfc->coeffs[0] *= g_1; - nfc->coeffs[1] = ((2.0f * b_10) + (4.0f * b_11)) / g_1; - nfc->coeffs[2] = (4.0f * b_11) / g_1; + nfc->gain *= g_1; + nfc->b1 = (2.0f*b_10 + 4.0f*b_11) / g_1; + nfc->b2 = 4.0f * b_11 / g_1; /* Calculate bass-cut coefficients. */ r = 0.5f * w1; @@ -117,10 +117,10 @@ static void NfcFilterCreate2(struct NfcFilter2 *nfc, const float w0, const float b_11 = B[2][1] * r * r; g_1 = 1.0f + b_10 + b_11; - nfc->g /= g_1; - nfc->coeffs[0] /= g_1; - nfc->coeffs[2+1] = ((2.0f * b_10) + (4.0f * b_11)) / g_1; - nfc->coeffs[2+2] = (4.0f * b_11) / g_1; + nfc->base_gain /= g_1; + nfc->gain /= g_1; + nfc->a1 = (2.0f*b_10 + 4.0f*b_11) / g_1; + nfc->a2 = 4.0f * b_11 / g_1; } static void NfcFilterAdjust2(struct NfcFilter2 *nfc, const float w0) @@ -133,9 +133,9 @@ static void NfcFilterAdjust2(struct NfcFilter2 *nfc, const float w0) b_11 = B[2][1] * r * r; g_1 = 1.0f + b_10 + b_11; - nfc->coeffs[0] = nfc->g * g_1; - nfc->coeffs[1] = ((2.0f * b_10) + (4.0f * b_11)) / g_1; - nfc->coeffs[2] = (4.0f * b_11) / g_1; + nfc->gain = nfc->base_gain * g_1; + nfc->b1 = (2.0f*b_10 + 4.0f*b_11) / g_1; + nfc->b2 = 4.0f * b_11 / g_1; } @@ -145,8 +145,8 @@ static void NfcFilterCreate3(struct NfcFilter3 *nfc, const float w0, const float float b_00, g_0; float r; - nfc->g = 1.0f; - nfc->coeffs[0] = 1.0f; + nfc->base_gain = 1.0f; + nfc->gain = 1.0f; /* Calculate bass-boost coefficients. */ r = 0.5f * w0; @@ -154,15 +154,15 @@ static void NfcFilterCreate3(struct NfcFilter3 *nfc, const float w0, const float b_11 = B[3][1] * r * r; g_1 = 1.0f + b_10 + b_11; - nfc->coeffs[0] *= g_1; - nfc->coeffs[1] = ((2.0f * b_10) + (4.0f * b_11)) / g_1; - nfc->coeffs[2] = (4.0f * b_11) / g_1; + nfc->gain *= g_1; + nfc->b1 = (2.0f*b_10 + 4.0f*b_11) / g_1; + nfc->b2 = 4.0f * b_11 / g_1; b_00 = B[3][2] * r; g_0 = 1.0f + b_00; - nfc->coeffs[0] *= g_0; - nfc->coeffs[2+1] = (2.0f * b_00) / g_0; + nfc->gain *= g_0; + nfc->b3 = 2.0f * b_00 / g_0; /* Calculate bass-cut coefficients. */ r = 0.5f * w1; @@ -170,17 +170,17 @@ static void NfcFilterCreate3(struct NfcFilter3 *nfc, const float w0, const float b_11 = B[3][1] * r * r; g_1 = 1.0f + b_10 + b_11; - nfc->g /= g_1; - nfc->coeffs[0] /= g_1; - nfc->coeffs[3+1] = ((2.0f * b_10) + (4.0f * b_11)) / g_1; - nfc->coeffs[3+2] = (4.0f * b_11) / g_1; - + nfc->base_gain /= g_1; + nfc->gain /= g_1; + nfc->a1 = (2.0f*b_10 + 4.0f*b_11) / g_1; + nfc->a2 = 4.0f * b_11 / g_1; + b_00 = B[3][2] * r; g_0 = 1.0f + b_00; - nfc->g /= g_0; - nfc->coeffs[0] /= g_0; - nfc->coeffs[3+2+1] = (2.0f * b_00) / g_0; + nfc->base_gain /= g_0; + nfc->gain /= g_0; + nfc->a3 = 2.0f * b_00 / g_0; } static void NfcFilterAdjust3(struct NfcFilter3 *nfc, const float w0) @@ -194,15 +194,15 @@ static void NfcFilterAdjust3(struct NfcFilter3 *nfc, const float w0) b_11 = B[3][1] * r * r; g_1 = 1.0f + b_10 + b_11; - nfc->coeffs[0] = nfc->g * g_1; - nfc->coeffs[1] = ((2.0f * b_10) + (4.0f * b_11)) / g_1; - nfc->coeffs[2] = (4.0f * b_11) / g_1; + nfc->gain = nfc->base_gain * g_1; + nfc->b1 = (2.0f*b_10 + 4.0f*b_11) / g_1; + nfc->b2 = 4.0f * b_11 / g_1; b_00 = B[3][2] * r; g_0 = 1.0f + b_00; - nfc->coeffs[0] *= g_0; - nfc->coeffs[2+1] = (2.0f * b_00) / g_0; + nfc->gain *= g_0; + nfc->b3 = 2.0f * b_00 / g_0; } @@ -224,10 +224,10 @@ void NfcFilterAdjust(NfcFilter *nfc, const float w0) void NfcFilterProcess1(NfcFilter *nfc, float *restrict dst, const float *restrict src, const int count) { - const float gain = nfc->first.coeffs[0]; - const float b1 = nfc->first.coeffs[1]; - const float a1 = nfc->first.coeffs[2]; - float z1 = nfc->first.history[0]; + const float gain = nfc->first.gain; + const float b1 = nfc->first.b1; + const float a1 = nfc->first.a1; + float z1 = nfc->first.z[0]; int i; ASSUME(count > 0); @@ -240,18 +240,18 @@ void NfcFilterProcess1(NfcFilter *nfc, float *restrict dst, const float *restric dst[i] = out; } - nfc->first.history[0] = z1; + nfc->first.z[0] = z1; } void NfcFilterProcess2(NfcFilter *nfc, float *restrict dst, const float *restrict src, const int count) { - const float gain = nfc->second.coeffs[0]; - const float b1 = nfc->second.coeffs[1]; - const float b2 = nfc->second.coeffs[2]; - const float a1 = nfc->second.coeffs[3]; - const float a2 = nfc->second.coeffs[4]; - float z1 = nfc->second.history[0]; - float z2 = nfc->second.history[1]; + const float gain = nfc->second.gain; + const float b1 = nfc->second.b1; + const float b2 = nfc->second.b2; + const float a1 = nfc->second.a1; + const float a2 = nfc->second.a2; + float z1 = nfc->second.z[0]; + float z2 = nfc->second.z[1]; int i; ASSUME(count > 0); @@ -265,22 +265,22 @@ void NfcFilterProcess2(NfcFilter *nfc, float *restrict dst, const float *restric dst[i] = out; } - nfc->second.history[0] = z1; - nfc->second.history[1] = z2; + nfc->second.z[0] = z1; + nfc->second.z[1] = z2; } void NfcFilterProcess3(NfcFilter *nfc, float *restrict dst, const float *restrict src, const int count) { - const float gain = nfc->third.coeffs[0]; - const float b1 = nfc->third.coeffs[1]; - const float b2 = nfc->third.coeffs[2]; - const float b3 = nfc->third.coeffs[3]; - const float a1 = nfc->third.coeffs[4]; - const float a2 = nfc->third.coeffs[5]; - const float a3 = nfc->third.coeffs[6]; - float z1 = nfc->third.history[0]; - float z2 = nfc->third.history[1]; - float z3 = nfc->third.history[2]; + const float gain = nfc->third.gain; + const float b1 = nfc->third.b1; + const float b2 = nfc->third.b2; + const float b3 = nfc->third.b3; + const float a1 = nfc->third.a1; + const float a2 = nfc->third.a2; + const float a3 = nfc->third.a3; + float z1 = nfc->third.z[0]; + float z2 = nfc->third.z[1]; + float z3 = nfc->third.z[2]; int i; ASSUME(count > 0); @@ -298,9 +298,9 @@ void NfcFilterProcess3(NfcFilter *nfc, float *restrict dst, const float *restric dst[i] = out; } - nfc->third.history[0] = z1; - nfc->third.history[1] = z2; - nfc->third.history[2] = z3; + nfc->third.z[0] = z1; + nfc->third.z[1] = z2; + nfc->third.z[2] = z3; } #if 0 /* Original methods the above are derived from. */ diff --git a/Alc/filters/nfc.h b/Alc/filters/nfc.h index 8c6cc6ae..12a5a18f 100644 --- a/Alc/filters/nfc.h +++ b/Alc/filters/nfc.h @@ -2,19 +2,19 @@ #define FILTER_NFC_H struct NfcFilter1 { - float g; - float coeffs[1*2 + 1]; - float history[1]; + float base_gain, gain; + float b1, a1; + float z[1]; }; struct NfcFilter2 { - float g; - float coeffs[2*2 + 1]; - float history[2]; + float base_gain, gain; + float b1, b2, a1, a2; + float z[2]; }; struct NfcFilter3 { - float g; - float coeffs[3*2 + 1]; - float history[3]; + float base_gain, gain; + float b1, b2, b3, a1, a2, a3; + float z[3]; }; typedef struct NfcFilter { |