summaryrefslogtreecommitdiff
path: root/firmware/drivers/audio/mas35xx.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2013-04-12 23:35:47 -0400
committerMichael Sevakis <jethead71@rockbox.org>2013-04-15 12:02:05 -0400
commit0c7b7873984e04941c9f21fa272638018fdb9a16 (patch)
treefb6afca45d2bef0a2c91732a39ffc0b965f5c557 /firmware/drivers/audio/mas35xx.c
parentfd9e2568908f91b5bcf7378dc28f6ec070d6027a (diff)
downloadrockbox-0c7b7873984e04941c9f21fa272638018fdb9a16.tar.gz
rockbox-0c7b7873984e04941c9f21fa272638018fdb9a16.zip
Straighten out the mad twisted state of sound.c and related areas.
This is going right in since it's long overdue. If anything is goofed, drop me a line or just tweak it yourself if you know what's wrong. :-) Make HW/SW codec interface more uniform when emulating HW functionality on SWCODEC for functions such as "audiohw_set_pitch". The firmware-to- DSP plumbing is in firmware/drivers/audiohw-swcodec.c. "sound_XXX" APIs are all in sound.c with none in DSP code any longer. Reduce number of settings definitions needed by each codec by providing defaults for common ones like balance, channels and SW tone controls. Remove need for separate SIM code and tables and add virtual codec header for hosted targets. Change-Id: I3f23702bca054fc9bda40f49824ce681bb7f777b
Diffstat (limited to 'firmware/drivers/audio/mas35xx.c')
-rw-r--r--firmware/drivers/audio/mas35xx.c71
1 files changed, 37 insertions, 34 deletions
diff --git a/firmware/drivers/audio/mas35xx.c b/firmware/drivers/audio/mas35xx.c
index e6cc665109..deb9223187 100644
--- a/firmware/drivers/audio/mas35xx.c
+++ b/firmware/drivers/audio/mas35xx.c
@@ -26,36 +26,6 @@
26#include "system.h" /* MAX MIN macros */ 26#include "system.h" /* MAX MIN macros */
27#include "audiohw.h" 27#include "audiohw.h"
28 28
29const struct sound_settings_info audiohw_settings[] = {
30#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
31 [SOUND_VOLUME] = {"dB", 0, 1,-100, 12, -25},
32 [SOUND_BASS] = {"dB", 0, 1, -12, 12, 6},
33 [SOUND_TREBLE] = {"dB", 0, 1, -12, 12, 6},
34#elif CONFIG_CODEC == MAS3507D
35 [SOUND_VOLUME] = {"dB", 0, 1, -78, 18, -18},
36 [SOUND_BASS] = {"dB", 0, 1, -15, 15, 7},
37 [SOUND_TREBLE] = {"dB", 0, 1, -15, 15, 7},
38#endif
39 [SOUND_BALANCE] = {"%", 0, 1,-100, 100, 0},
40 [SOUND_CHANNELS] = {"", 0, 1, 0, 5, 0},
41 [SOUND_STEREO_WIDTH] = {"%", 0, 5, 0, 250, 100},
42#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
43 [SOUND_LOUDNESS] = {"dB", 0, 1, 0, 17, 0},
44 [SOUND_AVC] = {"", 0, 1, -1, 4, 0},
45 [SOUND_MDB_STRENGTH] = {"dB", 0, 1, 0, 127, 48},
46 [SOUND_MDB_HARMONICS] = {"%", 0, 1, 0, 100, 50},
47 [SOUND_MDB_CENTER] = {"Hz", 0, 10, 20, 300, 60},
48 [SOUND_MDB_SHAPE] = {"Hz", 0, 10, 50, 300, 90},
49 [SOUND_MDB_ENABLE] = {"", 0, 1, 0, 1, 0},
50 [SOUND_SUPERBASS] = {"", 0, 1, 0, 1, 0},
51#endif
52#if CONFIG_CODEC == MAS3587F && defined(HAVE_RECORDING)
53 [SOUND_LEFT_GAIN] = {"dB", 1, 1, 0, 15, 8},
54 [SOUND_RIGHT_GAIN] = {"dB", 1, 1, 0, 15, 8},
55 [SOUND_MIC_GAIN] = {"dB", 1, 1, 0, 15, 2},
56#endif
57};
58
59int channel_configuration = SOUND_CHAN_STEREO; 29int channel_configuration = SOUND_CHAN_STEREO;
60int stereo_width = 100; 30int stereo_width = 100;
61 31
@@ -65,7 +35,6 @@ unsigned long loudness_shadow = 0;
65unsigned long shadow_io_control_main; 35unsigned long shadow_io_control_main;
66#endif 36#endif
67 37
68
69static void set_channel_config(void) 38static void set_channel_config(void)
70{ 39{
71 /* default values: stereo */ 40 /* default values: stereo */
@@ -185,6 +154,22 @@ void audiohw_set_treble(int val)
185#endif 154#endif
186} 155}
187 156
157#if (CONFIG_CODEC == MAS3507D)
158/* convert tenth of dB volume (-780..+180) to dac3550 register value */
159static unsigned int tenthdb2reg(int db)
160{
161 if (db < -540) /* 3 dB steps */
162 return (db + 780) / 30;
163 else /* 1.5 dB steps */
164 return (db + 660) / 15;
165}
166
167void audiohw_set_volume(int vol_l, int vol_r)
168{
169 dac_volume(tenthdb2reg(vol_l), tenthdb2reg(vol_r), false);
170}
171#endif /* CONFIG_CODEC == MAS3507D */
172
188#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) 173#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
189void audiohw_set_volume(int val) 174void audiohw_set_volume(int val)
190{ 175{
@@ -268,14 +253,32 @@ void audiohw_set_balance(int val)
268 mas_codec_writereg(MAS_REG_BALANCE, tmp); 253 mas_codec_writereg(MAS_REG_BALANCE, tmp);
269} 254}
270 255
271void audiohw_set_pitch(unsigned long val) 256/* This functionality works by telling the decoder that we have another
257 crystal frequency than we actually have. It will adjust its internal
258 parameters and the result is that the audio is played at another pitch.
259*/
260static int32_t last_pitch = PITCH_SPEED_100;
261
262void audiohw_set_pitch(int32_t val)
272{ 263{
273 mas_writemem(MAS_BANK_D0, MAS_D0_OFREQ_CONTROL, &val, 1); 264 if (val == last_pitch)
265 return;
266
267 /* Calculate the new (bogus) frequency */
268 unsigned long reg = 18432 * PITCH_SPEED_100 / val;
269 mas_writemem(MAS_BANK_D0, MAS_D0_OFREQ_CONTROL, &reg, 1);
274 270
275 /* We must tell the MAS that the frequency has changed. 271 /* We must tell the MAS that the frequency has changed.
276 * This will unfortunately cause a short silence. */ 272 * This will unfortunately cause a short silence. */
273 mas_writemem(MAS_BANK_D0, MAS_D0_IO_CONTROL_MAIN,
274 &shadow_io_control_main, 1);
275
276 last_pitch = val;
277}
277 278
278 mas_writemem(MAS_BANK_D0, MAS_D0_IO_CONTROL_MAIN, &shadow_io_control_main, 1); 279int32_t audiohw_get_pitch(void)
280{
281 return last_pitch;
279} 282}
280 283
281#endif /* CONFIG_CODEC == MAS3587F || CONFIG_CODEC == MAS3539F */ 284#endif /* CONFIG_CODEC == MAS3587F || CONFIG_CODEC == MAS3539F */