1/*- 2 * Copyright (c) 2005-2009 Ariff Abdullah <ariff@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 45 unchanged lines hidden (view full) --- 54#endif 55#include <dev/sound/pcm/sound.h> 56#include <dev/sound/pcm/pcm.h> 57#include "feeder_if.h" 58 59#define SND_USE_FXDIV 60#include "snd_fxdiv_gen.h" 61 |
62SND_DECLARE_FILE("$FreeBSD: head/sys/dev/sound/pcm/feeder_rate.c 195689 2009-07-14 18:53:34Z ariff $"); |
63#endif 64 65#include "feeder_rate_gen.h" 66 67#if !defined(_KERNEL) && defined(SND_DIAGNOSTIC) 68#undef Z_DIAGNOSTIC 69#define Z_DIAGNOSTIC 1 70#elif defined(_KERNEL) --- 713 unchanged lines hidden (view full) --- 784 * Pick suitable polynomial interpolators based on filter oversampled ratio 785 * (2 ^ Z_DRIFT_SHIFT). 786 */ 787#if !(defined(Z_COEFF_INTERP_ZOH) || defined(Z_COEFF_INTERP_LINEAR) || \ 788 defined(Z_COEFF_INTERP_QUADRATIC) || defined(Z_COEFF_INTERP_HERMITE) || \ 789 defined(Z_COEFF_INTER_BSPLINE) || defined(Z_COEFF_INTERP_OPT32X) || \ 790 defined(Z_COEFF_INTERP_OPT16X) || defined(Z_COEFF_INTERP_OPT8X) || \ 791 defined(Z_COEFF_INTERP_OPT4X) || defined(Z_COEFF_INTERP_OPT2X)) |
792#if Z_DRIFT_SHIFT >= 6 793#define Z_COEFF_INTERP_BSPLINE 1 |
794#elif Z_DRIFT_SHIFT >= 5 795#define Z_COEFF_INTERP_OPT32X 1 796#elif Z_DRIFT_SHIFT == 4 797#define Z_COEFF_INTERP_OPT16X 1 798#elif Z_DRIFT_SHIFT == 3 799#define Z_COEFF_INTERP_OPT8X 1 800#elif Z_DRIFT_SHIFT == 2 801#define Z_COEFF_INTERP_OPT4X 1 --- 26 unchanged lines hidden (view full) --- 828 coeff = z_coeff[0]; 829#elif defined(Z_COEFF_INTERP_LINEAR) 830 int32_t zl0, zl1; 831 832 /* 2-point, 1st-order Linear */ 833 zl0 = z_coeff[0]; 834 zl1 = z_coeff[1] - z_coeff[0]; 835 |
836 coeff = Z_RSHIFT((int64_t)zl1 * z, Z_SHIFT) + zl0; |
837#elif defined(Z_COEFF_INTERP_QUADRATIC) 838 int32_t zq0, zq1, zq2; 839 840 /* 3-point, 2nd-order Quadratic */ 841 zq0 = z_coeff[0]; 842 zq1 = z_coeff[1] - z_coeff[-1]; 843 zq2 = z_coeff[1] + z_coeff[-1] - (z_coeff[0] << 1); 844 |
845 coeff = Z_RSHIFT((Z_RSHIFT((int64_t)zq2 * z, Z_SHIFT) + 846 zq1) * z, Z_SHIFT + 1) + zq0; |
847#elif defined(Z_COEFF_INTERP_HERMITE) 848 int32_t zh0, zh1, zh2, zh3; 849 850 /* 4-point, 3rd-order Hermite */ 851 zh0 = z_coeff[0]; 852 zh1 = z_coeff[1] - z_coeff[-1]; 853 zh2 = (z_coeff[-1] << 1) - (z_coeff[0] * 5) + (z_coeff[1] << 2) - 854 z_coeff[2]; 855 zh3 = z_coeff[2] - z_coeff[-1] + ((z_coeff[0] - z_coeff[1]) * 3); 856 |
857 coeff = Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((int64_t)zh3 * z, Z_SHIFT) + 858 zh2) * z, Z_SHIFT) + zh1) * z, Z_SHIFT + 1) + zh0; |
859#elif defined(Z_COEFF_INTERP_BSPLINE) 860 int32_t zb0, zb1, zb2, zb3; 861 862 /* 4-point, 3rd-order B-Spline */ |
863 zb0 = Z_RSHIFT(0x15555555LL * (((int64_t)z_coeff[0] << 2) + 864 z_coeff[-1] + z_coeff[1]), 30); |
865 zb1 = z_coeff[1] - z_coeff[-1]; 866 zb2 = z_coeff[-1] + z_coeff[1] - (z_coeff[0] << 1); |
867 zb3 = Z_RSHIFT(0x15555555LL * (((z_coeff[0] - z_coeff[1]) * 3) + 868 z_coeff[2] - z_coeff[-1]), 30); |
869 |
870 coeff = (Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((int64_t)zb3 * z, Z_SHIFT) + 871 zb2) * z, Z_SHIFT) + zb1) * z, Z_SHIFT) + zb0 + 1) >> 1; |
872#elif defined(Z_COEFF_INTERP_OPT32X) 873 int32_t zoz, zoe1, zoe2, zoe3, zoo1, zoo2, zoo3; 874 int32_t zoc0, zoc1, zoc2, zoc3, zoc4, zoc5; 875 876 /* 6-point, 5th-order Optimal 32x */ 877 zoz = z - (Z_ONE >> 1); 878 zoe1 = z_coeff[1] + z_coeff[0]; 879 zoe2 = z_coeff[2] + z_coeff[-1]; 880 zoe3 = z_coeff[3] + z_coeff[-2]; 881 zoo1 = z_coeff[1] - z_coeff[0]; 882 zoo2 = z_coeff[2] - z_coeff[-1]; 883 zoo3 = z_coeff[3] - z_coeff[-2]; 884 |
885 zoc0 = Z_RSHIFT((0x1ac2260dLL * zoe1) + (0x0526cdcaLL * zoe2) + 886 (0x00170c29LL * zoe3), 30); 887 zoc1 = Z_RSHIFT((0x14f8a49aLL * zoo1) + (0x0d6d1109LL * zoo2) + 888 (0x008cd4dcLL * zoo3), 30); 889 zoc2 = Z_RSHIFT((-0x0d3e94a4LL * zoe1) + (0x0bddded4LL * zoe2) + 890 (0x0160b5d0LL * zoe3), 30); 891 zoc3 = Z_RSHIFT((-0x0de10cc4LL * zoo1) + (0x019b2a7dLL * zoo2) + 892 (0x01cfe914LL * zoo3), 30); 893 zoc4 = Z_RSHIFT((0x02aa12d7LL * zoe1) + (-0x03ff1bb3LL * zoe2) + 894 (0x015508ddLL * zoe3), 30); 895 zoc5 = Z_RSHIFT((0x051d29e5LL * zoo1) + (-0x028e7647LL * zoo2) + 896 (0x0082d81aLL * zoo3), 30); |
897 |
898 coeff = Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((Z_RSHIFT( 899 (int64_t)zoc5 * zoz, Z_SHIFT) + 900 zoc4) * zoz, Z_SHIFT) + zoc3) * zoz, Z_SHIFT) + 901 zoc2) * zoz, Z_SHIFT) + zoc1) * zoz, Z_SHIFT) + zoc0; |
902#elif defined(Z_COEFF_INTERP_OPT16X) 903 int32_t zoz, zoe1, zoe2, zoe3, zoo1, zoo2, zoo3; 904 int32_t zoc0, zoc1, zoc2, zoc3, zoc4, zoc5; 905 906 /* 6-point, 5th-order Optimal 16x */ 907 zoz = z - (Z_ONE >> 1); 908 zoe1 = z_coeff[1] + z_coeff[0]; 909 zoe2 = z_coeff[2] + z_coeff[-1]; 910 zoe3 = z_coeff[3] + z_coeff[-2]; 911 zoo1 = z_coeff[1] - z_coeff[0]; 912 zoo2 = z_coeff[2] - z_coeff[-1]; 913 zoo3 = z_coeff[3] - z_coeff[-2]; 914 |
915 zoc0 = Z_RSHIFT((0x1ac2260dLL * zoe1) + (0x0526cdcaLL * zoe2) + 916 (0x00170c29LL * zoe3), 30); 917 zoc1 = Z_RSHIFT((0x14f8a49aLL * zoo1) + (0x0d6d1109LL * zoo2) + 918 (0x008cd4dcLL * zoo3), 30); 919 zoc2 = Z_RSHIFT((-0x0d3e94a4LL * zoe1) + (0x0bddded4LL * zoe2) + 920 (0x0160b5d0LL * zoe3), 30); 921 zoc3 = Z_RSHIFT((-0x0de10cc4LL * zoo1) + (0x019b2a7dLL * zoo2) + 922 (0x01cfe914LL * zoo3), 30); 923 zoc4 = Z_RSHIFT((0x02aa12d7LL * zoe1) + (-0x03ff1bb3LL * zoe2) + 924 (0x015508ddLL * zoe3), 30); 925 zoc5 = Z_RSHIFT((0x051d29e5LL * zoo1) + (-0x028e7647LL * zoo2) + 926 (0x0082d81aLL * zoo3), 30); |
927 |
928 coeff = Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((Z_RSHIFT( 929 (int64_t)zoc5 * zoz, Z_SHIFT) + 930 zoc4) * zoz, Z_SHIFT) + zoc3) * zoz, Z_SHIFT) + 931 zoc2) * zoz, Z_SHIFT) + zoc1) * zoz, Z_SHIFT) + zoc0; |
932#elif defined(Z_COEFF_INTERP_OPT8X) 933 int32_t zoz, zoe1, zoe2, zoe3, zoo1, zoo2, zoo3; 934 int32_t zoc0, zoc1, zoc2, zoc3, zoc4, zoc5; 935 936 /* 6-point, 5th-order Optimal 8x */ 937 zoz = z - (Z_ONE >> 1); 938 zoe1 = z_coeff[1] + z_coeff[0]; 939 zoe2 = z_coeff[2] + z_coeff[-1]; 940 zoe3 = z_coeff[3] + z_coeff[-2]; 941 zoo1 = z_coeff[1] - z_coeff[0]; 942 zoo2 = z_coeff[2] - z_coeff[-1]; 943 zoo3 = z_coeff[3] - z_coeff[-2]; 944 |
945 zoc0 = Z_RSHIFT((0x1aa9b47dLL * zoe1) + (0x053d9944LL * zoe2) + 946 (0x0018b23fLL * zoe3), 30); 947 zoc1 = Z_RSHIFT((0x14a104d1LL * zoo1) + (0x0d7d2504LL * zoo2) + 948 (0x0094b599LL * zoo3), 30); 949 zoc2 = Z_RSHIFT((-0x0d22530bLL * zoe1) + (0x0bb37a2cLL * zoe2) + 950 (0x016ed8e0LL * zoe3), 30); 951 zoc3 = Z_RSHIFT((-0x0d744b1cLL * zoo1) + (0x01649591LL * zoo2) + 952 (0x01dae93aLL * zoo3), 30); 953 zoc4 = Z_RSHIFT((0x02a7ee1bLL * zoe1) + (-0x03fbdb24LL * zoe2) + 954 (0x0153ed07LL * zoe3), 30); 955 zoc5 = Z_RSHIFT((0x04cf9b6cLL * zoo1) + (-0x0266b378LL * zoo2) + 956 (0x007a7c26LL * zoo3), 30); |
957 |
958 coeff = Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((Z_RSHIFT( 959 (int64_t)zoc5 * zoz, Z_SHIFT) + 960 zoc4) * zoz, Z_SHIFT) + zoc3) * zoz, Z_SHIFT) + 961 zoc2) * zoz, Z_SHIFT) + zoc1) * zoz, Z_SHIFT) + zoc0; |
962#elif defined(Z_COEFF_INTERP_OPT4X) 963 int32_t zoz, zoe1, zoe2, zoe3, zoo1, zoo2, zoo3; 964 int32_t zoc0, zoc1, zoc2, zoc3, zoc4, zoc5; 965 966 /* 6-point, 5th-order Optimal 4x */ 967 zoz = z - (Z_ONE >> 1); 968 zoe1 = z_coeff[1] + z_coeff[0]; 969 zoe2 = z_coeff[2] + z_coeff[-1]; 970 zoe3 = z_coeff[3] + z_coeff[-2]; 971 zoo1 = z_coeff[1] - z_coeff[0]; 972 zoo2 = z_coeff[2] - z_coeff[-1]; 973 zoo3 = z_coeff[3] - z_coeff[-2]; 974 |
975 zoc0 = Z_RSHIFT((0x1a8eda43LL * zoe1) + (0x0556ee38LL * zoe2) + 976 (0x001a3784LL * zoe3), 30); 977 zoc1 = Z_RSHIFT((0x143d863eLL * zoo1) + (0x0d910e36LL * zoo2) + 978 (0x009ca889LL * zoo3), 30); 979 zoc2 = Z_RSHIFT((-0x0d026821LL * zoe1) + (0x0b837773LL * zoe2) + 980 (0x017ef0c6LL * zoe3), 30); 981 zoc3 = Z_RSHIFT((-0x0cef1502LL * zoo1) + (0x01207a8eLL * zoo2) + 982 (0x01e936dbLL * zoo3), 30); 983 zoc4 = Z_RSHIFT((0x029fe643LL * zoe1) + (-0x03ef3fc8LL * zoe2) + 984 (0x014f5923LL * zoe3), 30); 985 zoc5 = Z_RSHIFT((0x043a9d08LL * zoo1) + (-0x02154febLL * zoo2) + 986 (0x00670dbdLL * zoo3), 30); |
987 |
988 coeff = Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((Z_RSHIFT( 989 (int64_t)zoc5 * zoz, Z_SHIFT) + 990 zoc4) * zoz, Z_SHIFT) + zoc3) * zoz, Z_SHIFT) + 991 zoc2) * zoz, Z_SHIFT) + zoc1) * zoz, Z_SHIFT) + zoc0; |
992#elif defined(Z_COEFF_INTERP_OPT2X) 993 int32_t zoz, zoe1, zoe2, zoe3, zoo1, zoo2, zoo3; 994 int32_t zoc0, zoc1, zoc2, zoc3, zoc4, zoc5; 995 996 /* 6-point, 5th-order Optimal 2x */ 997 zoz = z - (Z_ONE >> 1); 998 zoe1 = z_coeff[1] + z_coeff[0]; 999 zoe2 = z_coeff[2] + z_coeff[-1]; 1000 zoe3 = z_coeff[3] + z_coeff[-2]; 1001 zoo1 = z_coeff[1] - z_coeff[0]; 1002 zoo2 = z_coeff[2] - z_coeff[-1]; 1003 zoo3 = z_coeff[3] - z_coeff[-2]; 1004 |
1005 zoc0 = Z_RSHIFT((0x19edb6fdLL * zoe1) + (0x05ebd062LL * zoe2) + 1006 (0x00267881LL * zoe3), 30); 1007 zoc1 = Z_RSHIFT((0x1223af76LL * zoo1) + (0x0de3dd6bLL * zoo2) + 1008 (0x00d683cdLL * zoo3), 30); 1009 zoc2 = Z_RSHIFT((-0x0c3ee068LL * zoe1) + (0x0a5c3769LL * zoe2) + 1010 (0x01e2aceaLL * zoe3), 30); 1011 zoc3 = Z_RSHIFT((-0x0a8ab614LL * zoo1) + (-0x0019522eLL * zoo2) + 1012 (0x022cefc7LL * zoo3), 30); 1013 zoc4 = Z_RSHIFT((0x0276187dLL * zoe1) + (-0x03a801e8LL * zoe2) + 1014 (0x0131d935LL * zoe3), 30); 1015 zoc5 = Z_RSHIFT((0x02c373f5LL * zoo1) + (-0x01275f83LL * zoo2) + 1016 (0x0018ee79LL * zoo3), 30); |
1017 |
1018 coeff = Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((Z_RSHIFT((Z_RSHIFT( 1019 (int64_t)zoc5 * zoz, Z_SHIFT) + 1020 zoc4) * zoz, Z_SHIFT) + zoc3) * zoz, Z_SHIFT) + 1021 zoc2) * zoz, Z_SHIFT) + zoc1) * zoz, Z_SHIFT) + zoc0; |
1022#else 1023#error "Interpolation type screwed!" 1024#endif 1025 1026#if Z_POLYPHASE_COEFF_SHIFT > 0 1027 coeff = Z_RSHIFT(coeff, Z_POLYPHASE_COEFF_SHIFT); 1028#endif 1029 return (coeff); --- 714 unchanged lines hidden --- |