add True Audio (TTA) codec
[kugel-rb.git] / apps / codecs / libtta / filter.h
blob6eef6dcf421846555e09dd2f0c68699e21a3bbd6
1 /*
2 * filter.h
4 * Description: TTAv1 filter functions
5 * Developed by: Alexander Djourik <ald@true-audio.com>
6 * Pavel Zhilin <pzh@true-audio.com>
8 * Copyright (c) 2004 True Audio Software. All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
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.
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.
39 #ifndef FILTER_H
40 #define FILTER_H
42 ///////// Filter Settings //////////
43 static int flt_set[3] = {10, 9, 10};
45 #ifdef CPU_ARM
46 int hybrid_filter(fltst *fs, int *in); /* implements in filter_arm.S */
48 #else
50 static inline void
51 memshl (register int *pA) {
52 register int *pB = pA + 16;
54 *pA++ = *pB++;
55 *pA++ = *pB++;
56 *pA++ = *pB++;
57 *pA++ = *pB++;
58 *pA++ = *pB++;
59 *pA++ = *pB++;
60 *pA++ = *pB++;
61 *pA = *pB;
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;
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++);
101 pB = pA++;
102 fs->error = *in;
103 *in += (sum >> fs->shift);
104 *pA = *in;
106 *pM-- = ((*pB-- >> 30) | 1) << 2;
107 *pM-- = ((*pB-- >> 30) | 1) << 1;
108 *pM-- = ((*pB-- >> 30) | 1) << 1;
109 *pM = ((*pB >> 30) | 1);
111 *(pA-1) = *(pA-0) - *(pA-1);
112 *(pA-2) = *(pA-1) - *(pA-2);
113 *(pA-3) = *(pA-2) - *(pA-3);
116 * Rockbox speciffic
117 * in order to make speed up, memshl() is executed at the rate once every 16 times.
119 if (++fs->index == 16)
121 memshl (fs->dl);
122 memshl (fs->dx);
123 fs->index = 0;
126 #endif
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;
136 #endif /* FILTER_H */