diff options
author | ariff <ariff@FreeBSD.org> | 2009-07-14 18:53:34 +0000 |
---|---|---|
committer | ariff <ariff@FreeBSD.org> | 2009-07-14 18:53:34 +0000 |
commit | 7fc9bbac6d9984b91f868ad989071d95c3e3d9b3 (patch) | |
tree | 7d3e9c1a688634697c00d29c4b2fcdc97d6aa357 | |
parent | 7fbb681c5424e100b1fcfca116f474c35aeecfe2 (diff) | |
download | FreeBSD-src-7fc9bbac6d9984b91f868ad989071d95c3e3d9b3.zip FreeBSD-src-7fc9bbac6d9984b91f868ad989071d95c3e3d9b3.tar.gz |
- Do aggresive saturation on various polynomial interpolators.
This dramatically pushing 99.9% interpolations and quantizations
error _below_ -180dB on 32bit dynamic range, resulting extremely
high quality conversion.
- Use BSPLINE interpolator for filter oversampling factor greater or
equal than 64 (log2 6).
Approved by: re (kib)
-rw-r--r-- | sys/dev/sound/pcm/feeder_rate.c | 191 |
1 files changed, 98 insertions, 93 deletions
diff --git a/sys/dev/sound/pcm/feeder_rate.c b/sys/dev/sound/pcm/feeder_rate.c index 6f57395..9e8813f 100644 --- a/sys/dev/sound/pcm/feeder_rate.c +++ b/sys/dev/sound/pcm/feeder_rate.c @@ -789,10 +789,8 @@ z_resampler_sinc_len(struct z_info *info) defined(Z_COEFF_INTER_BSPLINE) || defined(Z_COEFF_INTERP_OPT32X) || \ defined(Z_COEFF_INTERP_OPT16X) || defined(Z_COEFF_INTERP_OPT8X) || \ defined(Z_COEFF_INTERP_OPT4X) || defined(Z_COEFF_INTERP_OPT2X)) -#if Z_DRIFT_SHIFT >= 12 -#define Z_COEFF_INTERP_LINEAR 1 -#elif Z_DRIFT_SHIFT >= 8 -#define Z_COEFF_INTERP_QUADRATIC 1 +#if Z_DRIFT_SHIFT >= 6 +#define Z_COEFF_INTERP_BSPLINE 1 #elif Z_DRIFT_SHIFT >= 5 #define Z_COEFF_INTERP_OPT32X 1 #elif Z_DRIFT_SHIFT == 4 @@ -835,7 +833,7 @@ z_coeff_interpolate(int32_t z, int32_t *z_coeff) zl0 = z_coeff[0]; zl1 = z_coeff[1] - z_coeff[0]; - coeff = (((int64_t)zl1 * z) >> Z_SHIFT) + zl0; + coeff = Z_RSHIFT((int64_t)zl1 * z, Z_SHIFT) + zl0; #elif defined(Z_COEFF_INTERP_QUADRATIC) int32_t zq0, zq1, zq2; @@ -844,8 +842,8 @@ z_coeff_interpolate(int32_t z, int32_t *z_coeff) zq1 = z_coeff[1] - z_coeff[-1]; zq2 = z_coeff[1] + z_coeff[-1] - (z_coeff[0] << 1); - coeff = ((((((int64_t)zq2 * z) >> Z_SHIFT) + - zq1) * z) >> (Z_SHIFT + 1)) + zq0; + coeff = Z_RSHIFT((Z_RSHIFT((int64_t)zq2 * z, Z_SHIFT) + + zq1) * z, Z_SHIFT + 1) + zq0; #elif defined(Z_COEFF_INTERP_HERMITE) int32_t zh0, zh1, zh2, zh3; @@ -856,19 +854,21 @@ z_coeff_interpolate(int32_t z, int32_t *z_coeff) z_coeff[2]; zh3 = z_coeff[2] - z_coeff[-1] + ((z_coeff[0] - z_coeff[1]) * 3); - coeff = (((((((((int64_t)zh3 * z) >> Z_SHIFT) + - zh2) * z) >> Z_SHIFT) + zh1) * z) >> (Z_SHIFT + 1)) + zh0; + coeff = Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((int64_t)zh3 * z, Z_SHIFT) + + zh2) * z, Z_SHIFT) + zh1) * z, Z_SHIFT + 1) + zh0; #elif defined(Z_COEFF_INTERP_BSPLINE) int32_t zb0, zb1, zb2, zb3; /* 4-point, 3rd-order B-Spline */ - zb0 = (((int64_t)z_coeff[0] << 2) + z_coeff[-1] + z_coeff[1]) / 3; + zb0 = Z_RSHIFT(0x15555555LL * (((int64_t)z_coeff[0] << 2) + + z_coeff[-1] + z_coeff[1]), 30); zb1 = z_coeff[1] - z_coeff[-1]; zb2 = z_coeff[-1] + z_coeff[1] - (z_coeff[0] << 1); - zb3 = (((z_coeff[0] - z_coeff[1]) * 3) + z_coeff[2] - z_coeff[-1]) / 3; + zb3 = Z_RSHIFT(0x15555555LL * (((z_coeff[0] - z_coeff[1]) * 3) + + z_coeff[2] - z_coeff[-1]), 30); - coeff = ((((((((((int64_t)zb3 * z) >> Z_SHIFT) + - zb2) * z) >> Z_SHIFT) + zb1) * z) >> Z_SHIFT) + zb0) >> 1; + coeff = (Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((int64_t)zb3 * z, Z_SHIFT) + + zb2) * z, Z_SHIFT) + zb1) * z, Z_SHIFT) + zb0 + 1) >> 1; #elif defined(Z_COEFF_INTERP_OPT32X) int32_t zoz, zoe1, zoe2, zoe3, zoo1, zoo2, zoo3; int32_t zoc0, zoc1, zoc2, zoc3, zoc4, zoc5; @@ -882,22 +882,23 @@ z_coeff_interpolate(int32_t z, int32_t *z_coeff) zoo2 = z_coeff[2] - z_coeff[-1]; zoo3 = z_coeff[3] - z_coeff[-2]; - zoc0 = ((0x1ac2260dLL * zoe1) + (0x0526cdcaLL * zoe2) + - (0x00170c29LL * zoe3)) >> 30; - zoc1 = ((0x14f8a49aLL * zoo1) + (0x0d6d1109LL * zoo2) + - (0x008cd4dcLL * zoo3)) >> 30; - zoc2 = ((-0x0d3e94a4LL * zoe1) + (0x0bddded4LL * zoe2) + - (0x0160b5d0LL * zoe3)) >> 30; - zoc3 = ((-0x0de10cc4LL * zoo1) + (0x019b2a7dLL * zoo2) + - (0x01cfe914LL * zoo3)) >> 30; - zoc4 = ((0x02aa12d7LL * zoe1) + (-0x03ff1bb3LL * zoe2) + - (0x015508ddLL * zoe3)) >> 30; - zoc5 = ((0x051d29e5LL * zoo1) + (-0x028e7647LL * zoo2) + - (0x0082d81aLL * zoo3)) >> 30; - - coeff = (((((((((((((((int64_t)zoc5 * zoz) >> Z_SHIFT) + - zoc4) * zoz) >> Z_SHIFT) + zoc3) * zoz) >> Z_SHIFT) + - zoc2) * zoz) >> Z_SHIFT) + zoc1) * zoz) >> Z_SHIFT) + zoc0; + zoc0 = Z_RSHIFT((0x1ac2260dLL * zoe1) + (0x0526cdcaLL * zoe2) + + (0x00170c29LL * zoe3), 30); + zoc1 = Z_RSHIFT((0x14f8a49aLL * zoo1) + (0x0d6d1109LL * zoo2) + + (0x008cd4dcLL * zoo3), 30); + zoc2 = Z_RSHIFT((-0x0d3e94a4LL * zoe1) + (0x0bddded4LL * zoe2) + + (0x0160b5d0LL * zoe3), 30); + zoc3 = Z_RSHIFT((-0x0de10cc4LL * zoo1) + (0x019b2a7dLL * zoo2) + + (0x01cfe914LL * zoo3), 30); + zoc4 = Z_RSHIFT((0x02aa12d7LL * zoe1) + (-0x03ff1bb3LL * zoe2) + + (0x015508ddLL * zoe3), 30); + zoc5 = Z_RSHIFT((0x051d29e5LL * zoo1) + (-0x028e7647LL * zoo2) + + (0x0082d81aLL * zoo3), 30); + + coeff = Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((Z_RSHIFT( + (int64_t)zoc5 * zoz, Z_SHIFT) + + zoc4) * zoz, Z_SHIFT) + zoc3) * zoz, Z_SHIFT) + + zoc2) * zoz, Z_SHIFT) + zoc1) * zoz, Z_SHIFT) + zoc0; #elif defined(Z_COEFF_INTERP_OPT16X) int32_t zoz, zoe1, zoe2, zoe3, zoo1, zoo2, zoo3; int32_t zoc0, zoc1, zoc2, zoc3, zoc4, zoc5; @@ -911,22 +912,23 @@ z_coeff_interpolate(int32_t z, int32_t *z_coeff) zoo2 = z_coeff[2] - z_coeff[-1]; zoo3 = z_coeff[3] - z_coeff[-2]; - zoc0 = ((0x1ac2260dLL * zoe1) + (0x0526cdcaLL * zoe2) + - (0x00170c29LL * zoe3)) >> 30; - zoc1 = ((0x14f8a49aLL * zoo1) + (0x0d6d1109LL * zoo2) + - (0x008cd4dcLL * zoo3)) >> 30; - zoc2 = ((-0x0d3e94a4LL * zoe1) + (0x0bddded4LL * zoe2) + - (0x0160b5d0LL * zoe3)) >> 30; - zoc3 = ((-0x0de10cc4LL * zoo1) + (0x019b2a7dLL * zoo2) + - (0x01cfe914LL * zoo3)) >> 30; - zoc4 = ((0x02aa12d7LL * zoe1) + (-0x03ff1bb3LL * zoe2) + - (0x015508ddLL * zoe3)) >> 30; - zoc5 = ((0x051d29e5LL * zoo1) + (-0x028e7647LL * zoo2) + - (0x0082d81aLL * zoo3)) >> 30; - - coeff = (((((((((((((((int64_t)zoc5 * zoz) >> Z_SHIFT) + - zoc4) * zoz) >> Z_SHIFT) + zoc3) * zoz) >> Z_SHIFT) + - zoc2) * zoz) >> Z_SHIFT) + zoc1) * zoz) >> Z_SHIFT) + zoc0; + zoc0 = Z_RSHIFT((0x1ac2260dLL * zoe1) + (0x0526cdcaLL * zoe2) + + (0x00170c29LL * zoe3), 30); + zoc1 = Z_RSHIFT((0x14f8a49aLL * zoo1) + (0x0d6d1109LL * zoo2) + + (0x008cd4dcLL * zoo3), 30); + zoc2 = Z_RSHIFT((-0x0d3e94a4LL * zoe1) + (0x0bddded4LL * zoe2) + + (0x0160b5d0LL * zoe3), 30); + zoc3 = Z_RSHIFT((-0x0de10cc4LL * zoo1) + (0x019b2a7dLL * zoo2) + + (0x01cfe914LL * zoo3), 30); + zoc4 = Z_RSHIFT((0x02aa12d7LL * zoe1) + (-0x03ff1bb3LL * zoe2) + + (0x015508ddLL * zoe3), 30); + zoc5 = Z_RSHIFT((0x051d29e5LL * zoo1) + (-0x028e7647LL * zoo2) + + (0x0082d81aLL * zoo3), 30); + + coeff = Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((Z_RSHIFT( + (int64_t)zoc5 * zoz, Z_SHIFT) + + zoc4) * zoz, Z_SHIFT) + zoc3) * zoz, Z_SHIFT) + + zoc2) * zoz, Z_SHIFT) + zoc1) * zoz, Z_SHIFT) + zoc0; #elif defined(Z_COEFF_INTERP_OPT8X) int32_t zoz, zoe1, zoe2, zoe3, zoo1, zoo2, zoo3; int32_t zoc0, zoc1, zoc2, zoc3, zoc4, zoc5; @@ -940,22 +942,23 @@ z_coeff_interpolate(int32_t z, int32_t *z_coeff) zoo2 = z_coeff[2] - z_coeff[-1]; zoo3 = z_coeff[3] - z_coeff[-2]; - zoc0 = ((0x1aa9b47dLL * zoe1) + (0x053d9944LL * zoe2) + - (0x0018b23fLL * zoe3)) >> 30; - zoc1 = ((0x14a104d1LL * zoo1) + (0x0d7d2504LL * zoo2) + - (0x0094b599LL * zoo3)) >> 30; - zoc2 = ((-0x0d22530bLL * zoe1) + (0x0bb37a2cLL * zoe2) + - (0x016ed8e0LL * zoe3)) >> 30; - zoc3 = ((-0x0d744b1cLL * zoo1) + (0x01649591LL * zoo2) + - (0x01dae93aLL * zoo3)) >> 30; - zoc4 = ((0x02a7ee1bLL * zoe1) + (-0x03fbdb24LL * zoe2) + - (0x0153ed07LL * zoe3)) >> 30; - zoc5 = ((0x04cf9b6cLL * zoo1) + (-0x0266b378LL * zoo2) + - (0x007a7c26LL * zoo3)) >> 30; - - coeff = (((((((((((((((int64_t)zoc5 * zoz) >> Z_SHIFT) + - zoc4) * zoz) >> Z_SHIFT) + zoc3) * zoz) >> Z_SHIFT) + - zoc2) * zoz) >> Z_SHIFT) + zoc1) * zoz) >> Z_SHIFT) + zoc0; + zoc0 = Z_RSHIFT((0x1aa9b47dLL * zoe1) + (0x053d9944LL * zoe2) + + (0x0018b23fLL * zoe3), 30); + zoc1 = Z_RSHIFT((0x14a104d1LL * zoo1) + (0x0d7d2504LL * zoo2) + + (0x0094b599LL * zoo3), 30); + zoc2 = Z_RSHIFT((-0x0d22530bLL * zoe1) + (0x0bb37a2cLL * zoe2) + + (0x016ed8e0LL * zoe3), 30); + zoc3 = Z_RSHIFT((-0x0d744b1cLL * zoo1) + (0x01649591LL * zoo2) + + (0x01dae93aLL * zoo3), 30); + zoc4 = Z_RSHIFT((0x02a7ee1bLL * zoe1) + (-0x03fbdb24LL * zoe2) + + (0x0153ed07LL * zoe3), 30); + zoc5 = Z_RSHIFT((0x04cf9b6cLL * zoo1) + (-0x0266b378LL * zoo2) + + (0x007a7c26LL * zoo3), 30); + + coeff = Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((Z_RSHIFT( + (int64_t)zoc5 * zoz, Z_SHIFT) + + zoc4) * zoz, Z_SHIFT) + zoc3) * zoz, Z_SHIFT) + + zoc2) * zoz, Z_SHIFT) + zoc1) * zoz, Z_SHIFT) + zoc0; #elif defined(Z_COEFF_INTERP_OPT4X) int32_t zoz, zoe1, zoe2, zoe3, zoo1, zoo2, zoo3; int32_t zoc0, zoc1, zoc2, zoc3, zoc4, zoc5; @@ -969,22 +972,23 @@ z_coeff_interpolate(int32_t z, int32_t *z_coeff) zoo2 = z_coeff[2] - z_coeff[-1]; zoo3 = z_coeff[3] - z_coeff[-2]; - zoc0 = ((0x1a8eda43LL * zoe1) + (0x0556ee38LL * zoe2) + - (0x001a3784LL * zoe3)) >> 30; - zoc1 = ((0x143d863eLL * zoo1) + (0x0d910e36LL * zoo2) + - (0x009ca889LL * zoo3)) >> 30; - zoc2 = ((-0x0d026821LL * zoe1) + (0x0b837773LL * zoe2) + - (0x017ef0c6LL * zoe3)) >> 30; - zoc3 = ((-0x0cef1502LL * zoo1) + (0x01207a8eLL * zoo2) + - (0x01e936dbLL * zoo3)) >> 30; - zoc4 = ((0x029fe643LL * zoe1) + (-0x03ef3fc8LL * zoe2) + - (0x014f5923LL * zoe3)) >> 30; - zoc5 = ((0x043a9d08LL * zoo1) + (-0x02154febLL * zoo2) + - (0x00670dbdLL * zoo3)) >> 30; - - coeff = (((((((((((((((int64_t)zoc5 * zoz) >> Z_SHIFT) + - zoc4) * zoz) >> Z_SHIFT) + zoc3) * zoz) >> Z_SHIFT) + - zoc2) * zoz) >> Z_SHIFT) + zoc1) * zoz) >> Z_SHIFT) + zoc0; + zoc0 = Z_RSHIFT((0x1a8eda43LL * zoe1) + (0x0556ee38LL * zoe2) + + (0x001a3784LL * zoe3), 30); + zoc1 = Z_RSHIFT((0x143d863eLL * zoo1) + (0x0d910e36LL * zoo2) + + (0x009ca889LL * zoo3), 30); + zoc2 = Z_RSHIFT((-0x0d026821LL * zoe1) + (0x0b837773LL * zoe2) + + (0x017ef0c6LL * zoe3), 30); + zoc3 = Z_RSHIFT((-0x0cef1502LL * zoo1) + (0x01207a8eLL * zoo2) + + (0x01e936dbLL * zoo3), 30); + zoc4 = Z_RSHIFT((0x029fe643LL * zoe1) + (-0x03ef3fc8LL * zoe2) + + (0x014f5923LL * zoe3), 30); + zoc5 = Z_RSHIFT((0x043a9d08LL * zoo1) + (-0x02154febLL * zoo2) + + (0x00670dbdLL * zoo3), 30); + + coeff = Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((Z_RSHIFT( + (int64_t)zoc5 * zoz, Z_SHIFT) + + zoc4) * zoz, Z_SHIFT) + zoc3) * zoz, Z_SHIFT) + + zoc2) * zoz, Z_SHIFT) + zoc1) * zoz, Z_SHIFT) + zoc0; #elif defined(Z_COEFF_INTERP_OPT2X) int32_t zoz, zoe1, zoe2, zoe3, zoo1, zoo2, zoo3; int32_t zoc0, zoc1, zoc2, zoc3, zoc4, zoc5; @@ -998,22 +1002,23 @@ z_coeff_interpolate(int32_t z, int32_t *z_coeff) zoo2 = z_coeff[2] - z_coeff[-1]; zoo3 = z_coeff[3] - z_coeff[-2]; - zoc0 = ((0x19edb6fdLL * zoe1) + (0x05ebd062LL * zoe2) + - (0x00267881LL * zoe3)) >> 30; - zoc1 = ((0x1223af76LL * zoo1) + (0x0de3dd6bLL * zoo2) + - (0x00d683cdLL * zoo3)) >> 30; - zoc2 = ((-0x0c3ee068LL * zoe1) + (0x0a5c3769LL * zoe2) + - (0x01e2aceaLL * zoe3)) >> 30; - zoc3 = ((-0x0a8ab614LL * zoo1) + (-0x0019522eLL * zoo2) + - (0x022cefc7LL * zoo3)) >> 30; - zoc4 = ((0x0276187dLL * zoe1) + (-0x03a801e8LL * zoe2) + - (0x0131d935LL * zoe3)) >> 30; - zoc5 = ((0x02c373f5LL * zoo1) + (-0x01275f83LL * zoo2) + - (0x0018ee79LL * zoo3)) >> 30; - - coeff = (((((((((((((((int64_t)zoc5 * zoz) >> Z_SHIFT) + - zoc4) * zoz) >> Z_SHIFT) + zoc3) * zoz) >> Z_SHIFT) + - zoc2) * zoz) >> Z_SHIFT) + zoc1) * zoz) >> Z_SHIFT) + zoc0; + zoc0 = Z_RSHIFT((0x19edb6fdLL * zoe1) + (0x05ebd062LL * zoe2) + + (0x00267881LL * zoe3), 30); + zoc1 = Z_RSHIFT((0x1223af76LL * zoo1) + (0x0de3dd6bLL * zoo2) + + (0x00d683cdLL * zoo3), 30); + zoc2 = Z_RSHIFT((-0x0c3ee068LL * zoe1) + (0x0a5c3769LL * zoe2) + + (0x01e2aceaLL * zoe3), 30); + zoc3 = Z_RSHIFT((-0x0a8ab614LL * zoo1) + (-0x0019522eLL * zoo2) + + (0x022cefc7LL * zoo3), 30); + zoc4 = Z_RSHIFT((0x0276187dLL * zoe1) + (-0x03a801e8LL * zoe2) + + (0x0131d935LL * zoe3), 30); + zoc5 = Z_RSHIFT((0x02c373f5LL * zoo1) + (-0x01275f83LL * zoo2) + + (0x0018ee79LL * zoo3), 30); + + coeff = Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((Z_RSHIFT( + (int64_t)zoc5 * zoz, Z_SHIFT) + + zoc4) * zoz, Z_SHIFT) + zoc3) * zoz, Z_SHIFT) + + zoc2) * zoz, Z_SHIFT) + zoc1) * zoz, Z_SHIFT) + zoc0; #else #error "Interpolation type screwed!" #endif |