summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2005-04-01 13:41:03 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2005-04-01 13:41:03 +0000
commit674eaca5ef59625f90088da006eca4d10e2bea56 (patch)
treeb0f02cec358ce1c506fb6d2256e2db059c7b6b6a
parent88d5aab5a1098c5636584ddf06bd3012dc8c5b4c (diff)
downloadrockbox-674eaca5ef59625f90088da006eca4d10e2bea56.tar.gz
rockbox-674eaca5ef59625f90088da006eca4d10e2bea56.zip
Moved the mpeg_sound_xxx() functions to sound.c and renamed them to sound_xxx()
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6240 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugin.c5
-rw-r--r--apps/plugin.h5
-rw-r--r--apps/plugins/alpine_cdc.c28
-rw-r--r--apps/plugins/metronome.c2
-rw-r--r--apps/plugins/oscilloscope.c4
-rw-r--r--apps/plugins/splitedit.c6
-rw-r--r--apps/plugins/video.c2
-rw-r--r--apps/plugins/vu_meter.c2
-rw-r--r--apps/recorder/radio.c20
-rw-r--r--apps/recorder/recording.c41
-rw-r--r--apps/screens.c13
-rw-r--r--apps/settings.c57
-rw-r--r--apps/sound_menu.c23
-rw-r--r--apps/status.c3
-rw-r--r--apps/wps.c23
-rw-r--r--firmware/SOURCES5
-rw-r--r--firmware/export/mp3_playback.h40
-rw-r--r--firmware/export/sound.h61
-rw-r--r--firmware/mp3_playback.c642
-rw-r--r--firmware/mpeg.c3
-rw-r--r--firmware/sound.c634
21 files changed, 841 insertions, 778 deletions
diff --git a/apps/plugin.c b/apps/plugin.c
index 35f03703ba..2031f0d450 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -44,6 +44,7 @@
44#include "mp3data.h" 44#include "mp3data.h"
45#include "powermgmt.h" 45#include "powermgmt.h"
46#include "system.h" 46#include "system.h"
47#include "sound.h"
47#if (CONFIG_HWCODEC == MASNONE) 48#if (CONFIG_HWCODEC == MASNONE)
48#include "pcm_playback.h" 49#include "pcm_playback.h"
49#endif 50#endif
@@ -188,7 +189,7 @@ static const struct plugin_api rockbox_api = {
188 memcmp, 189 memcmp,
189 190
190 /* sound */ 191 /* sound */
191 mpeg_sound_set, 192 sound_set,
192#ifndef SIMULATOR 193#ifndef SIMULATOR
193 mp3_play_data, 194 mp3_play_data,
194 mp3_play_pause, 195 mp3_play_pause,
@@ -214,7 +215,7 @@ static const struct plugin_api rockbox_api = {
214 mpeg_get_file_pos, 215 mpeg_get_file_pos,
215 mpeg_get_last_header, 216 mpeg_get_last_header,
216#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F) 217#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
217 mpeg_set_pitch, 218 sound_set_pitch,
218#endif 219#endif
219 220
220#if !defined(SIMULATOR) && (CONFIG_HWCODEC != MASNONE) 221#if !defined(SIMULATOR) && (CONFIG_HWCODEC != MASNONE)
diff --git a/apps/plugin.h b/apps/plugin.h
index 0707393b59..45f03555ec 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -50,6 +50,7 @@
50#ifdef HAVE_LCD_BITMAP 50#ifdef HAVE_LCD_BITMAP
51#include "widgets.h" 51#include "widgets.h"
52#endif 52#endif
53#include "sound.h"
53 54
54#ifdef PLUGIN 55#ifdef PLUGIN
55#if defined(DEBUG) || defined(SIMULATOR) 56#if defined(DEBUG) || defined(SIMULATOR)
@@ -228,7 +229,7 @@ struct plugin_api {
228 int (*memcmp)(const void *s1, const void *s2, size_t n); 229 int (*memcmp)(const void *s1, const void *s2, size_t n);
229 230
230 /* sound */ 231 /* sound */
231 void (*mpeg_sound_set)(int setting, int value); 232 void (*sound_set)(int setting, int value);
232#ifndef SIMULATOR 233#ifndef SIMULATOR
233 void (*mp3_play_data)(const unsigned char* start, int size, void (*get_more)(unsigned char** start, int* size)); 234 void (*mp3_play_data)(const unsigned char* start, int size, void (*get_more)(unsigned char** start, int* size));
234 void (*mp3_play_pause)(bool play); 235 void (*mp3_play_pause)(bool play);
@@ -254,7 +255,7 @@ struct plugin_api {
254 int (*mpeg_get_file_pos)(void); 255 int (*mpeg_get_file_pos)(void);
255 unsigned long (*mpeg_get_last_header)(void); 256 unsigned long (*mpeg_get_last_header)(void);
256#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F) 257#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
257 void (*mpeg_set_pitch)(int pitch); 258 void (*sound_set_pitch)(int pitch);
258#endif 259#endif
259 260
260 /* MAS communication */ 261 /* MAS communication */
diff --git a/apps/plugins/alpine_cdc.c b/apps/plugins/alpine_cdc.c
index 742e0bc6f5..d944810b31 100644
--- a/apps/plugins/alpine_cdc.c
+++ b/apps/plugins/alpine_cdc.c
@@ -1042,25 +1042,25 @@ void set_position(int seconds)
1042/* set to everything flat and 0 dB volume */ 1042/* set to everything flat and 0 dB volume */
1043void sound_neutral(void) 1043void sound_neutral(void)
1044{ /* neutral sound settings */ 1044{ /* neutral sound settings */
1045 rb->mpeg_sound_set(SOUND_BASS, 0); 1045 rb->sound_set(SOUND_BASS, 0);
1046 rb->mpeg_sound_set(SOUND_TREBLE, 0); 1046 rb->sound_set(SOUND_TREBLE, 0);
1047 rb->mpeg_sound_set(SOUND_BALANCE, 0); 1047 rb->sound_set(SOUND_BALANCE, 0);
1048 rb->mpeg_sound_set(SOUND_VOLUME, 92); /* 0 dB */ 1048 rb->sound_set(SOUND_VOLUME, 92); /* 0 dB */
1049 rb->mpeg_sound_set(SOUND_LOUDNESS, 0); 1049 rb->sound_set(SOUND_LOUDNESS, 0);
1050 rb->mpeg_sound_set(SOUND_SUPERBASS, 0); 1050 rb->sound_set(SOUND_SUPERBASS, 0);
1051 rb->mpeg_sound_set(SOUND_AVC, 0); 1051 rb->sound_set(SOUND_AVC, 0);
1052} 1052}
1053 1053
1054/* return to user settings */ 1054/* return to user settings */
1055void sound_normal(void) 1055void sound_normal(void)
1056{ /* restore sound settings */ 1056{ /* restore sound settings */
1057 rb->mpeg_sound_set(SOUND_BASS, rb->global_settings->bass); 1057 rb->sound_set(SOUND_BASS, rb->global_settings->bass);
1058 rb->mpeg_sound_set(SOUND_TREBLE, rb->global_settings->treble); 1058 rb->sound_set(SOUND_TREBLE, rb->global_settings->treble);
1059 rb->mpeg_sound_set(SOUND_BALANCE, rb->global_settings->balance); 1059 rb->sound_set(SOUND_BALANCE, rb->global_settings->balance);
1060 rb->mpeg_sound_set(SOUND_VOLUME, rb->global_settings->volume); 1060 rb->sound_set(SOUND_VOLUME, rb->global_settings->volume);
1061 rb->mpeg_sound_set(SOUND_LOUDNESS, rb->global_settings->loudness); 1061 rb->sound_set(SOUND_LOUDNESS, rb->global_settings->loudness);
1062 rb->mpeg_sound_set(SOUND_SUPERBASS, rb->global_settings->superbass); 1062 rb->sound_set(SOUND_SUPERBASS, rb->global_settings->superbass);
1063 rb->mpeg_sound_set(SOUND_AVC, rb->global_settings->avc); 1063 rb->sound_set(SOUND_AVC, rb->global_settings->avc);
1064} 1064}
1065 1065
1066/* the thread running it all */ 1066/* the thread running it all */
diff --git a/apps/plugins/metronome.c b/apps/plugins/metronome.c
index 98b516f9e8..3793fd9690 100644
--- a/apps/plugins/metronome.c
+++ b/apps/plugins/metronome.c
@@ -201,7 +201,7 @@ void change_volume(int delta){
201 if (vol > 100) vol = 100; 201 if (vol > 100) vol = 100;
202 else if (vol < 0) vol = 0; 202 else if (vol < 0) vol = 0;
203 if (vol != rb->global_settings->volume) { 203 if (vol != rb->global_settings->volume) {
204 rb->mpeg_sound_set(SOUND_VOLUME, vol); 204 rb->sound_set(SOUND_VOLUME, vol);
205 rb->global_settings->volume = vol; 205 rb->global_settings->volume = vol;
206 rb->snprintf(buffer, sizeof(buffer), "Vol: %d ", vol); 206 rb->snprintf(buffer, sizeof(buffer), "Vol: %d ", vol);
207#ifdef HAVE_LCD_BITMAP 207#ifdef HAVE_LCD_BITMAP
diff --git a/apps/plugins/oscilloscope.c b/apps/plugins/oscilloscope.c
index caa09a0ed4..868a20547c 100644
--- a/apps/plugins/oscilloscope.c
+++ b/apps/plugins/oscilloscope.c
@@ -242,7 +242,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
242 if (vol < 100) 242 if (vol < 100)
243 { 243 {
244 vol++; 244 vol++;
245 rb->mpeg_sound_set(SOUND_VOLUME, vol); 245 rb->sound_set(SOUND_VOLUME, vol);
246 rb->global_settings->volume = vol; 246 rb->global_settings->volume = vol;
247 } 247 }
248 break; 248 break;
@@ -253,7 +253,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
253 if (vol > 0) 253 if (vol > 0)
254 { 254 {
255 vol--; 255 vol--;
256 rb->mpeg_sound_set(SOUND_VOLUME, vol); 256 rb->sound_set(SOUND_VOLUME, vol);
257 rb->global_settings->volume = vol; 257 rb->global_settings->volume = vol;
258 } 258 }
259 break; 259 break;
diff --git a/apps/plugins/splitedit.c b/apps/plugins/splitedit.c
index d3145b438a..c2cdc8de6e 100644
--- a/apps/plugins/splitedit.c
+++ b/apps/plugins/splitedit.c
@@ -1055,17 +1055,17 @@ unsigned long splitedit_editor(struct mp3entry * mp3_to_split,
1055#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F) 1055#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
1056#if defined(SPLITEDIT_SPEED150) && defined(SPLITEDIT_SPEED100) && defined(SPLITEDIT_SPEED50) 1056#if defined(SPLITEDIT_SPEED150) && defined(SPLITEDIT_SPEED100) && defined(SPLITEDIT_SPEED50)
1057 case SPLITEDIT_SPEED150: 1057 case SPLITEDIT_SPEED150:
1058 rb->mpeg_set_pitch(1500); 1058 rb->sound_set_pitch(1500);
1059 splitedit_invalidate_osci(); 1059 splitedit_invalidate_osci();
1060 break; 1060 break;
1061 1061
1062 case SPLITEDIT_SPEED100: 1062 case SPLITEDIT_SPEED100:
1063 rb->mpeg_set_pitch(1000); 1063 rb->sound_set_pitch(1000);
1064 splitedit_invalidate_osci(); 1064 splitedit_invalidate_osci();
1065 break; 1065 break;
1066 1066
1067 case SPLITEDIT_SPEED50: 1067 case SPLITEDIT_SPEED50:
1068 rb->mpeg_set_pitch(500); 1068 rb->sound_set_pitch(500);
1069 splitedit_invalidate_osci(); 1069 splitedit_invalidate_osci();
1070 break; 1070 break;
1071#endif 1071#endif
diff --git a/apps/plugins/video.c b/apps/plugins/video.c
index 73968d33b3..0257ad26b7 100644
--- a/apps/plugins/video.c
+++ b/apps/plugins/video.c
@@ -278,7 +278,7 @@ void ChangeVolume(int delta)
278 else if (vol < 0) vol = 0; 278 else if (vol < 0) vol = 0;
279 if (vol != rb->global_settings->volume) 279 if (vol != rb->global_settings->volume)
280 { 280 {
281 rb->mpeg_sound_set(SOUND_VOLUME, vol); 281 rb->sound_set(SOUND_VOLUME, vol);
282 rb->global_settings->volume = vol; 282 rb->global_settings->volume = vol;
283 rb->snprintf(gPrint, sizeof(gPrint), "Vol: %d", vol); 283 rb->snprintf(gPrint, sizeof(gPrint), "Vol: %d", vol);
284 rb->lcd_puts(0, 7, gPrint); 284 rb->lcd_puts(0, 7, gPrint);
diff --git a/apps/plugins/vu_meter.c b/apps/plugins/vu_meter.c
index 22fc5217d2..afeaa83d90 100644
--- a/apps/plugins/vu_meter.c
+++ b/apps/plugins/vu_meter.c
@@ -139,7 +139,7 @@ void change_volume(int delta) {
139 if (vol>100) vol = 100; 139 if (vol>100) vol = 100;
140 else if (vol < 0) vol = 0; 140 else if (vol < 0) vol = 0;
141 if (vol != rb->global_settings->volume) { 141 if (vol != rb->global_settings->volume) {
142 rb->mpeg_sound_set(SOUND_VOLUME, vol); 142 rb->sound_set(SOUND_VOLUME, vol);
143 rb->global_settings->volume = vol; 143 rb->global_settings->volume = vol;
144 rb->snprintf(curr_vol, sizeof(curr_vol), "%d", vol); 144 rb->snprintf(curr_vol, sizeof(curr_vol), "%d", vol);
145 rb->lcd_putsxy(0,0, curr_vol); 145 rb->lcd_putsxy(0,0, curr_vol);
diff --git a/apps/recorder/radio.c b/apps/recorder/radio.c
index 9acca539ee..fae01a7590 100644
--- a/apps/recorder/radio.c
+++ b/apps/recorder/radio.c
@@ -220,8 +220,8 @@ bool radio_screen(void)
220 global_settings.rec_prerecord_time); 220 global_settings.rec_prerecord_time);
221 221
222 222
223 mpeg_set_recording_gain(mpeg_sound_default(SOUND_LEFT_GAIN), 223 mpeg_set_recording_gain(sound_default(SOUND_LEFT_GAIN),
224 mpeg_sound_default(SOUND_RIGHT_GAIN), false); 224 sound_default(SOUND_RIGHT_GAIN), false);
225#endif 225#endif
226 226
227 curr_freq = global_settings.last_frequency * FREQ_STEP + MIN_FREQ; 227 curr_freq = global_settings.last_frequency * FREQ_STEP + MIN_FREQ;
@@ -356,9 +356,9 @@ bool radio_screen(void)
356 case BUTTON_UP: 356 case BUTTON_UP:
357 case BUTTON_UP | BUTTON_REPEAT: 357 case BUTTON_UP | BUTTON_REPEAT:
358 global_settings.volume++; 358 global_settings.volume++;
359 if(global_settings.volume > mpeg_sound_max(SOUND_VOLUME)) 359 if(global_settings.volume > sound_max(SOUND_VOLUME))
360 global_settings.volume = mpeg_sound_max(SOUND_VOLUME); 360 global_settings.volume = sound_max(SOUND_VOLUME);
361 mpeg_sound_set(SOUND_VOLUME, global_settings.volume); 361 sound_set(SOUND_VOLUME, global_settings.volume);
362 update_screen = true; 362 update_screen = true;
363 settings_save(); 363 settings_save();
364 break; 364 break;
@@ -366,9 +366,9 @@ bool radio_screen(void)
366 case BUTTON_DOWN: 366 case BUTTON_DOWN:
367 case BUTTON_DOWN | BUTTON_REPEAT: 367 case BUTTON_DOWN | BUTTON_REPEAT:
368 global_settings.volume--; 368 global_settings.volume--;
369 if(global_settings.volume < mpeg_sound_min(SOUND_VOLUME)) 369 if(global_settings.volume < sound_min(SOUND_VOLUME))
370 global_settings.volume = mpeg_sound_min(SOUND_VOLUME); 370 global_settings.volume = sound_min(SOUND_VOLUME);
371 mpeg_sound_set(SOUND_VOLUME, global_settings.volume); 371 sound_set(SOUND_VOLUME, global_settings.volume);
372 update_screen = true; 372 update_screen = true;
373 settings_save(); 373 settings_save();
374 break; 374 break;
@@ -548,8 +548,8 @@ bool radio_screen(void)
548 if(keep_playing) 548 if(keep_playing)
549 { 549 {
550 /* Enable the Left and right A/D Converter */ 550 /* Enable the Left and right A/D Converter */
551 mpeg_set_recording_gain(mpeg_sound_default(SOUND_LEFT_GAIN), 551 mpeg_set_recording_gain(sound_default(SOUND_LEFT_GAIN),
552 mpeg_sound_default(SOUND_RIGHT_GAIN), false); 552 sound_default(SOUND_RIGHT_GAIN), false);
553 mas_codec_writereg(6, 0x4000); 553 mas_codec_writereg(6, 0x4000);
554 radio_set_status(FMRADIO_POWERED); /* leave it powered */ 554 radio_set_status(FMRADIO_POWERED); /* leave it powered */
555 } 555 }
diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c
index d9b75d05f9..7aa6aba98c 100644
--- a/apps/recorder/recording.c
+++ b/apps/recorder/recording.c
@@ -49,6 +49,7 @@
49#include "errno.h" 49#include "errno.h"
50#include "talk.h" 50#include "talk.h"
51#include "atoi.h" 51#include "atoi.h"
52#include "sound.h"
52 53
53#ifdef HAVE_RECORDING 54#ifdef HAVE_RECORDING
54 55
@@ -124,9 +125,9 @@ char *fmt_gain(int snd, int val, char *str, int len)
124 int tmp, i, d, numdec; 125 int tmp, i, d, numdec;
125 const char *unit; 126 const char *unit;
126 127
127 tmp = mpeg_val2phys(snd, val); 128 tmp = sound_val2phys(snd, val);
128 numdec = mpeg_sound_numdecimals(snd); 129 numdec = sound_numdecimals(snd);
129 unit = mpeg_sound_unit(snd); 130 unit = sound_unit(snd);
130 131
131 i = tmp / (10*numdec); 132 i = tmp / (10*numdec);
132 d = abs(tmp % (10*numdec)); 133 d = abs(tmp % (10*numdec));
@@ -268,7 +269,7 @@ bool recording_screen(void)
268 cursor = 0; 269 cursor = 0;
269 mpeg_init_recording(); 270 mpeg_init_recording();
270 271
271 mpeg_sound_set(SOUND_VOLUME, global_settings.volume); 272 sound_set(SOUND_VOLUME, global_settings.volume);
272 273
273 /* Yes, we use the D/A for monitoring */ 274 /* Yes, we use the D/A for monitoring */
274 peak_meter_playback(true); 275 peak_meter_playback(true);
@@ -395,16 +396,16 @@ bool recording_screen(void)
395 { 396 {
396 global_settings.rec_mic_gain++; 397 global_settings.rec_mic_gain++;
397 if(global_settings.rec_mic_gain > 398 if(global_settings.rec_mic_gain >
398 mpeg_sound_max(SOUND_MIC_GAIN)) 399 sound_max(SOUND_MIC_GAIN))
399 global_settings.rec_mic_gain = 400 global_settings.rec_mic_gain =
400 mpeg_sound_max(SOUND_MIC_GAIN); 401 sound_max(SOUND_MIC_GAIN);
401 } 402 }
402 else 403 else
403 { 404 {
404 gain = MAX(global_settings.rec_left_gain, 405 gain = MAX(global_settings.rec_left_gain,
405 global_settings.rec_right_gain) + 1; 406 global_settings.rec_right_gain) + 1;
406 if(gain > mpeg_sound_max(SOUND_MIC_GAIN)) 407 if(gain > sound_max(SOUND_MIC_GAIN))
407 gain = mpeg_sound_max(SOUND_MIC_GAIN); 408 gain = sound_max(SOUND_MIC_GAIN);
408 global_settings.rec_left_gain = gain; 409 global_settings.rec_left_gain = gain;
409 global_settings.rec_right_gain = gain; 410 global_settings.rec_right_gain = gain;
410 } 411 }
@@ -412,16 +413,16 @@ bool recording_screen(void)
412 case 1: 413 case 1:
413 global_settings.rec_left_gain++; 414 global_settings.rec_left_gain++;
414 if(global_settings.rec_left_gain > 415 if(global_settings.rec_left_gain >
415 mpeg_sound_max(SOUND_LEFT_GAIN)) 416 sound_max(SOUND_LEFT_GAIN))
416 global_settings.rec_left_gain = 417 global_settings.rec_left_gain =
417 mpeg_sound_max(SOUND_LEFT_GAIN); 418 sound_max(SOUND_LEFT_GAIN);
418 break; 419 break;
419 case 2: 420 case 2:
420 global_settings.rec_right_gain++; 421 global_settings.rec_right_gain++;
421 if(global_settings.rec_right_gain > 422 if(global_settings.rec_right_gain >
422 mpeg_sound_max(SOUND_RIGHT_GAIN)) 423 sound_max(SOUND_RIGHT_GAIN))
423 global_settings.rec_right_gain = 424 global_settings.rec_right_gain =
424 mpeg_sound_max(SOUND_RIGHT_GAIN); 425 sound_max(SOUND_RIGHT_GAIN);
425 break; 426 break;
426 } 427 }
427 set_gain(); 428 set_gain();
@@ -437,16 +438,16 @@ bool recording_screen(void)
437 { 438 {
438 global_settings.rec_mic_gain--; 439 global_settings.rec_mic_gain--;
439 if(global_settings.rec_mic_gain < 440 if(global_settings.rec_mic_gain <
440 mpeg_sound_min(SOUND_MIC_GAIN)) 441 sound_min(SOUND_MIC_GAIN))
441 global_settings.rec_mic_gain = 442 global_settings.rec_mic_gain =
442 mpeg_sound_min(SOUND_MIC_GAIN); 443 sound_min(SOUND_MIC_GAIN);
443 } 444 }
444 else 445 else
445 { 446 {
446 gain = MAX(global_settings.rec_left_gain, 447 gain = MAX(global_settings.rec_left_gain,
447 global_settings.rec_right_gain) - 1; 448 global_settings.rec_right_gain) - 1;
448 if(gain < mpeg_sound_min(SOUND_LEFT_GAIN)) 449 if(gain < sound_min(SOUND_LEFT_GAIN))
449 gain = mpeg_sound_min(SOUND_LEFT_GAIN); 450 gain = sound_min(SOUND_LEFT_GAIN);
450 global_settings.rec_left_gain = gain; 451 global_settings.rec_left_gain = gain;
451 global_settings.rec_right_gain = gain; 452 global_settings.rec_right_gain = gain;
452 } 453 }
@@ -454,16 +455,16 @@ bool recording_screen(void)
454 case 1: 455 case 1:
455 global_settings.rec_left_gain--; 456 global_settings.rec_left_gain--;
456 if(global_settings.rec_left_gain < 457 if(global_settings.rec_left_gain <
457 mpeg_sound_min(SOUND_LEFT_GAIN)) 458 sound_min(SOUND_LEFT_GAIN))
458 global_settings.rec_left_gain = 459 global_settings.rec_left_gain =
459 mpeg_sound_min(SOUND_LEFT_GAIN); 460 sound_min(SOUND_LEFT_GAIN);
460 break; 461 break;
461 case 2: 462 case 2:
462 global_settings.rec_right_gain--; 463 global_settings.rec_right_gain--;
463 if(global_settings.rec_right_gain < 464 if(global_settings.rec_right_gain <
464 mpeg_sound_min(SOUND_MIC_GAIN)) 465 sound_min(SOUND_MIC_GAIN))
465 global_settings.rec_right_gain = 466 global_settings.rec_right_gain =
466 mpeg_sound_min(SOUND_MIC_GAIN); 467 sound_min(SOUND_MIC_GAIN);
467 break; 468 break;
468 } 469 }
469 set_gain(); 470 set_gain();
diff --git a/apps/screens.c b/apps/screens.c
index 0efb30a806..f56c28a165 100644
--- a/apps/screens.c
+++ b/apps/screens.c
@@ -44,6 +44,7 @@
44#include "screens.h" 44#include "screens.h"
45#include "debug.h" 45#include "debug.h"
46#include "led.h" 46#include "led.h"
47#include "sound.h"
47#ifdef HAVE_MMC 48#ifdef HAVE_MMC
48#include "ata_mmc.h" 49#include "ata_mmc.h"
49#endif 50#endif
@@ -437,7 +438,7 @@ int pitch_screen(void)
437 pitch++; 438 pitch++;
438 if ( pitch > 2000 ) 439 if ( pitch > 2000 )
439 pitch = 2000; 440 pitch = 2000;
440 mpeg_set_pitch(pitch); 441 sound_set_pitch(pitch);
441 break; 442 break;
442 443
443 case BUTTON_DOWN: 444 case BUTTON_DOWN:
@@ -447,7 +448,7 @@ int pitch_screen(void)
447 pitch--; 448 pitch--;
448 if ( pitch < 500 ) 449 if ( pitch < 500 )
449 pitch = 500; 450 pitch = 500;
450 mpeg_set_pitch(pitch); 451 sound_set_pitch(pitch);
451 break; 452 break;
452 453
453 case BUTTON_ON | BUTTON_PLAY: 454 case BUTTON_ON | BUTTON_PLAY:
@@ -468,28 +469,28 @@ int pitch_screen(void)
468 case BUTTON_ON | BUTTON_RIGHT: 469 case BUTTON_ON | BUTTON_RIGHT:
469 if ( pitch < 2000 ) { 470 if ( pitch < 2000 ) {
470 pitch += 20; 471 pitch += 20;
471 mpeg_set_pitch(pitch); 472 sound_set_pitch(pitch);
472 } 473 }
473 break; 474 break;
474 475
475 case BUTTON_RIGHT | BUTTON_REL: 476 case BUTTON_RIGHT | BUTTON_REL:
476 if ( pitch > 500 ) { 477 if ( pitch > 500 ) {
477 pitch -= 20; 478 pitch -= 20;
478 mpeg_set_pitch(pitch); 479 sound_set_pitch(pitch);
479 } 480 }
480 break; 481 break;
481 482
482 case BUTTON_ON | BUTTON_LEFT: 483 case BUTTON_ON | BUTTON_LEFT:
483 if ( pitch > 500 ) { 484 if ( pitch > 500 ) {
484 pitch -= 20; 485 pitch -= 20;
485 mpeg_set_pitch(pitch); 486 sound_set_pitch(pitch);
486 } 487 }
487 break; 488 break;
488 489
489 case BUTTON_LEFT | BUTTON_REL: 490 case BUTTON_LEFT | BUTTON_REL:
490 if ( pitch < 2000 ) { 491 if ( pitch < 2000 ) {
491 pitch += 20; 492 pitch += 20;
492 mpeg_set_pitch(pitch); 493 sound_set_pitch(pitch);
493 } 494 }
494 break; 495 break;
495 496
diff --git a/apps/settings.c b/apps/settings.c
index 8ff9c7b0b0..df03bdcfcf 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -64,6 +64,7 @@
64#include "keyboard.h" 64#include "keyboard.h"
65#include "version.h" 65#include "version.h"
66#include "rtc.h" 66#include "rtc.h"
67#include "sound.h"
67#if CONFIG_HWCODEC == MAS3507D 68#if CONFIG_HWCODEC == MAS3507D
68void dac_line_in(bool enable); 69void dac_line_in(bool enable);
69#endif 70#endif
@@ -719,21 +720,21 @@ void settings_apply_pm_range(void)
719 720
720void sound_settings_apply(void) 721void sound_settings_apply(void)
721{ 722{
722 mpeg_sound_set(SOUND_BASS, global_settings.bass); 723 sound_set(SOUND_BASS, global_settings.bass);
723 mpeg_sound_set(SOUND_TREBLE, global_settings.treble); 724 sound_set(SOUND_TREBLE, global_settings.treble);
724 mpeg_sound_set(SOUND_BALANCE, global_settings.balance); 725 sound_set(SOUND_BALANCE, global_settings.balance);
725 mpeg_sound_set(SOUND_VOLUME, global_settings.volume); 726 sound_set(SOUND_VOLUME, global_settings.volume);
726 mpeg_sound_set(SOUND_CHANNELS, global_settings.channel_config); 727 sound_set(SOUND_CHANNELS, global_settings.channel_config);
727 mpeg_sound_set(SOUND_STEREO_WIDTH, global_settings.stereo_width); 728 sound_set(SOUND_STEREO_WIDTH, global_settings.stereo_width);
728#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F) 729#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
729 mpeg_sound_set(SOUND_LOUDNESS, global_settings.loudness); 730 sound_set(SOUND_LOUDNESS, global_settings.loudness);
730 mpeg_sound_set(SOUND_AVC, global_settings.avc); 731 sound_set(SOUND_AVC, global_settings.avc);
731 mpeg_sound_set(SOUND_MDB_STRENGTH, global_settings.mdb_strength); 732 sound_set(SOUND_MDB_STRENGTH, global_settings.mdb_strength);
732 mpeg_sound_set(SOUND_MDB_HARMONICS, global_settings.mdb_harmonics); 733 sound_set(SOUND_MDB_HARMONICS, global_settings.mdb_harmonics);
733 mpeg_sound_set(SOUND_MDB_CENTER, global_settings.mdb_center); 734 sound_set(SOUND_MDB_CENTER, global_settings.mdb_center);
734 mpeg_sound_set(SOUND_MDB_SHAPE, global_settings.mdb_shape); 735 sound_set(SOUND_MDB_SHAPE, global_settings.mdb_shape);
735 mpeg_sound_set(SOUND_MDB_ENABLE, global_settings.mdb_enable); 736 sound_set(SOUND_MDB_ENABLE, global_settings.mdb_enable);
736 mpeg_sound_set(SOUND_SUPERBASS, global_settings.superbass); 737 sound_set(SOUND_SUPERBASS, global_settings.superbass);
737#endif 738#endif
738} 739}
739 740
@@ -1261,20 +1262,20 @@ void settings_reset(void) {
1261 default_table(hd_bits, sizeof(hd_bits)/sizeof(hd_bits[0])); 1262 default_table(hd_bits, sizeof(hd_bits)/sizeof(hd_bits[0]));
1262 1263
1263 /* do some special cases not covered by table */ 1264 /* do some special cases not covered by table */
1264 global_settings.volume = mpeg_sound_default(SOUND_VOLUME); 1265 global_settings.volume = sound_default(SOUND_VOLUME);
1265 global_settings.balance = mpeg_sound_default(SOUND_BALANCE); 1266 global_settings.balance = sound_default(SOUND_BALANCE);
1266 global_settings.bass = mpeg_sound_default(SOUND_BASS); 1267 global_settings.bass = sound_default(SOUND_BASS);
1267 global_settings.treble = mpeg_sound_default(SOUND_TREBLE); 1268 global_settings.treble = sound_default(SOUND_TREBLE);
1268 global_settings.loudness = mpeg_sound_default(SOUND_LOUDNESS); 1269 global_settings.loudness = sound_default(SOUND_LOUDNESS);
1269 global_settings.avc = mpeg_sound_default(SOUND_AVC); 1270 global_settings.avc = sound_default(SOUND_AVC);
1270 global_settings.channel_config = mpeg_sound_default(SOUND_CHANNELS); 1271 global_settings.channel_config = sound_default(SOUND_CHANNELS);
1271 global_settings.stereo_width = mpeg_sound_default(SOUND_STEREO_WIDTH); 1272 global_settings.stereo_width = sound_default(SOUND_STEREO_WIDTH);
1272 global_settings.mdb_strength = mpeg_sound_default(SOUND_MDB_STRENGTH); 1273 global_settings.mdb_strength = sound_default(SOUND_MDB_STRENGTH);
1273 global_settings.mdb_harmonics = mpeg_sound_default(SOUND_MDB_HARMONICS); 1274 global_settings.mdb_harmonics = sound_default(SOUND_MDB_HARMONICS);
1274 global_settings.mdb_center = mpeg_sound_default(SOUND_MDB_CENTER); 1275 global_settings.mdb_center = sound_default(SOUND_MDB_CENTER);
1275 global_settings.mdb_shape = mpeg_sound_default(SOUND_MDB_SHAPE); 1276 global_settings.mdb_shape = sound_default(SOUND_MDB_SHAPE);
1276 global_settings.mdb_enable = mpeg_sound_default(SOUND_MDB_ENABLE); 1277 global_settings.mdb_enable = sound_default(SOUND_MDB_ENABLE);
1277 global_settings.superbass = mpeg_sound_default(SOUND_SUPERBASS); 1278 global_settings.superbass = sound_default(SOUND_SUPERBASS);
1278 global_settings.contrast = lcd_default_contrast(); 1279 global_settings.contrast = lcd_default_contrast();
1279 global_settings.wps_file[0] = '\0'; 1280 global_settings.wps_file[0] = '\0';
1280 global_settings.font_file[0] = '\0'; 1281 global_settings.font_file[0] = '\0';
diff --git a/apps/sound_menu.c b/apps/sound_menu.c
index f08ee35525..560163c7c1 100644
--- a/apps/sound_menu.c
+++ b/apps/sound_menu.c
@@ -34,6 +34,7 @@
34#include "sprintf.h" 34#include "sprintf.h"
35#include "talk.h" 35#include "talk.h"
36#include "misc.h" 36#include "misc.h"
37#include "sound.h"
37 38
38static const char* const fmt[] = 39static const char* const fmt[] =
39{ 40{
@@ -59,11 +60,11 @@ bool set_sound(const char* string,
59 int steps; 60 int steps;
60 int button; 61 int button;
61 62
62 unit = mpeg_sound_unit(setting); 63 unit = sound_unit(setting);
63 numdec = mpeg_sound_numdecimals(setting); 64 numdec = sound_numdecimals(setting);
64 steps = mpeg_sound_steps(setting); 65 steps = sound_steps(setting);
65 min = mpeg_sound_min(setting); 66 min = sound_min(setting);
66 max = mpeg_sound_max(setting); 67 max = sound_max(setting);
67 if (*unit == 'd') /* crude reconstruction */ 68 if (*unit == 'd') /* crude reconstruction */
68 talkunit = UNIT_DB; 69 talkunit = UNIT_DB;
69 else if (*unit == '%') 70 else if (*unit == '%')
@@ -82,7 +83,7 @@ bool set_sound(const char* string,
82 83
83 while (!done) { 84 while (!done) {
84 if (changed) { 85 if (changed) {
85 val = mpeg_val2phys(setting, *variable); 86 val = sound_val2phys(setting, *variable);
86 if(numdec) 87 if(numdec)
87 { 88 {
88 integer = val / (10 * numdec); 89 integer = val / (10 * numdec);
@@ -136,7 +137,7 @@ bool set_sound(const char* string,
136 break; 137 break;
137 } 138 }
138 if (changed) 139 if (changed)
139 mpeg_sound_set(setting, *variable); 140 sound_set(setting, *variable);
140 } 141 }
141 lcd_stop_scroll(); 142 lcd_stop_scroll();
142 return false; 143 return false;
@@ -196,7 +197,7 @@ static bool mdb_shape(void)
196 197
197static void set_mdb_enable(bool value) 198static void set_mdb_enable(bool value)
198{ 199{
199 mpeg_sound_set(SOUND_MDB_ENABLE, (int)value); 200 sound_set(SOUND_MDB_ENABLE, (int)value);
200} 201}
201 202
202static bool mdb_enable(void) 203static bool mdb_enable(void)
@@ -210,7 +211,7 @@ static bool mdb_enable(void)
210 211
211static void set_superbass(bool value) 212static void set_superbass(bool value)
212{ 213{
213 mpeg_sound_set(SOUND_SUPERBASS, (int)value); 214 sound_set(SOUND_SUPERBASS, (int)value);
214} 215}
215 216
216static bool superbass(void) 217static bool superbass(void)
@@ -224,7 +225,7 @@ static bool superbass(void)
224 225
225static void set_avc(int val) 226static void set_avc(int val)
226{ 227{
227 mpeg_sound_set(SOUND_AVC, val); 228 sound_set(SOUND_AVC, val);
228} 229}
229 230
230static bool avc(void) 231static bool avc(void)
@@ -379,7 +380,7 @@ static bool reconstartup(void)
379 380
380static void set_chanconf(int val) 381static void set_chanconf(int val)
381{ 382{
382 mpeg_sound_set(SOUND_CHANNELS, val); 383 sound_set(SOUND_CHANNELS, val);
383} 384}
384 385
385static bool chanconf(void) 386static bool chanconf(void)
diff --git a/apps/status.c b/apps/status.c
index 562cd50964..d4736f3773 100644
--- a/apps/status.c
+++ b/apps/status.c
@@ -36,6 +36,7 @@
36#endif 36#endif
37#include "powermgmt.h" 37#include "powermgmt.h"
38#include "led.h" 38#include "led.h"
39#include "sound.h"
39 40
40static enum playmode ff_mode; 41static enum playmode ff_mode;
41 42
@@ -146,7 +147,7 @@ void status_draw(bool force_redraw)
146 (void)force_redraw; /* players always "redraw" */ 147 (void)force_redraw; /* players always "redraw" */
147#endif 148#endif
148 149
149 info.volume = mpeg_val2phys(SOUND_VOLUME, global_settings.volume); 150 info.volume = sound_val2phys(SOUND_VOLUME, global_settings.volume);
150 info.inserted = charger_inserted(); 151 info.inserted = charger_inserted();
151 info.battlevel = battery_level(); 152 info.battlevel = battery_level();
152 info.battery_safe = battery_level_safe(); 153 info.battery_safe = battery_level_safe();
diff --git a/apps/wps.c b/apps/wps.c
index 91969df00e..d5f921c350 100644
--- a/apps/wps.c
+++ b/apps/wps.c
@@ -49,6 +49,7 @@
49#include "lang.h" 49#include "lang.h"
50#include "bookmark.h" 50#include "bookmark.h"
51#include "misc.h" 51#include "misc.h"
52#include "sound.h"
52 53
53#define FF_REWIND_MAX_PERCENT 3 /* cap ff/rewind step size at max % of file */ 54#define FF_REWIND_MAX_PERCENT 3 /* cap ff/rewind step size at max % of file */
54 /* 3% of 30min file == 54s step size */ 55 /* 3% of 30min file == 54s step size */
@@ -172,17 +173,17 @@ static char current_track_path[MAX_PATH+1];
172*/ 173*/
173static bool setvol(void) 174static bool setvol(void)
174{ 175{
175 if (global_settings.volume < mpeg_sound_min(SOUND_VOLUME)) 176 if (global_settings.volume < sound_min(SOUND_VOLUME))
176 global_settings.volume = mpeg_sound_min(SOUND_VOLUME); 177 global_settings.volume = sound_min(SOUND_VOLUME);
177 if (global_settings.volume > mpeg_sound_max(SOUND_VOLUME)) 178 if (global_settings.volume > sound_max(SOUND_VOLUME))
178 global_settings.volume = mpeg_sound_max(SOUND_VOLUME); 179 global_settings.volume = sound_max(SOUND_VOLUME);
179 mpeg_sound_set(SOUND_VOLUME, global_settings.volume); 180 sound_set(SOUND_VOLUME, global_settings.volume);
180 status_draw(false); 181 status_draw(false);
181 wps_refresh(id3, nid3, 0, WPS_REFRESH_NON_STATIC); 182 wps_refresh(id3, nid3, 0, WPS_REFRESH_NON_STATIC);
182 settings_save(); 183 settings_save();
183#ifdef HAVE_LCD_CHARCELLS 184#ifdef HAVE_LCD_CHARCELLS
184 splash(0, false, "Vol: %d %% ", 185 splash(0, false, "Vol: %d %% ",
185 mpeg_val2phys(SOUND_VOLUME, global_settings.volume)); 186 sound_val2phys(SOUND_VOLUME, global_settings.volume));
186 return true; 187 return true;
187#endif 188#endif
188 return false; 189 return false;
@@ -388,7 +389,7 @@ static void fade(bool fade_in)
388 int current_volume = 20; 389 int current_volume = 20;
389 390
390 /* zero out the sound */ 391 /* zero out the sound */
391 mpeg_sound_set(SOUND_VOLUME, current_volume); 392 sound_set(SOUND_VOLUME, current_volume);
392 393
393 sleep(HZ/10); /* let mpeg thread run */ 394 sleep(HZ/10); /* let mpeg thread run */
394 mpeg_resume(); 395 mpeg_resume();
@@ -396,9 +397,9 @@ static void fade(bool fade_in)
396 while (current_volume < global_settings.volume) { 397 while (current_volume < global_settings.volume) {
397 current_volume += 2; 398 current_volume += 2;
398 sleep(1); 399 sleep(1);
399 mpeg_sound_set(SOUND_VOLUME, current_volume); 400 sound_set(SOUND_VOLUME, current_volume);
400 } 401 }
401 mpeg_sound_set(SOUND_VOLUME, global_settings.volume); 402 sound_set(SOUND_VOLUME, global_settings.volume);
402 } 403 }
403 else { 404 else {
404 /* fade out */ 405 /* fade out */
@@ -407,13 +408,13 @@ static void fade(bool fade_in)
407 while (current_volume > 20) { 408 while (current_volume > 20) {
408 current_volume -= 2; 409 current_volume -= 2;
409 sleep(1); 410 sleep(1);
410 mpeg_sound_set(SOUND_VOLUME, current_volume); 411 sound_set(SOUND_VOLUME, current_volume);
411 } 412 }
412 mpeg_pause(); 413 mpeg_pause();
413 sleep(HZ/5); /* let mpeg thread run */ 414 sleep(HZ/5); /* let mpeg thread run */
414 415
415 /* reset volume to what it was before the fade */ 416 /* reset volume to what it was before the fade */
416 mpeg_sound_set(SOUND_VOLUME, global_settings.volume); 417 sound_set(SOUND_VOLUME, global_settings.volume);
417 } 418 }
418} 419}
419 420
diff --git a/firmware/SOURCES b/firmware/SOURCES
index 870026f835..8279f812d1 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -111,7 +111,10 @@ bitswap.S
111descramble.S 111descramble.S
112#endif 112#endif
113drivers/lcd.S 113drivers/lcd.S
114#if defined(IRIVER_H100) && !defined(SIMULATOR) 114#ifdef IRIVER_H100
115#ifndef SIMULATOR
115drivers/uda1380.c 116drivers/uda1380.c
116pcm_playback.c 117pcm_playback.c
117#endif 118#endif
119#endif
120sound.c
diff --git a/firmware/export/mp3_playback.h b/firmware/export/mp3_playback.h
index aced6ddc94..4da1ffce6d 100644
--- a/firmware/export/mp3_playback.h
+++ b/firmware/export/mp3_playback.h
@@ -30,19 +30,6 @@ void mp3_init(int volume, int bass, int treble, int balance, int loudness,
30 int mdb_strength, int mdb_harmonics, 30 int mdb_strength, int mdb_harmonics,
31 int mdb_center, int mdb_shape, bool mdb_enable, 31 int mdb_center, int mdb_shape, bool mdb_enable,
32 bool superbass); 32 bool superbass);
33void mpeg_sound_set(int setting, int value);
34int mpeg_sound_min(int setting);
35int mpeg_sound_max(int setting);
36int mpeg_sound_default(int setting);
37void mpeg_sound_channel_config(int configuration);
38int mpeg_val2phys(int setting, int value);
39const char *mpeg_sound_unit(int setting);
40int mpeg_sound_numdecimals(int setting);
41int mpeg_sound_steps(int setting);
42#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F) || defined(SIMULATOR)
43void mpeg_set_pitch(int percent);
44#endif
45
46 33
47/* exported just for mpeg.c, to keep the recording there */ 34/* exported just for mpeg.c, to keep the recording there */
48#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F) 35#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
@@ -62,31 +49,4 @@ bool mp3_is_playing(void);
62unsigned char* mp3_get_pos(void); 49unsigned char* mp3_get_pos(void);
63void mp3_shutdown(void); 50void mp3_shutdown(void);
64 51
65
66#define SOUND_VOLUME 0
67#define SOUND_BASS 1
68#define SOUND_TREBLE 2
69#define SOUND_BALANCE 3
70#define SOUND_LOUDNESS 4
71#define SOUND_AVC 5
72#define SOUND_CHANNELS 6
73#define SOUND_STEREO_WIDTH 7
74#define SOUND_LEFT_GAIN 8
75#define SOUND_RIGHT_GAIN 9
76#define SOUND_MIC_GAIN 10
77#define SOUND_MDB_STRENGTH 11
78#define SOUND_MDB_HARMONICS 12
79#define SOUND_MDB_CENTER 13
80#define SOUND_MDB_SHAPE 14
81#define SOUND_MDB_ENABLE 15
82#define SOUND_SUPERBASS 16
83#define SOUND_NUMSETTINGS 17
84
85#define MPEG_SOUND_STEREO 0
86#define MPEG_SOUND_MONO 1
87#define MPEG_SOUND_CUSTOM 2
88#define MPEG_SOUND_MONO_LEFT 3
89#define MPEG_SOUND_MONO_RIGHT 4
90#define MPEG_SOUND_KARAOKE 5
91
92#endif /* #ifndef _MP3_PLAYBACK_H_ */ 52#endif /* #ifndef _MP3_PLAYBACK_H_ */
diff --git a/firmware/export/sound.h b/firmware/export/sound.h
new file mode 100644
index 0000000000..2fa00d88a9
--- /dev/null
+++ b/firmware/export/sound.h
@@ -0,0 +1,61 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 by Linus Nielsen Feltzing
11 *
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.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#ifndef SOUND_H
20#define SOUND_H
21
22#define SOUND_VOLUME 0
23#define SOUND_BASS 1
24#define SOUND_TREBLE 2
25#define SOUND_BALANCE 3
26#define SOUND_LOUDNESS 4
27#define SOUND_AVC 5
28#define SOUND_CHANNELS 6
29#define SOUND_STEREO_WIDTH 7
30#define SOUND_LEFT_GAIN 8
31#define SOUND_RIGHT_GAIN 9
32#define SOUND_MIC_GAIN 10
33#define SOUND_MDB_STRENGTH 11
34#define SOUND_MDB_HARMONICS 12
35#define SOUND_MDB_CENTER 13
36#define SOUND_MDB_SHAPE 14
37#define SOUND_MDB_ENABLE 15
38#define SOUND_SUPERBASS 16
39#define SOUND_NUMSETTINGS 17
40
41#define SOUND_CHAN_STEREO 0
42#define SOUND_CHAN_MONO 1
43#define SOUND_CHAN_CUSTOM 2
44#define SOUND_CHAN_MONO_LEFT 3
45#define SOUND_CHAN_MONO_RIGHT 4
46#define SOUND_CHAN_KARAOKE 5
47
48void sound_set(int setting, int value);
49int sound_min(int setting);
50int sound_max(int setting);
51int sound_default(int setting);
52void sound_channel_config(int configuration);
53int sound_val2phys(int setting, int value);
54const char *sound_unit(int setting);
55int sound_numdecimals(int setting);
56int sound_steps(int setting);
57#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F) || defined(SIMULATOR)
58void sound_set_pitch(int percent);
59#endif
60
61#endif
diff --git a/firmware/mp3_playback.c b/firmware/mp3_playback.c
index 16fe544c7a..14e0aa796e 100644
--- a/firmware/mp3_playback.c
+++ b/firmware/mp3_playback.c
@@ -26,6 +26,7 @@
26#include <kernel.h> 26#include <kernel.h>
27#include "mpeg.h" /* ToDo: remove crosslinks */ 27#include "mpeg.h" /* ToDo: remove crosslinks */
28#include "mp3_playback.h" 28#include "mp3_playback.h"
29#include "sound.h"
29#ifndef SIMULATOR 30#ifndef SIMULATOR
30#include "i2c.h" 31#include "i2c.h"
31#include "mas.h" 32#include "mas.h"
@@ -63,183 +64,12 @@ static long cumulative_ticks;
63static void (*callback_for_more)(unsigned char**, int*); 64static void (*callback_for_more)(unsigned char**, int*);
64#endif /* #ifndef SIMULATOR */ 65#endif /* #ifndef SIMULATOR */
65 66
66static const char* const units[] =
67{
68 "%", /* Volume */
69 "dB", /* Bass */
70 "dB", /* Treble */
71 "%", /* Balance */
72 "dB", /* Loudness */
73 "", /* AVC */
74 "", /* Channels */
75 "%", /* Stereo width */
76 "dB", /* Left gain */
77 "dB", /* Right gain */
78 "dB", /* Mic gain */
79 "dB", /* MDB Strength */
80 "%", /* MDB Harmonics */
81 "Hz", /* MDB Center */
82 "Hz", /* MDB Shape */
83 "", /* MDB Enable */
84 "", /* Super bass */
85};
86
87static const int numdecimals[] =
88{
89 0, /* Volume */
90 0, /* Bass */
91 0, /* Treble */
92 0, /* Balance */
93 0, /* Loudness */
94 0, /* AVC */
95 0, /* Channels */
96 0, /* Stereo width */
97 1, /* Left gain */
98 1, /* Right gain */
99 1, /* Mic gain */
100 0, /* MDB Strength */
101 0, /* MDB Harmonics */
102 0, /* MDB Center */
103 0, /* MDB Shape */
104 0, /* MDB Enable */
105 0, /* Super bass */
106};
107
108static const int steps[] =
109{
110 1, /* Volume */
111 1, /* Bass */
112 1, /* Treble */
113 1, /* Balance */
114 1, /* Loudness */
115 1, /* AVC */
116 1, /* Channels */
117 1, /* Stereo width */
118 1, /* Left gain */
119 1, /* Right gain */
120 1, /* Mic gain */
121 1, /* MDB Strength */
122 1, /* MDB Harmonics */
123 10, /* MDB Center */
124 10, /* MDB Shape */
125 1, /* MDB Enable */
126 1, /* Super bass */
127};
128
129static const int minval[] =
130{
131 0, /* Volume */
132#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
133 -12, /* Bass */
134 -12, /* Treble */
135#else
136 -15, /* Bass */
137 -15, /* Treble */
138#endif
139 -100, /* Balance */
140 0, /* Loudness */
141 -1, /* AVC */
142 0, /* Channels */
143 0, /* Stereo width */
144 0, /* Left gain */
145 0, /* Right gain */
146 0, /* Mic gain */
147 0, /* MDB Strength */
148 0, /* MDB Harmonics */
149 20, /* MDB Center */
150 50, /* MDB Shape */
151 0, /* MDB Enable */
152 0, /* Super bass */
153};
154
155static const int maxval[] =
156{
157 100, /* Volume */
158#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
159 12, /* Bass */
160 12, /* Treble */
161#else
162 15, /* Bass */
163 15, /* Treble */
164#endif
165 100, /* Balance */
166 17, /* Loudness */
167 4, /* AVC */
168 5, /* Channels */
169 255, /* Stereo width */
170 15, /* Left gain */
171 15, /* Right gain */
172 15, /* Mic gain */
173 127, /* MDB Strength */
174 100, /* MDB Harmonics */
175 300, /* MDB Center */
176 300, /* MDB Shape */
177 1, /* MDB Enable */
178 1, /* Super bass */
179};
180
181static const int defaultval[] =
182{
183 70, /* Volume */
184#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
185 6, /* Bass */
186 6, /* Treble */
187#else
188 7, /* Bass */
189 7, /* Treble */
190#endif
191 0, /* Balance */
192 0, /* Loudness */
193 0, /* AVC */
194 0, /* Channels */
195 100, /* Stereo width */
196 8, /* Left gain */
197 8, /* Right gain */
198 2, /* Mic gain */
199 50, /* MDB Strength */
200 48, /* MDB Harmonics */
201 60, /* MDB Center */
202 90, /* MDB Shape */
203 0, /* MDB Enable */
204 0, /* Super bass */
205};
206
207const char *mpeg_sound_unit(int setting)
208{
209 return units[setting];
210}
211
212int mpeg_sound_numdecimals(int setting)
213{
214 return numdecimals[setting];
215}
216
217int mpeg_sound_steps(int setting)
218{
219 return steps[setting];
220}
221
222int mpeg_sound_min(int setting)
223{
224 return minval[setting];
225}
226
227int mpeg_sound_max(int setting)
228{
229 return maxval[setting];
230}
231
232int mpeg_sound_default(int setting)
233{
234 return defaultval[setting];
235}
236
237/* list of tracks in memory */ 67/* list of tracks in memory */
238#define MAX_ID3_TAGS (1<<4) /* Must be power of 2 */ 68#define MAX_ID3_TAGS (1<<4) /* Must be power of 2 */
239#define MAX_ID3_TAGS_MASK (MAX_ID3_TAGS - 1) 69#define MAX_ID3_TAGS_MASK (MAX_ID3_TAGS - 1)
240 70
241#ifndef SIMULATOR 71#ifndef SIMULATOR
242static bool mpeg_is_initialized = false; 72bool audio_is_initialized = false;
243#endif 73#endif
244 74
245#if CONFIG_HWCODEC != MASNONE 75#if CONFIG_HWCODEC != MASNONE
@@ -249,99 +79,6 @@ static bool mpeg_is_initialized = false;
249 79
250unsigned long mas_version_code; 80unsigned long mas_version_code;
251 81
252#if CONFIG_HWCODEC == MAS3507D
253
254static const unsigned int bass_table[] =
255{
256 0x9e400, /* -15dB */
257 0xa2800, /* -14dB */
258 0xa7400, /* -13dB */
259 0xac400, /* -12dB */
260 0xb1800, /* -11dB */
261 0xb7400, /* -10dB */
262 0xbd400, /* -9dB */
263 0xc3c00, /* -8dB */
264 0xca400, /* -7dB */
265 0xd1800, /* -6dB */
266 0xd8c00, /* -5dB */
267 0xe0400, /* -4dB */
268 0xe8000, /* -3dB */
269 0xefc00, /* -2dB */
270 0xf7c00, /* -1dB */
271 0,
272 0x800, /* 1dB */
273 0x10000, /* 2dB */
274 0x17c00, /* 3dB */
275 0x1f800, /* 4dB */
276 0x27000, /* 5dB */
277 0x2e400, /* 6dB */
278 0x35800, /* 7dB */
279 0x3c000, /* 8dB */
280 0x42800, /* 9dB */
281 0x48800, /* 10dB */
282 0x4e400, /* 11dB */
283 0x53800, /* 12dB */
284 0x58800, /* 13dB */
285 0x5d400, /* 14dB */
286 0x61800 /* 15dB */
287};
288
289static const unsigned int treble_table[] =
290{
291 0xb2c00, /* -15dB */
292 0xbb400, /* -14dB */
293 0xc1800, /* -13dB */
294 0xc6c00, /* -12dB */
295 0xcbc00, /* -11dB */
296 0xd0400, /* -10dB */
297 0xd5000, /* -9dB */
298 0xd9800, /* -8dB */
299 0xde000, /* -7dB */
300 0xe2800, /* -6dB */
301 0xe7e00, /* -5dB */
302 0xec000, /* -4dB */
303 0xf0c00, /* -3dB */
304 0xf5c00, /* -2dB */
305 0xfac00, /* -1dB */
306 0,
307 0x5400, /* 1dB */
308 0xac00, /* 2dB */
309 0x10400, /* 3dB */
310 0x16000, /* 4dB */
311 0x1c000, /* 5dB */
312 0x22400, /* 6dB */
313 0x28400, /* 7dB */
314 0x2ec00, /* 8dB */
315 0x35400, /* 9dB */
316 0x3c000, /* 10dB */
317 0x42c00, /* 11dB */
318 0x49c00, /* 12dB */
319 0x51800, /* 13dB */
320 0x58400, /* 14dB */
321 0x5f800 /* 15dB */
322};
323
324static const unsigned int prescale_table[] =
325{
326 0x80000, /* 0db */
327 0x8e000, /* 1dB */
328 0x9a400, /* 2dB */
329 0xa5800, /* 3dB */
330 0xaf400, /* 4dB */
331 0xb8000, /* 5dB */
332 0xbfc00, /* 6dB */
333 0xc6c00, /* 7dB */
334 0xcd000, /* 8dB */
335 0xd25c0, /* 9dB */
336 0xd7800, /* 10dB */
337 0xdc000, /* 11dB */
338 0xdfc00, /* 12dB */
339 0xe3400, /* 13dB */
340 0xe6800, /* 14dB */
341 0xe9400 /* 15dB */
342};
343#endif
344
345bool dma_on; /* The DMA is active */ 82bool dma_on; /* The DMA is active */
346 83
347#if CONFIG_HWCODEC == MAS3507D 84#if CONFIG_HWCODEC == MAS3507D
@@ -589,329 +326,6 @@ static void init_playback(void)
589} 326}
590#endif /* #if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F) */ 327#endif /* #if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F) */
591 328
592#ifndef SIMULATOR
593#if CONFIG_HWCODEC == MAS3507D
594/* all values in tenth of dB */
595int current_volume = 0; /* -780..+180 */
596int current_balance = 0; /* -960..+960 */
597int current_treble = 0; /* -150..+150 */
598int current_bass = 0; /* -150..+150 */
599
600/* convert tenth of dB volume to register value */
601static int tenthdb2reg(int db) {
602 if (db < -540)
603 return (db + 780) / 30;
604 else
605 return (db + 660) / 15;
606}
607
608void set_prescaled_volume(void)
609{
610 int prescale;
611 int l, r;
612
613 prescale = MAX(current_bass, current_treble);
614 if (prescale < 0)
615 prescale = 0; /* no need to prescale if we don't boost
616 bass or treble */
617
618 mas_writereg(MAS_REG_KPRESCALE, prescale_table[prescale/10]);
619
620 /* gain up the analog volume to compensate the prescale reduction gain,
621 * but limit to +18 dB (the maximum the DAC can do */
622 if (current_volume + prescale > 180)
623 prescale = 180 - current_volume;
624 l = r = current_volume + prescale;
625
626 if (current_balance > 0)
627 {
628 l -= current_balance;
629 if (l < -780)
630 l = -780;
631 }
632 if (current_balance < 0)
633 {
634 r += current_balance;
635 if (r < -780)
636 r = -780;
637 }
638
639 dac_volume(tenthdb2reg(l), tenthdb2reg(r), false);
640}
641#endif /* MAS3507D */
642#endif /* !SIMULATOR */
643
644int channel_configuration = MPEG_SOUND_STEREO;
645int stereo_width = 100;
646
647#ifndef SIMULATOR
648static void set_channel_config(void)
649{
650 /* default values: stereo */
651 unsigned long val_ll = 0x80000;
652 unsigned long val_lr = 0;
653 unsigned long val_rl = 0;
654 unsigned long val_rr = 0x80000;
655
656 switch(channel_configuration)
657 {
658 /* case MPEG_SOUND_STEREO unnecessary */
659
660 case MPEG_SOUND_MONO:
661 val_ll = 0xc0000;
662 val_lr = 0xc0000;
663 val_rl = 0xc0000;
664 val_rr = 0xc0000;
665 break;
666
667 case MPEG_SOUND_CUSTOM:
668 {
669 /* fixed point variables (matching MAS internal format)
670 integer part: upper 13 bits (inlcuding sign)
671 fractional part: lower 19 bits */
672 long fp_width, fp_straight, fp_cross;
673
674 fp_width = (stereo_width << 19) / 100;
675 if (stereo_width <= 100)
676 {
677 fp_straight = - ((1<<19) + fp_width) / 2;
678 fp_cross = fp_straight + fp_width;
679 }
680 else
681 {
682 fp_straight = - (1<<19);
683 fp_cross = ((2 * fp_width / (((1<<19) + fp_width) >> 10))
684 << 9) - (1<<19);
685 }
686 val_ll = val_rr = fp_straight & 0xFFFFF;
687 val_lr = val_rl = fp_cross & 0xFFFFF;
688 }
689 break;
690
691 case MPEG_SOUND_MONO_LEFT:
692 val_ll = 0x80000;
693 val_lr = 0x80000;
694 val_rl = 0;
695 val_rr = 0;
696 break;
697
698 case MPEG_SOUND_MONO_RIGHT:
699 val_ll = 0;
700 val_lr = 0;
701 val_rl = 0x80000;
702 val_rr = 0x80000;
703 break;
704
705 case MPEG_SOUND_KARAOKE:
706 val_ll = 0x80001;
707 val_lr = 0x7ffff;
708 val_rl = 0x7ffff;
709 val_rr = 0x80001;
710 break;
711 }
712
713#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
714 mas_writemem(MAS_BANK_D0, MAS_D0_OUT_LL, &val_ll, 1); /* LL */
715 mas_writemem(MAS_BANK_D0, MAS_D0_OUT_LR, &val_lr, 1); /* LR */
716 mas_writemem(MAS_BANK_D0, MAS_D0_OUT_RL, &val_rl, 1); /* RL */
717 mas_writemem(MAS_BANK_D0, MAS_D0_OUT_RR, &val_rr, 1); /* RR */
718#elif CONFIG_HWCODEC == MAS3507D
719 mas_writemem(MAS_BANK_D1, 0x7f8, &val_ll, 1); /* LL */
720 mas_writemem(MAS_BANK_D1, 0x7f9, &val_lr, 1); /* LR */
721 mas_writemem(MAS_BANK_D1, 0x7fa, &val_rl, 1); /* RL */
722 mas_writemem(MAS_BANK_D1, 0x7fb, &val_rr, 1); /* RR */
723#endif
724}
725#endif /* !SIMULATOR */
726
727#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
728unsigned long mdb_shape_shadow = 0;
729unsigned long loudness_shadow = 0;
730#endif
731
732void mpeg_sound_set(int setting, int value)
733{
734#ifdef SIMULATOR
735 setting = value;
736#else
737#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
738 int tmp;
739#endif
740
741 if(!mpeg_is_initialized)
742 return;
743
744 switch(setting)
745 {
746 case SOUND_VOLUME:
747#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
748 tmp = 0x7f00 * value / 100;
749 mas_codec_writereg(0x10, tmp & 0xff00);
750#else
751 current_volume = -780 + (value * 960 / 100); /* tenth of dB */
752 set_prescaled_volume();
753#endif
754 break;
755
756 case SOUND_BALANCE:
757#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
758 tmp = ((value * 127 / 100) & 0xff) << 8;
759 mas_codec_writereg(0x11, tmp & 0xff00);
760#else
761 current_balance = value * 960 / 100; /* tenth of dB */
762 set_prescaled_volume();
763#endif
764 break;
765
766 case SOUND_BASS:
767#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
768 tmp = ((value * 8) & 0xff) << 8;
769 mas_codec_writereg(0x14, tmp & 0xff00);
770#else
771 mas_writereg(MAS_REG_KBASS, bass_table[value+15]);
772 current_bass = value * 10;
773 set_prescaled_volume();
774#endif
775 break;
776
777 case SOUND_TREBLE:
778#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
779 tmp = ((value * 8) & 0xff) << 8;
780 mas_codec_writereg(0x15, tmp & 0xff00);
781#else
782 mas_writereg(MAS_REG_KTREBLE, treble_table[value+15]);
783 current_treble = value * 10;
784 set_prescaled_volume();
785#endif
786 break;
787
788#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
789 case SOUND_LOUDNESS:
790 loudness_shadow = (loudness_shadow & 0x04) |
791 (MAX(MIN(value * 4, 0x44), 0) << 8);
792 mas_codec_writereg(MAS_REG_KLOUDNESS, loudness_shadow);
793 break;
794
795 case SOUND_AVC:
796 switch (value) {
797 case 1: /* 20ms */
798 tmp = (0x1 << 8) | (0x8 << 12);
799 break;
800 case 2: /* 2s */
801 tmp = (0x2 << 8) | (0x8 << 12);
802 break;
803 case 3: /* 4s */
804 tmp = (0x4 << 8) | (0x8 << 12);
805 break;
806 case 4: /* 8s */
807 tmp = (0x8 << 8) | (0x8 << 12);
808 break;
809 case -1: /* turn off and then turn on again to decay quickly */
810 tmp = mas_codec_readreg(MAS_REG_KAVC);
811 mas_codec_writereg(MAS_REG_KAVC, 0);
812 break;
813 default: /* off */
814 tmp = 0;
815 break;
816 }
817 mas_codec_writereg(MAS_REG_KAVC, tmp);
818 break;
819
820 case SOUND_MDB_STRENGTH:
821 mas_codec_writereg(MAS_REG_KMDB_STR, (value & 0x7f) << 8);
822 break;
823
824 case SOUND_MDB_HARMONICS:
825 tmp = value * 127 / 100;
826 mas_codec_writereg(MAS_REG_KMDB_HAR, (tmp & 0x7f) << 8);
827 break;
828
829 case SOUND_MDB_CENTER:
830 mas_codec_writereg(MAS_REG_KMDB_FC, (value/10) << 8);
831 break;
832
833 case SOUND_MDB_SHAPE:
834 mdb_shape_shadow = (mdb_shape_shadow & 0x02) | ((value/10) << 8);
835 mas_codec_writereg(MAS_REG_KMDB_SWITCH, mdb_shape_shadow);
836 break;
837
838 case SOUND_MDB_ENABLE:
839 mdb_shape_shadow = (mdb_shape_shadow & ~0x02) | (value?2:0);
840 mas_codec_writereg(MAS_REG_KMDB_SWITCH, mdb_shape_shadow);
841 break;
842
843 case SOUND_SUPERBASS:
844 loudness_shadow = (loudness_shadow & ~0x04) |
845 (value?4:0);
846 mas_codec_writereg(MAS_REG_KLOUDNESS, loudness_shadow);
847 break;
848#endif
849 case SOUND_CHANNELS:
850 channel_configuration = value;
851 set_channel_config();
852 break;
853
854 case SOUND_STEREO_WIDTH:
855 stereo_width = value;
856 if (channel_configuration == MPEG_SOUND_CUSTOM)
857 set_channel_config();
858 break;
859 }
860#endif /* SIMULATOR */
861}
862
863int mpeg_val2phys(int setting, int value)
864{
865#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
866 int result = 0;
867
868 switch(setting)
869 {
870 case SOUND_LEFT_GAIN:
871 case SOUND_RIGHT_GAIN:
872 result = (value - 2) * 15;
873 break;
874
875 case SOUND_MIC_GAIN:
876 result = value * 15 + 210;
877 break;
878
879 default:
880 result = value;
881 break;
882 }
883 return result;
884#else
885 (void)setting;
886 return value;
887#endif
888}
889
890#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
891/* This function works by telling the decoder that we have another
892 crystal frequency than we actually have. It will adjust its internal
893 parameters and the result is that the audio is played at another pitch.
894
895 The pitch value is in tenths of percent.
896*/
897void mpeg_set_pitch(int pitch)
898{
899 unsigned long val;
900
901 /* invert pitch value */
902 pitch = 1000000/pitch;
903
904 /* Calculate the new (bogus) frequency */
905 val = 18432*pitch/1000;
906
907 mas_writemem(MAS_BANK_D0, MAS_D0_OFREQ_CONTROL, &val, 1);
908
909 /* We must tell the MAS that the frequency has changed.
910 This will unfortunately cause a short silence. */
911 mas_writemem(MAS_BANK_D0, MAS_D0_IO_CONTROL_MAIN, &shadow_io_control_main, 1);
912}
913#endif
914
915void mp3_init(int volume, int bass, int treble, int balance, int loudness, 329void mp3_init(int volume, int bass, int treble, int balance, int loudness,
916 int avc, int channel_config, int stereo_width, 330 int avc, int channel_config, int stereo_width,
917 int mdb_strength, int mdb_harmonics, 331 int mdb_strength, int mdb_harmonics,
@@ -1035,25 +449,25 @@ void mp3_init(int volume, int bass, int treble, int balance, int loudness,
1035 PACR1 = (PACR1 & 0x3fff) | 0x4000; /* PA15 is IRQ3 */ 449 PACR1 = (PACR1 & 0x3fff) | 0x4000; /* PA15 is IRQ3 */
1036#endif 450#endif
1037 451
1038 /* Must be done before calling mpeg_sound_set() */ 452 /* Must be done before calling sound_set() */
1039 mpeg_is_initialized = true; 453 audio_is_initialized = true;
1040 454
1041 mpeg_sound_set(SOUND_BASS, bass); 455 sound_set(SOUND_BASS, bass);
1042 mpeg_sound_set(SOUND_TREBLE, treble); 456 sound_set(SOUND_TREBLE, treble);
1043 mpeg_sound_set(SOUND_BALANCE, balance); 457 sound_set(SOUND_BALANCE, balance);
1044 mpeg_sound_set(SOUND_VOLUME, volume); 458 sound_set(SOUND_VOLUME, volume);
1045 mpeg_sound_set(SOUND_CHANNELS, channel_config); 459 sound_set(SOUND_CHANNELS, channel_config);
1046 mpeg_sound_set(SOUND_STEREO_WIDTH, stereo_width); 460 sound_set(SOUND_STEREO_WIDTH, stereo_width);
1047 461
1048#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F) 462#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
1049 mpeg_sound_set(SOUND_LOUDNESS, loudness); 463 sound_set(SOUND_LOUDNESS, loudness);
1050 mpeg_sound_set(SOUND_AVC, avc); 464 sound_set(SOUND_AVC, avc);
1051 mpeg_sound_set(SOUND_MDB_STRENGTH, mdb_strength); 465 sound_set(SOUND_MDB_STRENGTH, mdb_strength);
1052 mpeg_sound_set(SOUND_MDB_HARMONICS, mdb_harmonics); 466 sound_set(SOUND_MDB_HARMONICS, mdb_harmonics);
1053 mpeg_sound_set(SOUND_MDB_CENTER, mdb_center); 467 sound_set(SOUND_MDB_CENTER, mdb_center);
1054 mpeg_sound_set(SOUND_MDB_SHAPE, mdb_shape); 468 sound_set(SOUND_MDB_SHAPE, mdb_shape);
1055 mpeg_sound_set(SOUND_MDB_ENABLE, mdb_enable); 469 sound_set(SOUND_MDB_ENABLE, mdb_enable);
1056 mpeg_sound_set(SOUND_SUPERBASS, superbass); 470 sound_set(SOUND_SUPERBASS, superbass);
1057#endif 471#endif
1058#endif /* !SIMULATOR */ 472#endif /* !SIMULATOR */
1059 473
@@ -1201,7 +615,7 @@ void mp3_init(int volume, int bass, int treble, int balance, int loudness,
1201 playstart_tick = 0; 615 playstart_tick = 0;
1202 cumulative_ticks = 0; 616 cumulative_ticks = 0;
1203 callback_for_more = 0; 617 callback_for_more = 0;
1204 mpeg_is_initialized = false; 618 audio_is_initialized = false;
1205#endif 619#endif
1206} 620}
1207void mp3_shutdown(void) 621void mp3_shutdown(void)
@@ -1228,24 +642,6 @@ void mp3_play_pause(bool play)
1228 (void)play; 642 (void)play;
1229} 643}
1230 644
1231void mpeg_sound_set(int setting, int value)
1232{
1233 /* a dummy */
1234 (void)setting;
1235 (void)value;
1236}
1237bool mp3_is_playing(void)
1238{
1239 /* a dummy */
1240 return false;
1241}
1242
1243int mpeg_val2phys(int setting, int value)
1244{
1245 (void) setting;
1246 (void) value;
1247 return value; /* FIX dummy */
1248}
1249unsigned char* mp3_get_pos(void) 645unsigned char* mp3_get_pos(void)
1250{ 646{
1251 /* a dummy */ 647 /* a dummy */
diff --git a/firmware/mpeg.c b/firmware/mpeg.c
index 250547e24e..d8de1a37b4 100644
--- a/firmware/mpeg.c
+++ b/firmware/mpeg.c
@@ -31,6 +31,7 @@
31#include "mp3data.h" 31#include "mp3data.h"
32#include "buffer.h" 32#include "buffer.h"
33#include "mp3_playback.h" 33#include "mp3_playback.h"
34#include "sound.h"
34#ifndef SIMULATOR 35#ifndef SIMULATOR
35#include "i2c.h" 36#include "i2c.h"
36#include "mas.h" 37#include "mas.h"
@@ -901,7 +902,7 @@ static void track_change(void)
901 902
902#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F) 903#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
903 /* Reset the AVC */ 904 /* Reset the AVC */
904 mpeg_sound_set(SOUND_AVC, -1); 905 sound_set(SOUND_AVC, -1);
905#endif /* #if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F) */ 906#endif /* #if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F) */
906 remove_current_tag(); 907 remove_current_tag();
907 908
diff --git a/firmware/sound.c b/firmware/sound.c
new file mode 100644
index 0000000000..ab0ab1ed46
--- /dev/null
+++ b/firmware/sound.c
@@ -0,0 +1,634 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 by Linus Nielsen Feltzing
11 *
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.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include <stdbool.h>
20#include "config.h"
21#include "sound.h"
22#ifndef SIMULATOR
23#include "i2c.h"
24#include "mas.h"
25#include "dac.h"
26#include "system.h"
27#include "hwcompat.h"
28#endif
29
30#ifndef SIMULATOR
31extern bool audio_is_initialized;
32#endif
33
34#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
35extern unsigned long shadow_io_control_main;
36extern unsigned shadow_codec_reg0;
37#endif
38
39static const char* const units[] =
40{
41 "%", /* Volume */
42 "dB", /* Bass */
43 "dB", /* Treble */
44 "%", /* Balance */
45 "dB", /* Loudness */
46 "", /* AVC */
47 "", /* Channels */
48 "%", /* Stereo width */
49 "dB", /* Left gain */
50 "dB", /* Right gain */
51 "dB", /* Mic gain */
52 "dB", /* MDB Strength */
53 "%", /* MDB Harmonics */
54 "Hz", /* MDB Center */
55 "Hz", /* MDB Shape */
56 "", /* MDB Enable */
57 "", /* Super bass */
58};
59
60static const int numdecimals[] =
61{
62 0, /* Volume */
63 0, /* Bass */
64 0, /* Treble */
65 0, /* Balance */
66 0, /* Loudness */
67 0, /* AVC */
68 0, /* Channels */
69 0, /* Stereo width */
70 1, /* Left gain */
71 1, /* Right gain */
72 1, /* Mic gain */
73 0, /* MDB Strength */
74 0, /* MDB Harmonics */
75 0, /* MDB Center */
76 0, /* MDB Shape */
77 0, /* MDB Enable */
78 0, /* Super bass */
79};
80
81static const int steps[] =
82{
83 1, /* Volume */
84 1, /* Bass */
85 1, /* Treble */
86 1, /* Balance */
87 1, /* Loudness */
88 1, /* AVC */
89 1, /* Channels */
90 1, /* Stereo width */
91 1, /* Left gain */
92 1, /* Right gain */
93 1, /* Mic gain */
94 1, /* MDB Strength */
95 1, /* MDB Harmonics */
96 10, /* MDB Center */
97 10, /* MDB Shape */
98 1, /* MDB Enable */
99 1, /* Super bass */
100};
101
102static const int minval[] =
103{
104 0, /* Volume */
105#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
106 -12, /* Bass */
107 -12, /* Treble */
108#else
109 -15, /* Bass */
110 -15, /* Treble */
111#endif
112 -100, /* Balance */
113 0, /* Loudness */
114 -1, /* AVC */
115 0, /* Channels */
116 0, /* Stereo width */
117 0, /* Left gain */
118 0, /* Right gain */
119 0, /* Mic gain */
120 0, /* MDB Strength */
121 0, /* MDB Harmonics */
122 20, /* MDB Center */
123 50, /* MDB Shape */
124 0, /* MDB Enable */
125 0, /* Super bass */
126};
127
128static const int maxval[] =
129{
130 100, /* Volume */
131#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
132 12, /* Bass */
133 12, /* Treble */
134#else
135 15, /* Bass */
136 15, /* Treble */
137#endif
138 100, /* Balance */
139 17, /* Loudness */
140 4, /* AVC */
141 5, /* Channels */
142 255, /* Stereo width */
143 15, /* Left gain */
144 15, /* Right gain */
145 15, /* Mic gain */
146 127, /* MDB Strength */
147 100, /* MDB Harmonics */
148 300, /* MDB Center */
149 300, /* MDB Shape */
150 1, /* MDB Enable */
151 1, /* Super bass */
152};
153
154static const int defaultval[] =
155{
156 70, /* Volume */
157#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
158 6, /* Bass */
159 6, /* Treble */
160#else
161 7, /* Bass */
162 7, /* Treble */
163#endif
164 0, /* Balance */
165 0, /* Loudness */
166 0, /* AVC */
167 0, /* Channels */
168 100, /* Stereo width */
169 8, /* Left gain */
170 8, /* Right gain */
171 2, /* Mic gain */
172 50, /* MDB Strength */
173 48, /* MDB Harmonics */
174 60, /* MDB Center */
175 90, /* MDB Shape */
176 0, /* MDB Enable */
177 0, /* Super bass */
178};
179
180const char *sound_unit(int setting)
181{
182 return units[setting];
183}
184
185int sound_numdecimals(int setting)
186{
187 return numdecimals[setting];
188}
189
190int sound_steps(int setting)
191{
192 return steps[setting];
193}
194
195int sound_min(int setting)
196{
197 return minval[setting];
198}
199
200int sound_max(int setting)
201{
202 return maxval[setting];
203}
204
205int sound_default(int setting)
206{
207 return defaultval[setting];
208}
209
210#ifndef SIMULATOR
211#if CONFIG_HWCODEC == MAS3507D
212static const unsigned int bass_table[] =
213{
214 0x9e400, /* -15dB */
215 0xa2800, /* -14dB */
216 0xa7400, /* -13dB */
217 0xac400, /* -12dB */
218 0xb1800, /* -11dB */
219 0xb7400, /* -10dB */
220 0xbd400, /* -9dB */
221 0xc3c00, /* -8dB */
222 0xca400, /* -7dB */
223 0xd1800, /* -6dB */
224 0xd8c00, /* -5dB */
225 0xe0400, /* -4dB */
226 0xe8000, /* -3dB */
227 0xefc00, /* -2dB */
228 0xf7c00, /* -1dB */
229 0,
230 0x800, /* 1dB */
231 0x10000, /* 2dB */
232 0x17c00, /* 3dB */
233 0x1f800, /* 4dB */
234 0x27000, /* 5dB */
235 0x2e400, /* 6dB */
236 0x35800, /* 7dB */
237 0x3c000, /* 8dB */
238 0x42800, /* 9dB */
239 0x48800, /* 10dB */
240 0x4e400, /* 11dB */
241 0x53800, /* 12dB */
242 0x58800, /* 13dB */
243 0x5d400, /* 14dB */
244 0x61800 /* 15dB */
245};
246
247static const unsigned int treble_table[] =
248{
249 0xb2c00, /* -15dB */
250 0xbb400, /* -14dB */
251 0xc1800, /* -13dB */
252 0xc6c00, /* -12dB */
253 0xcbc00, /* -11dB */
254 0xd0400, /* -10dB */
255 0xd5000, /* -9dB */
256 0xd9800, /* -8dB */
257 0xde000, /* -7dB */
258 0xe2800, /* -6dB */
259 0xe7e00, /* -5dB */
260 0xec000, /* -4dB */
261 0xf0c00, /* -3dB */
262 0xf5c00, /* -2dB */
263 0xfac00, /* -1dB */
264 0,
265 0x5400, /* 1dB */
266 0xac00, /* 2dB */
267 0x10400, /* 3dB */
268 0x16000, /* 4dB */
269 0x1c000, /* 5dB */
270 0x22400, /* 6dB */
271 0x28400, /* 7dB */
272 0x2ec00, /* 8dB */
273 0x35400, /* 9dB */
274 0x3c000, /* 10dB */
275 0x42c00, /* 11dB */
276 0x49c00, /* 12dB */
277 0x51800, /* 13dB */
278 0x58400, /* 14dB */
279 0x5f800 /* 15dB */
280};
281
282static const unsigned int prescale_table[] =
283{
284 0x80000, /* 0db */
285 0x8e000, /* 1dB */
286 0x9a400, /* 2dB */
287 0xa5800, /* 3dB */
288 0xaf400, /* 4dB */
289 0xb8000, /* 5dB */
290 0xbfc00, /* 6dB */
291 0xc6c00, /* 7dB */
292 0xcd000, /* 8dB */
293 0xd25c0, /* 9dB */
294 0xd7800, /* 10dB */
295 0xdc000, /* 11dB */
296 0xdfc00, /* 12dB */
297 0xe3400, /* 13dB */
298 0xe6800, /* 14dB */
299 0xe9400 /* 15dB */
300};
301
302/* all values in tenth of dB */
303int current_volume = 0; /* -780..+180 */
304int current_balance = 0; /* -960..+960 */
305int current_treble = 0; /* -150..+150 */
306int current_bass = 0; /* -150..+150 */
307
308/* convert tenth of dB volume to register value */
309static int tenthdb2reg(int db) {
310 if (db < -540)
311 return (db + 780) / 30;
312 else
313 return (db + 660) / 15;
314}
315
316void set_prescaled_volume(void)
317{
318 int prescale;
319 int l, r;
320
321 prescale = MAX(current_bass, current_treble);
322 if (prescale < 0)
323 prescale = 0; /* no need to prescale if we don't boost
324 bass or treble */
325
326 mas_writereg(MAS_REG_KPRESCALE, prescale_table[prescale/10]);
327
328 /* gain up the analog volume to compensate the prescale reduction gain,
329 * but limit to +18 dB (the maximum the DAC can do */
330 if (current_volume + prescale > 180)
331 prescale = 180 - current_volume;
332 l = r = current_volume + prescale;
333
334 if (current_balance > 0)
335 {
336 l -= current_balance;
337 if (l < -780)
338 l = -780;
339 }
340 if (current_balance < 0)
341 {
342 r += current_balance;
343 if (r < -780)
344 r = -780;
345 }
346
347 dac_volume(tenthdb2reg(l), tenthdb2reg(r), false);
348}
349#endif /* MAS3507D */
350#endif /* !SIMULATOR */
351
352int channel_configuration = SOUND_CHAN_STEREO;
353int stereo_width = 100;
354
355#ifndef SIMULATOR
356static void set_channel_config(void)
357{
358 /* default values: stereo */
359 unsigned long val_ll = 0x80000;
360 unsigned long val_lr = 0;
361 unsigned long val_rl = 0;
362 unsigned long val_rr = 0x80000;
363
364 switch(channel_configuration)
365 {
366 /* case SOUND_CHAN_STEREO unnecessary */
367
368 case SOUND_CHAN_MONO:
369 val_ll = 0xc0000;
370 val_lr = 0xc0000;
371 val_rl = 0xc0000;
372 val_rr = 0xc0000;
373 break;
374
375 case SOUND_CHAN_CUSTOM:
376 {
377 /* fixed point variables (matching MAS internal format)
378 integer part: upper 13 bits (inlcuding sign)
379 fractional part: lower 19 bits */
380 long fp_width, fp_straight, fp_cross;
381
382 fp_width = (stereo_width << 19) / 100;
383 if (stereo_width <= 100)
384 {
385 fp_straight = - ((1<<19) + fp_width) / 2;
386 fp_cross = fp_straight + fp_width;
387 }
388 else
389 {
390 fp_straight = - (1<<19);
391 fp_cross = ((2 * fp_width / (((1<<19) + fp_width) >> 10))
392 << 9) - (1<<19);
393 }
394 val_ll = val_rr = fp_straight & 0xFFFFF;
395 val_lr = val_rl = fp_cross & 0xFFFFF;
396 }
397 break;
398
399 case SOUND_CHAN_MONO_LEFT:
400 val_ll = 0x80000;
401 val_lr = 0x80000;
402 val_rl = 0;
403 val_rr = 0;
404 break;
405
406 case SOUND_CHAN_MONO_RIGHT:
407 val_ll = 0;
408 val_lr = 0;
409 val_rl = 0x80000;
410 val_rr = 0x80000;
411 break;
412
413 case SOUND_CHAN_KARAOKE:
414 val_ll = 0x80001;
415 val_lr = 0x7ffff;
416 val_rl = 0x7ffff;
417 val_rr = 0x80001;
418 break;
419 }
420
421#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
422 mas_writemem(MAS_BANK_D0, MAS_D0_OUT_LL, &val_ll, 1); /* LL */
423 mas_writemem(MAS_BANK_D0, MAS_D0_OUT_LR, &val_lr, 1); /* LR */
424 mas_writemem(MAS_BANK_D0, MAS_D0_OUT_RL, &val_rl, 1); /* RL */
425 mas_writemem(MAS_BANK_D0, MAS_D0_OUT_RR, &val_rr, 1); /* RR */
426#elif CONFIG_HWCODEC == MAS3507D
427 mas_writemem(MAS_BANK_D1, 0x7f8, &val_ll, 1); /* LL */
428 mas_writemem(MAS_BANK_D1, 0x7f9, &val_lr, 1); /* LR */
429 mas_writemem(MAS_BANK_D1, 0x7fa, &val_rl, 1); /* RL */
430 mas_writemem(MAS_BANK_D1, 0x7fb, &val_rr, 1); /* RR */
431#endif
432}
433#endif /* !SIMULATOR */
434
435#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
436unsigned long mdb_shape_shadow = 0;
437unsigned long loudness_shadow = 0;
438#endif
439
440void sound_set(int setting, int value)
441{
442#ifdef SIMULATOR
443 setting = value;
444#else
445#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
446 int tmp;
447#endif
448
449 if(!audio_is_initialized)
450 return;
451
452 switch(setting)
453 {
454 case SOUND_VOLUME:
455#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
456 tmp = 0x7f00 * value / 100;
457 mas_codec_writereg(0x10, tmp & 0xff00);
458#elif CONFIG_HWCODEC == MAS3507D
459 current_volume = -780 + (value * 960 / 100); /* tenth of dB */
460 set_prescaled_volume();
461#endif
462 break;
463
464 case SOUND_BALANCE:
465#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
466 tmp = ((value * 127 / 100) & 0xff) << 8;
467 mas_codec_writereg(0x11, tmp & 0xff00);
468#elif CONFIG_HWCODEC == MAS3507D
469 current_balance = value * 960 / 100; /* tenth of dB */
470 set_prescaled_volume();
471#endif
472 break;
473
474 case SOUND_BASS:
475#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
476 tmp = ((value * 8) & 0xff) << 8;
477 mas_codec_writereg(0x14, tmp & 0xff00);
478#elif CONFIG_HWCODEC == MAS3507D
479 mas_writereg(MAS_REG_KBASS, bass_table[value+15]);
480 current_bass = value * 10;
481 set_prescaled_volume();
482#endif
483 break;
484
485 case SOUND_TREBLE:
486#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
487 tmp = ((value * 8) & 0xff) << 8;
488 mas_codec_writereg(0x15, tmp & 0xff00);
489#elif CONFIG_HWCODEC == MAS3507D
490 mas_writereg(MAS_REG_KTREBLE, treble_table[value+15]);
491 current_treble = value * 10;
492 set_prescaled_volume();
493#endif
494 break;
495
496#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
497 case SOUND_LOUDNESS:
498 loudness_shadow = (loudness_shadow & 0x04) |
499 (MAX(MIN(value * 4, 0x44), 0) << 8);
500 mas_codec_writereg(MAS_REG_KLOUDNESS, loudness_shadow);
501 break;
502
503 case SOUND_AVC:
504 switch (value) {
505 case 1: /* 20ms */
506 tmp = (0x1 << 8) | (0x8 << 12);
507 break;
508 case 2: /* 2s */
509 tmp = (0x2 << 8) | (0x8 << 12);
510 break;
511 case 3: /* 4s */
512 tmp = (0x4 << 8) | (0x8 << 12);
513 break;
514 case 4: /* 8s */
515 tmp = (0x8 << 8) | (0x8 << 12);
516 break;
517 case -1: /* turn off and then turn on again to decay quickly */
518 tmp = mas_codec_readreg(MAS_REG_KAVC);
519 mas_codec_writereg(MAS_REG_KAVC, 0);
520 break;
521 default: /* off */
522 tmp = 0;
523 break;
524 }
525 mas_codec_writereg(MAS_REG_KAVC, tmp);
526 break;
527
528 case SOUND_MDB_STRENGTH:
529 mas_codec_writereg(MAS_REG_KMDB_STR, (value & 0x7f) << 8);
530 break;
531
532 case SOUND_MDB_HARMONICS:
533 tmp = value * 127 / 100;
534 mas_codec_writereg(MAS_REG_KMDB_HAR, (tmp & 0x7f) << 8);
535 break;
536
537 case SOUND_MDB_CENTER:
538 mas_codec_writereg(MAS_REG_KMDB_FC, (value/10) << 8);
539 break;
540
541 case SOUND_MDB_SHAPE:
542 mdb_shape_shadow = (mdb_shape_shadow & 0x02) | ((value/10) << 8);
543 mas_codec_writereg(MAS_REG_KMDB_SWITCH, mdb_shape_shadow);
544 break;
545
546 case SOUND_MDB_ENABLE:
547 mdb_shape_shadow = (mdb_shape_shadow & ~0x02) | (value?2:0);
548 mas_codec_writereg(MAS_REG_KMDB_SWITCH, mdb_shape_shadow);
549 break;
550
551 case SOUND_SUPERBASS:
552 loudness_shadow = (loudness_shadow & ~0x04) |
553 (value?4:0);
554 mas_codec_writereg(MAS_REG_KLOUDNESS, loudness_shadow);
555 break;
556#endif
557 case SOUND_CHANNELS:
558 channel_configuration = value;
559 set_channel_config();
560 break;
561
562 case SOUND_STEREO_WIDTH:
563 stereo_width = value;
564 if (channel_configuration == SOUND_CHAN_CUSTOM)
565 set_channel_config();
566 break;
567 }
568#endif /* SIMULATOR */
569}
570
571int sound_val2phys(int setting, int value)
572{
573#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
574 int result = 0;
575
576 switch(setting)
577 {
578 case SOUND_LEFT_GAIN:
579 case SOUND_RIGHT_GAIN:
580 result = (value - 2) * 15;
581 break;
582
583 case SOUND_MIC_GAIN:
584 result = value * 15 + 210;
585 break;
586
587 default:
588 result = value;
589 break;
590 }
591 return result;
592#else
593 (void)setting;
594 return value;
595#endif
596}
597
598#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
599/* This function works by telling the decoder that we have another
600 crystal frequency than we actually have. It will adjust its internal
601 parameters and the result is that the audio is played at another pitch.
602
603 The pitch value is in tenths of percent.
604*/
605void sound_set_pitch(int pitch)
606{
607 unsigned long val;
608
609 /* invert pitch value */
610 pitch = 1000000/pitch;
611
612 /* Calculate the new (bogus) frequency */
613 val = 18432*pitch/1000;
614
615 mas_writemem(MAS_BANK_D0, MAS_D0_OFREQ_CONTROL, &val, 1);
616
617 /* We must tell the MAS that the frequency has changed.
618 This will unfortunately cause a short silence. */
619 mas_writemem(MAS_BANK_D0, MAS_D0_IO_CONTROL_MAIN, &shadow_io_control_main, 1);
620}
621#elif defined SIMULATOR
622void sound_set_pitch(int pitch)
623{
624 (void)pitch;
625}
626#endif
627
628#if CONFIG_HWCODEC == MASNONE
629bool mp3_is_playing(void)
630{
631 /* a dummy */
632 return false;
633}
634#endif