diff options
Diffstat (limited to 'apps/codecs/libtta/filter.h')
-rw-r--r-- | apps/codecs/libtta/filter.h | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/apps/codecs/libtta/filter.h b/apps/codecs/libtta/filter.h new file mode 100644 index 0000000000..6eef6dcf42 --- /dev/null +++ b/apps/codecs/libtta/filter.h | |||
@@ -0,0 +1,136 @@ | |||
1 | /* | ||
2 | * filter.h | ||
3 | * | ||
4 | * Description: TTAv1 filter functions | ||
5 | * Developed by: Alexander Djourik <ald@true-audio.com> | ||
6 | * Pavel Zhilin <pzh@true-audio.com> | ||
7 | * | ||
8 | * Copyright (c) 2004 True Audio Software. All rights reserved. | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * Redistribution and use in source and binary forms, with or without | ||
14 | * modification, are permitted provided that the following conditions | ||
15 | * are met: | ||
16 | * | ||
17 | * 1. Redistributions of source code must retain the above copyright | ||
18 | * notice, this list of conditions and the following disclaimer. | ||
19 | * 2. Redistributions in binary form must reproduce the above copyright | ||
20 | * notice, this list of conditions and the following disclaimer in the | ||
21 | * documentation and/or other materials provided with the distribution. | ||
22 | * 3. Neither the name of the True Audio Software nor the names of its | ||
23 | * contributors may be used to endorse or promote products derived | ||
24 | * from this software without specific prior written permission. | ||
25 | * | ||
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
29 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
30 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
31 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
32 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
33 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
34 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
35 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
36 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
37 | */ | ||
38 | |||
39 | #ifndef FILTER_H | ||
40 | #define FILTER_H | ||
41 | |||
42 | ///////// Filter Settings ////////// | ||
43 | static int flt_set[3] = {10, 9, 10}; | ||
44 | |||
45 | #ifdef CPU_ARM | ||
46 | int hybrid_filter(fltst *fs, int *in); /* implements in filter_arm.S */ | ||
47 | |||
48 | #else | ||
49 | |||
50 | static inline void | ||
51 | memshl (register int *pA) { | ||
52 | register int *pB = pA + 16; | ||
53 | |||
54 | *pA++ = *pB++; | ||
55 | *pA++ = *pB++; | ||
56 | *pA++ = *pB++; | ||
57 | *pA++ = *pB++; | ||
58 | *pA++ = *pB++; | ||
59 | *pA++ = *pB++; | ||
60 | *pA++ = *pB++; | ||
61 | *pA = *pB; | ||
62 | } | ||
63 | |||
64 | static inline void | ||
65 | hybrid_filter (fltst *fs, int *in) { | ||
66 | register int *pA = fs->dl + fs->index; | ||
67 | register int *pB = fs->qm; | ||
68 | register int *pM = fs->dx + fs->index; | ||
69 | register int sum = fs->round; | ||
70 | |||
71 | if (!fs->error) { | ||
72 | sum += *pA++ * *pB++; | ||
73 | sum += *pA++ * *pB++; | ||
74 | sum += *pA++ * *pB++; | ||
75 | sum += *pA++ * *pB++; | ||
76 | sum += *pA++ * *pB++; | ||
77 | sum += *pA++ * *pB++; | ||
78 | sum += *pA++ * *pB++; | ||
79 | sum += *pA * *pB; | ||
80 | pM += 8; | ||
81 | } else if (fs->error < 0) { | ||
82 | sum += *pA++ * (*pB++ -= *pM++); | ||
83 | sum += *pA++ * (*pB++ -= *pM++); | ||
84 | sum += *pA++ * (*pB++ -= *pM++); | ||
85 | sum += *pA++ * (*pB++ -= *pM++); | ||
86 | sum += *pA++ * (*pB++ -= *pM++); | ||
87 | sum += *pA++ * (*pB++ -= *pM++); | ||
88 | sum += *pA++ * (*pB++ -= *pM++); | ||
89 | sum += *pA * (*pB -= *pM++); | ||
90 | } else { | ||
91 | sum += *pA++ * (*pB++ += *pM++); | ||
92 | sum += *pA++ * (*pB++ += *pM++); | ||
93 | sum += *pA++ * (*pB++ += *pM++); | ||
94 | sum += *pA++ * (*pB++ += *pM++); | ||
95 | sum += *pA++ * (*pB++ += *pM++); | ||
96 | sum += *pA++ * (*pB++ += *pM++); | ||
97 | sum += *pA++ * (*pB++ += *pM++); | ||
98 | sum += *pA * (*pB += *pM++); | ||
99 | } | ||
100 | |||
101 | pB = pA++; | ||
102 | fs->error = *in; | ||
103 | *in += (sum >> fs->shift); | ||
104 | *pA = *in; | ||
105 | |||
106 | *pM-- = ((*pB-- >> 30) | 1) << 2; | ||
107 | *pM-- = ((*pB-- >> 30) | 1) << 1; | ||
108 | *pM-- = ((*pB-- >> 30) | 1) << 1; | ||
109 | *pM = ((*pB >> 30) | 1); | ||
110 | |||
111 | *(pA-1) = *(pA-0) - *(pA-1); | ||
112 | *(pA-2) = *(pA-1) - *(pA-2); | ||
113 | *(pA-3) = *(pA-2) - *(pA-3); | ||
114 | |||
115 | /* | ||
116 | * Rockbox speciffic | ||
117 | * in order to make speed up, memshl() is executed at the rate once every 16 times. | ||
118 | */ | ||
119 | if (++fs->index == 16) | ||
120 | { | ||
121 | memshl (fs->dl); | ||
122 | memshl (fs->dx); | ||
123 | fs->index = 0; | ||
124 | } | ||
125 | } | ||
126 | #endif | ||
127 | |||
128 | static inline void | ||
129 | filter_init (fltst *fs, int shift) { | ||
130 | ci->memset (fs, 0, sizeof(fltst)); | ||
131 | fs->shift = shift; | ||
132 | fs->round = 1 << (shift - 1); | ||
133 | fs->index = 0; | ||
134 | } | ||
135 | |||
136 | #endif /* FILTER_H */ | ||