Make the mips compiler not complain when bitwise operations do not have parenthesis.
[kugel-rb.git] / apps / dsp.h
blobc3239360b03c43c979483fd615f33812f5e379ac
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 Miika Pekkarinen
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #ifndef _DSP_H
23 #define _DSP_H
25 #include <stdlib.h>
26 #include <stdbool.h>
28 #define NATIVE_FREQUENCY 44100
29 enum
31 STEREO_INTERLEAVED = 0,
32 STEREO_NONINTERLEAVED,
33 STEREO_MONO,
34 STEREO_NUM_MODES,
37 enum
39 CODEC_IDX_AUDIO = 0,
40 CODEC_IDX_VOICE,
43 enum
45 DSP_MYDSP = 1,
46 DSP_SET_FREQUENCY,
47 DSP_SWITCH_FREQUENCY,
48 DSP_SET_SAMPLE_DEPTH,
49 DSP_SET_STEREO_MODE,
50 DSP_RESET,
51 DSP_FLUSH,
52 DSP_SET_TRACK_GAIN,
53 DSP_SET_ALBUM_GAIN,
54 DSP_SET_TRACK_PEAK,
55 DSP_SET_ALBUM_PEAK,
56 DSP_CROSSFEED
59 enum {
60 DSP_CALLBACK_SET_PRESCALE = 0,
61 DSP_CALLBACK_SET_BASS,
62 DSP_CALLBACK_SET_TREBLE,
63 DSP_CALLBACK_SET_CHANNEL_CONFIG,
64 DSP_CALLBACK_SET_STEREO_WIDTH
67 /* A bunch of fixed point assembler helper macros */
68 #if defined(CPU_COLDFIRE)
69 /* These macros use the Coldfire EMAC extension and need the MACSR flags set
70 * to fractional mode with no rounding.
73 /* Multiply two S.31 fractional integers and return the sign bit and the
74 * 31 most significant bits of the result.
76 #define FRACMUL(x, y) \
77 ({ \
78 long t; \
79 asm ("mac.l %[a], %[b], %%acc0\n\t" \
80 "movclr.l %%acc0, %[t]\n\t" \
81 : [t] "=r" (t) : [a] "r" (x), [b] "r" (y)); \
82 t; \
85 /* Multiply two S.31 fractional integers, and return the 32 most significant
86 * bits after a shift left by the constant z. NOTE: Only works for shifts of
87 * 1 to 8 on Coldfire!
89 #define FRACMUL_SHL(x, y, z) \
90 ({ \
91 long t, t2; \
92 asm ("mac.l %[a], %[b], %%acc0\n\t" \
93 "moveq.l %[d], %[t]\n\t" \
94 "move.l %%accext01, %[t2]\n\t" \
95 "and.l %[mask], %[t2]\n\t" \
96 "lsr.l %[t], %[t2]\n\t" \
97 "movclr.l %%acc0, %[t]\n\t" \
98 "asl.l %[c], %[t]\n\t" \
99 "or.l %[t2], %[t]\n\t" \
100 : [t] "=&d" (t), [t2] "=&d" (t2) \
101 : [a] "r" (x), [b] "r" (y), [mask] "d" (0xff), \
102 [c] "i" ((z)), [d] "i" (8 - (z))); \
103 t; \
106 #elif defined(CPU_ARM)
108 /* Multiply two S.31 fractional integers and return the sign bit and the
109 * 31 most significant bits of the result.
111 #define FRACMUL(x, y) \
112 ({ \
113 long t, t2; \
114 asm ("smull %[t], %[t2], %[a], %[b]\n\t" \
115 "mov %[t2], %[t2], asl #1\n\t" \
116 "orr %[t], %[t2], %[t], lsr #31\n\t" \
117 : [t] "=&r" (t), [t2] "=&r" (t2) \
118 : [a] "r" (x), [b] "r" (y)); \
119 t; \
122 /* Multiply two S.31 fractional integers, and return the 32 most significant
123 * bits after a shift left by the constant z.
125 #define FRACMUL_SHL(x, y, z) \
126 ({ \
127 long t, t2; \
128 asm ("smull %[t], %[t2], %[a], %[b]\n\t" \
129 "mov %[t2], %[t2], asl %[c]\n\t" \
130 "orr %[t], %[t2], %[t], lsr %[d]\n\t" \
131 : [t] "=&r" (t), [t2] "=&r" (t2) \
132 : [a] "r" (x), [b] "r" (y), \
133 [c] "M" ((z) + 1), [d] "M" (31 - (z))); \
134 t; \
137 #else
139 #define FRACMUL(x, y) (long) (((((long long) (x)) * ((long long) (y))) >> 31))
140 #define FRACMUL_SHL(x, y, z) \
141 ((long)(((((long long) (x)) * ((long long) (y))) >> (31 - (z)))))
143 #endif
145 #define DIV64(x, y, z) (long)(((long long)(x) << (z))/(y))
147 struct dsp_config;
149 int dsp_process(struct dsp_config *dsp, char *dest,
150 const char *src[], int count);
151 int dsp_input_count(struct dsp_config *dsp, int count);
152 int dsp_output_count(struct dsp_config *dsp, int count);
153 intptr_t dsp_configure(struct dsp_config *dsp, int setting,
154 intptr_t value);
155 void dsp_set_replaygain(void);
156 void dsp_set_crossfeed(bool enable);
157 void dsp_set_crossfeed_direct_gain(int gain);
158 void dsp_set_crossfeed_cross_params(long lf_gain, long hf_gain,
159 long cutoff);
160 void dsp_set_eq(bool enable);
161 void dsp_set_eq_precut(int precut);
162 void dsp_set_eq_coefs(int band);
163 void sound_set_pitch(int r);
164 int sound_get_pitch(void);
165 int dsp_callback(int msg, intptr_t param);
166 void dsp_dither_enable(bool enable);
168 #endif