Get the user timer working properly consequentially fixing doom without a hack.
[Rockbox.git] / apps / dsp.h
blob838dc617ee614112f6e044f04138270284cac0de
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_SET_FILEBUF_WATERMARK = 1,
38 DSP_SWITCH_CODEC,
39 DSP_SET_FREQUENCY,
40 DSP_SWITCH_FREQUENCY,
41 DSP_SET_SAMPLE_DEPTH,
42 DSP_SET_STEREO_MODE,
43 DSP_RESET,
44 DSP_FLUSH,
45 DSP_SET_TRACK_GAIN,
46 DSP_SET_ALBUM_GAIN,
47 DSP_SET_TRACK_PEAK,
48 DSP_SET_ALBUM_PEAK,
49 DSP_CROSSFEED
52 enum {
53 DSP_CALLBACK_SET_PRESCALE = 0,
54 DSP_CALLBACK_SET_BASS,
55 DSP_CALLBACK_SET_TREBLE,
56 DSP_CALLBACK_SET_CHANNEL_CONFIG,
57 DSP_CALLBACK_SET_STEREO_WIDTH
60 /* A bunch of fixed point assembler helper macros */
61 #if defined(CPU_COLDFIRE)
62 /* These macros use the Coldfire EMAC extension and need the MACSR flags set
63 * to fractional mode with no rounding.
66 /* Multiply two S.31 fractional integers and return the sign bit and the
67 * 31 most significant bits of the result.
69 #define FRACMUL(x, y) \
70 ({ \
71 long t; \
72 asm ("mac.l %[a], %[b], %%acc0\n\t" \
73 "movclr.l %%acc0, %[t]\n\t" \
74 : [t] "=r" (t) : [a] "r" (x), [b] "r" (y)); \
75 t; \
78 /* Multiply two S.31 fractional integers, and return the 32 most significant
79 * bits after a shift left by the constant z. NOTE: Only works for shifts of
80 * up to 8 on Coldfire!
82 #define FRACMUL_SHL(x, y, z) \
83 ({ \
84 long t, t2; \
85 asm ("mac.l %[a], %[b], %%acc0\n\t" \
86 "moveq.l %[d], %[t]\n\t" \
87 "move.l %%accext01, %[t2]\n\t" \
88 "and.l %[mask], %[t2]\n\t" \
89 "lsr.l %[t], %[t2]\n\t" \
90 "movclr.l %%acc0, %[t]\n\t" \
91 "asl.l %[c], %[t]\n\t" \
92 "or.l %[t2], %[t]\n\t" \
93 : [t] "=&d" (t), [t2] "=&d" (t2) \
94 : [a] "r" (x), [b] "r" (y), [mask] "d" (0xff), \
95 [c] "i" ((z)), [d] "i" (8 - (z))); \
96 t; \
99 /* Multiply one S.31-bit and one S8.23 fractional integer and return the
100 * sign bit and the 31 most significant bits of the result. Load next value
101 * to multiply with into x from s (and increase s); x must contain the
102 * initial value.
104 #define FRACMUL_8_LOOP(x, y, s, d) \
106 long t, t2; \
107 asm volatile ("mac.l %[a], %[b], (%[src])+, %[a], %%acc0\n\t" \
108 "move.l %%accext01, %[t2]\n\t" \
109 "movclr.l %%acc0, %[t]\n\t" \
110 "asl.l #8, %[t]\n\t" \
111 "move.b %[t2], %[t]\n\t" \
112 "move.l %[t], (%[dst])+\n\t" \
113 : [a] "+r" (x), [src] "+a" (s), [dst] "+a" (d), \
114 [t] "=r" (t), [t2] "=r" (t2) \
115 : [b] "r" (y)); \
118 #define ACC(acc, x, y) \
119 (void)acc; \
120 asm ("mac.l %[a], %[b], %%acc0" \
121 : : [a] "i,r" (x), [b] "i,r" (y));
123 #define GET_ACC(acc) \
124 ({ \
125 long t; \
126 (void)acc; \
127 asm ("movclr.l %%acc0, %[t]" \
128 : [t] "=r" (t)); \
129 t; \
132 #define ACC_INIT(acc, x, y) ACC(acc, x, y)
134 #elif defined(CPU_ARM)
136 /* Multiply two S.31 fractional integers and return the sign bit and the
137 * 31 most significant bits of the result.
139 #define FRACMUL(x, y) \
140 ({ \
141 long t, t2; \
142 asm ("smull %[t], %[t2], %[a], %[b]\n\t" \
143 "mov %[t2], %[t2], asl #1\n\t" \
144 "orr %[t], %[t2], %[t], lsr #31\n\t" \
145 : [t] "=&r" (t), [t2] "=&r" (t2) \
146 : [a] "r" (x), [b] "r" (y)); \
147 t; \
150 /* Multiply two S.31 fractional integers, and return the 32 most significant
151 * bits after a shift left by the constant z.
153 #define FRACMUL_SHL(x, y, z) \
154 ({ \
155 long t, t2; \
156 asm ("smull %[t], %[t2], %[a], %[b]\n\t" \
157 "mov %[t2], %[t2], asl %[c]\n\t" \
158 "orr %[t], %[t2], %[t], lsr %[d]\n\t" \
159 : [t] "=&r" (t), [t2] "=&r" (t2) \
160 : [a] "r" (x), [b] "r" (y), \
161 [c] "M" ((z) + 1), [d] "M" (31 - (z))); \
162 t; \
165 #define ACC_INIT(acc, x, y) acc = FRACMUL(x, y)
166 #define ACC(acc, x, y) acc += FRACMUL(x, y)
167 #define GET_ACC(acc) acc
169 /* Multiply one S.31-bit and one S8.23 fractional integer and store the
170 * sign bit and the 31 most significant bits of the result to d (and
171 * increase d). Load next value to multiply with into x from s (and
172 * increase s); x must contain the initial value.
174 #define FRACMUL_8_LOOP(x, y, s, d) \
175 ({ \
176 long t, t2; \
177 asm volatile ("smull %[t], %[t2], %[a], %[b]\n\t" \
178 "mov %[t2], %[t2], asl #9\n\t" \
179 "orr %[d], %[t2], %[t], lsr #23\n\t" \
180 : [d] "=&r" (*(d)++), [t] "=&r" (t), [t2] "=&r" (t2) \
181 : [a] "r" (x), [b] "r" (y)); \
182 x = *(s)++; \
185 #else
187 #define ACC_INIT(acc, x, y) acc = FRACMUL(x, y)
188 #define ACC(acc, x, y) acc += FRACMUL(x, y)
189 #define GET_ACC(acc) acc
190 #define FRACMUL(x, y) (long) (((((long long) (x)) * ((long long) (y))) >> 31))
191 #define FRACMUL_SHL(x, y, z) \
192 ((long)(((((long long) (x)) * ((long long) (y))) >> (31 - (z)))))
193 #define FRACMUL_8_LOOP(x, y, s, d) \
194 ({ \
195 long t = x; \
196 x = *(s)++; \
197 *(d)++ = (long) (((((long long) (t)) * ((long long) (y))) >> 23)); \
200 #endif
202 #define DIV64(x, y, z) (long)(((long long)(x) << (z))/(y))
204 int dsp_process(char *dest, const char *src[], int count);
205 int dsp_input_count(int count);
206 int dsp_output_count(int count);
207 int dsp_stereo_mode(void);
208 bool dsp_configure(int setting, intptr_t value);
209 void dsp_set_replaygain(void);
210 void dsp_set_crossfeed(bool enable);
211 void dsp_set_crossfeed_direct_gain(int gain);
212 void dsp_set_crossfeed_cross_params(long lf_gain, long hf_gain, long cutoff);
213 void dsp_set_eq(bool enable);
214 void dsp_set_eq_precut(int precut);
215 void dsp_set_eq_coefs(int band);
216 void sound_set_pitch(int r);
217 int sound_get_pitch(void);
218 int dsp_callback(int msg, intptr_t param);
219 void dsp_set_channel_config(int value);
220 void dsp_set_stereo_width(int value);
221 void dsp_dither_enable(bool enable);
223 #endif