Sliding puzzle: Fix graphics size and help text for M3. * Bubbles: Better (larger...
[kugel-rb.git] / apps / dsp.h
blob799d023aee39a12da1fe4696e92398aed2740cc6
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 Miika Pekkarinen
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #ifndef _DSP_H
21 #define _DSP_H
23 #include <stdlib.h>
24 #include <stdbool.h>
26 #define NATIVE_FREQUENCY 44100
27 enum
29 STEREO_INTERLEAVED = 0,
30 STEREO_NONINTERLEAVED,
31 STEREO_MONO,
32 STEREO_NUM_MODES,
35 enum
37 CODEC_IDX_AUDIO = 0,
38 CODEC_IDX_VOICE,
41 enum
43 CODEC_SET_FILEBUF_WATERMARK = 1,
44 DSP_MYDSP,
45 DSP_SET_FREQUENCY,
46 DSP_SWITCH_FREQUENCY,
47 DSP_SET_SAMPLE_DEPTH,
48 DSP_SET_STEREO_MODE,
49 DSP_RESET,
50 DSP_FLUSH,
51 DSP_SET_TRACK_GAIN,
52 DSP_SET_ALBUM_GAIN,
53 DSP_SET_TRACK_PEAK,
54 DSP_SET_ALBUM_PEAK,
55 DSP_CROSSFEED
58 enum {
59 DSP_CALLBACK_SET_PRESCALE = 0,
60 DSP_CALLBACK_SET_BASS,
61 DSP_CALLBACK_SET_TREBLE,
62 DSP_CALLBACK_SET_CHANNEL_CONFIG,
63 DSP_CALLBACK_SET_STEREO_WIDTH
66 /* A bunch of fixed point assembler helper macros */
67 #if defined(CPU_COLDFIRE)
68 /* These macros use the Coldfire EMAC extension and need the MACSR flags set
69 * to fractional mode with no rounding.
72 /* Multiply two S.31 fractional integers and return the sign bit and the
73 * 31 most significant bits of the result.
75 #define FRACMUL(x, y) \
76 ({ \
77 long t; \
78 asm ("mac.l %[a], %[b], %%acc0\n\t" \
79 "movclr.l %%acc0, %[t]\n\t" \
80 : [t] "=r" (t) : [a] "r" (x), [b] "r" (y)); \
81 t; \
84 /* Multiply two S.31 fractional integers, and return the 32 most significant
85 * bits after a shift left by the constant z. NOTE: Only works for shifts of
86 * up to 8 on Coldfire!
88 #define FRACMUL_SHL(x, y, z) \
89 ({ \
90 long t, t2; \
91 asm ("mac.l %[a], %[b], %%acc0\n\t" \
92 "moveq.l %[d], %[t]\n\t" \
93 "move.l %%accext01, %[t2]\n\t" \
94 "and.l %[mask], %[t2]\n\t" \
95 "lsr.l %[t], %[t2]\n\t" \
96 "movclr.l %%acc0, %[t]\n\t" \
97 "asl.l %[c], %[t]\n\t" \
98 "or.l %[t2], %[t]\n\t" \
99 : [t] "=&d" (t), [t2] "=&d" (t2) \
100 : [a] "r" (x), [b] "r" (y), [mask] "d" (0xff), \
101 [c] "i" ((z)), [d] "i" (8 - (z))); \
102 t; \
105 /* Multiply one S.31-bit and one S8.23 fractional integer and return the
106 * sign bit and the 31 most significant bits of the result. Load next value
107 * to multiply with into x from s (and increase s); x must contain the
108 * initial value.
110 #define FRACMUL_8_LOOP(x, y, s, d) \
112 long t, t2; \
113 asm volatile ("mac.l %[a], %[b], (%[src])+, %[a], %%acc0\n\t" \
114 "move.l %%accext01, %[t2]\n\t" \
115 "movclr.l %%acc0, %[t]\n\t" \
116 "asl.l #8, %[t]\n\t" \
117 "move.b %[t2], %[t]\n\t" \
118 "move.l %[t], (%[dst])+\n\t" \
119 : [a] "+r" (x), [src] "+a" (s), [dst] "+a" (d), \
120 [t] "=r" (t), [t2] "=r" (t2) \
121 : [b] "r" (y)); \
124 #define ACC(acc, x, y) \
125 (void)acc; \
126 asm ("mac.l %[a], %[b], %%acc0" \
127 : : [a] "i,r" (x), [b] "i,r" (y));
129 #define GET_ACC(acc) \
130 ({ \
131 long t; \
132 (void)acc; \
133 asm ("movclr.l %%acc0, %[t]" \
134 : [t] "=r" (t)); \
135 t; \
138 #define ACC_INIT(acc, x, y) ACC(acc, x, y)
140 #elif defined(CPU_ARM)
142 /* Multiply two S.31 fractional integers and return the sign bit and the
143 * 31 most significant bits of the result.
145 #define FRACMUL(x, y) \
146 ({ \
147 long t, t2; \
148 asm ("smull %[t], %[t2], %[a], %[b]\n\t" \
149 "mov %[t2], %[t2], asl #1\n\t" \
150 "orr %[t], %[t2], %[t], lsr #31\n\t" \
151 : [t] "=&r" (t), [t2] "=&r" (t2) \
152 : [a] "r" (x), [b] "r" (y)); \
153 t; \
156 /* Multiply two S.31 fractional integers, and return the 32 most significant
157 * bits after a shift left by the constant z.
159 #define FRACMUL_SHL(x, y, z) \
160 ({ \
161 long t, t2; \
162 asm ("smull %[t], %[t2], %[a], %[b]\n\t" \
163 "mov %[t2], %[t2], asl %[c]\n\t" \
164 "orr %[t], %[t2], %[t], lsr %[d]\n\t" \
165 : [t] "=&r" (t), [t2] "=&r" (t2) \
166 : [a] "r" (x), [b] "r" (y), \
167 [c] "M" ((z) + 1), [d] "M" (31 - (z))); \
168 t; \
171 #define ACC_INIT(acc, x, y) acc = FRACMUL(x, y)
172 #define ACC(acc, x, y) acc += FRACMUL(x, y)
173 #define GET_ACC(acc) acc
175 /* Multiply one S.31-bit and one S8.23 fractional integer and store the
176 * sign bit and the 31 most significant bits of the result to d (and
177 * increase d). Load next value to multiply with into x from s (and
178 * increase s); x must contain the initial value.
180 #define FRACMUL_8_LOOP(x, y, s, d) \
181 ({ \
182 long t, t2; \
183 asm volatile ("smull %[t], %[t2], %[a], %[b]\n\t" \
184 "mov %[t2], %[t2], asl #9\n\t" \
185 "orr %[d], %[t2], %[t], lsr #23\n\t" \
186 : [d] "=&r" (*(d)++), [t] "=&r" (t), [t2] "=&r" (t2) \
187 : [a] "r" (x), [b] "r" (y)); \
188 x = *(s)++; \
191 #else
193 #define ACC_INIT(acc, x, y) acc = FRACMUL(x, y)
194 #define ACC(acc, x, y) acc += FRACMUL(x, y)
195 #define GET_ACC(acc) acc
196 #define FRACMUL(x, y) (long) (((((long long) (x)) * ((long long) (y))) >> 31))
197 #define FRACMUL_SHL(x, y, z) \
198 ((long)(((((long long) (x)) * ((long long) (y))) >> (31 - (z)))))
199 #define FRACMUL_8_LOOP(x, y, s, d) \
200 ({ \
201 long t = x; \
202 x = *(s)++; \
203 *(d)++ = (long) (((((long long) (t)) * ((long long) (y))) >> 23)); \
206 #endif
208 #define DIV64(x, y, z) (long)(((long long)(x) << (z))/(y))
210 struct dsp_config;
212 int dsp_process(struct dsp_config *dsp, char *dest,
213 const char *src[], int count);
214 int dsp_input_count(struct dsp_config *dsp, int count);
215 int dsp_output_count(struct dsp_config *dsp, int count);
216 intptr_t dsp_configure(struct dsp_config *dsp, int setting,
217 intptr_t value);
218 void dsp_set_replaygain(void);
219 void dsp_set_crossfeed(bool enable);
220 void dsp_set_crossfeed_direct_gain(int gain);
221 void dsp_set_crossfeed_cross_params(long lf_gain, long hf_gain,
222 long cutoff);
223 void dsp_set_eq(bool enable);
224 void dsp_set_eq_precut(int precut);
225 void dsp_set_eq_coefs(int band);
226 void sound_set_pitch(int r);
227 int sound_get_pitch(void);
228 int dsp_callback(int msg, intptr_t param);
229 void dsp_dither_enable(bool enable);
231 #endif