Also rename as3525_codec in the e200/fuze backlight driver
[kugel-rb.git] / apps / dsp.h
blob1746a5cccc276337e09e55764a8cff0c52667ec4
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 CODEC_SET_FILEBUF_WATERMARK = 1,
46 DSP_MYDSP,
47 DSP_SET_FREQUENCY,
48 DSP_SWITCH_FREQUENCY,
49 DSP_SET_SAMPLE_DEPTH,
50 DSP_SET_STEREO_MODE,
51 DSP_RESET,
52 DSP_FLUSH,
53 DSP_SET_TRACK_GAIN,
54 DSP_SET_ALBUM_GAIN,
55 DSP_SET_TRACK_PEAK,
56 DSP_SET_ALBUM_PEAK,
57 DSP_CROSSFEED
60 enum {
61 DSP_CALLBACK_SET_PRESCALE = 0,
62 DSP_CALLBACK_SET_BASS,
63 DSP_CALLBACK_SET_TREBLE,
64 DSP_CALLBACK_SET_CHANNEL_CONFIG,
65 DSP_CALLBACK_SET_STEREO_WIDTH
68 /* A bunch of fixed point assembler helper macros */
69 #if defined(CPU_COLDFIRE)
70 /* These macros use the Coldfire EMAC extension and need the MACSR flags set
71 * to fractional mode with no rounding.
74 /* Multiply two S.31 fractional integers and return the sign bit and the
75 * 31 most significant bits of the result.
77 #define FRACMUL(x, y) \
78 ({ \
79 long t; \
80 asm ("mac.l %[a], %[b], %%acc0\n\t" \
81 "movclr.l %%acc0, %[t]\n\t" \
82 : [t] "=r" (t) : [a] "r" (x), [b] "r" (y)); \
83 t; \
86 /* Multiply two S.31 fractional integers, and return the 32 most significant
87 * bits after a shift left by the constant z. NOTE: Only works for shifts of
88 * 1 to 8 on Coldfire!
90 #define FRACMUL_SHL(x, y, z) \
91 ({ \
92 long t, t2; \
93 asm ("mac.l %[a], %[b], %%acc0\n\t" \
94 "moveq.l %[d], %[t]\n\t" \
95 "move.l %%accext01, %[t2]\n\t" \
96 "and.l %[mask], %[t2]\n\t" \
97 "lsr.l %[t], %[t2]\n\t" \
98 "movclr.l %%acc0, %[t]\n\t" \
99 "asl.l %[c], %[t]\n\t" \
100 "or.l %[t2], %[t]\n\t" \
101 : [t] "=&d" (t), [t2] "=&d" (t2) \
102 : [a] "r" (x), [b] "r" (y), [mask] "d" (0xff), \
103 [c] "i" ((z)), [d] "i" (8 - (z))); \
104 t; \
107 #elif defined(CPU_ARM)
109 /* Multiply two S.31 fractional integers and return the sign bit and the
110 * 31 most significant bits of the result.
112 #define FRACMUL(x, y) \
113 ({ \
114 long t, t2; \
115 asm ("smull %[t], %[t2], %[a], %[b]\n\t" \
116 "mov %[t2], %[t2], asl #1\n\t" \
117 "orr %[t], %[t2], %[t], lsr #31\n\t" \
118 : [t] "=&r" (t), [t2] "=&r" (t2) \
119 : [a] "r" (x), [b] "r" (y)); \
120 t; \
123 /* Multiply two S.31 fractional integers, and return the 32 most significant
124 * bits after a shift left by the constant z.
126 #define FRACMUL_SHL(x, y, z) \
127 ({ \
128 long t, t2; \
129 asm ("smull %[t], %[t2], %[a], %[b]\n\t" \
130 "mov %[t2], %[t2], asl %[c]\n\t" \
131 "orr %[t], %[t2], %[t], lsr %[d]\n\t" \
132 : [t] "=&r" (t), [t2] "=&r" (t2) \
133 : [a] "r" (x), [b] "r" (y), \
134 [c] "M" ((z) + 1), [d] "M" (31 - (z))); \
135 t; \
138 #else
140 #define FRACMUL(x, y) (long) (((((long long) (x)) * ((long long) (y))) >> 31))
141 #define FRACMUL_SHL(x, y, z) \
142 ((long)(((((long long) (x)) * ((long long) (y))) >> (31 - (z)))))
144 #endif
146 #define DIV64(x, y, z) (long)(((long long)(x) << (z))/(y))
148 struct dsp_config;
150 int dsp_process(struct dsp_config *dsp, char *dest,
151 const char *src[], int count);
152 int dsp_input_count(struct dsp_config *dsp, int count);
153 int dsp_output_count(struct dsp_config *dsp, int count);
154 intptr_t dsp_configure(struct dsp_config *dsp, int setting,
155 intptr_t value);
156 void dsp_set_replaygain(void);
157 void dsp_set_crossfeed(bool enable);
158 void dsp_set_crossfeed_direct_gain(int gain);
159 void dsp_set_crossfeed_cross_params(long lf_gain, long hf_gain,
160 long cutoff);
161 void dsp_set_eq(bool enable);
162 void dsp_set_eq_precut(int precut);
163 void dsp_set_eq_coefs(int band);
164 void sound_set_pitch(int r);
165 int sound_get_pitch(void);
166 int dsp_callback(int msg, intptr_t param);
167 void dsp_dither_enable(bool enable);
169 #endif