summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-04-25 22:54:58 +0000
committerThomas Martitz <kugel@rockbox.org>2010-04-25 22:54:58 +0000
commit668bd3445ecb39483160bbb310afa4337c83d0d9 (patch)
tree9df94188c72cd0af723012e022187b14c0d8f710
parent5185d9e30a7597425aa7f77c2d323e3002c60d8e (diff)
downloadrockbox-668bd3445ecb39483160bbb310afa4337c83d0d9.tar.gz
rockbox-668bd3445ecb39483160bbb310afa4337c83d0d9.zip
Remove lots of simulator-speficic #ifdef'ing in sound.c to allow for DSP effects in the sims, e.g. for bass and treble (targets that do those effects in HW don't simulate using dsp).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25719 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/export/audiohw.h14
-rw-r--r--firmware/export/sound.h1
-rw-r--r--firmware/mp3_playback.c3
-rw-r--r--firmware/sound.c145
-rw-r--r--uisimulator/sdl/sound.c59
5 files changed, 92 insertions, 130 deletions
diff --git a/firmware/export/audiohw.h b/firmware/export/audiohw.h
index 91df2dd8b9..781bc12f8e 100644
--- a/firmware/export/audiohw.h
+++ b/firmware/export/audiohw.h
@@ -65,6 +65,20 @@
65#include "ak4537.h" 65#include "ak4537.h"
66#endif 66#endif
67 67
68
69
70#define ONE_DB 10
71
72#if !defined(VOLUME_MIN) && !defined(VOLUME_MAX)
73#warning define for VOLUME_MIN and VOLUME_MAX is missing
74#define VOLUME_MIN -700
75#define VOLUME_MAX 0
76#endif
77
78/* volume/balance/treble/bass interdependency main part */
79#define VOLUME_RANGE (VOLUME_MAX - VOLUME_MIN)
80
81
68/* convert caps into defines */ 82/* convert caps into defines */
69#ifdef AUDIOHW_CAPS 83#ifdef AUDIOHW_CAPS
70#if (AUDIOHW_CAPS & TREBLE_CAP) 84#if (AUDIOHW_CAPS & TREBLE_CAP)
diff --git a/firmware/export/sound.h b/firmware/export/sound.h
index 2e13174516..e68ae23774 100644
--- a/firmware/export/sound.h
+++ b/firmware/export/sound.h
@@ -24,6 +24,7 @@
24#include <inttypes.h> 24#include <inttypes.h>
25#include <audiohw.h> 25#include <audiohw.h>
26 26
27
27#if CONFIG_CODEC == SWCODEC 28#if CONFIG_CODEC == SWCODEC
28enum { 29enum {
29 DSP_CALLBACK_SET_PRESCALE = 0, 30 DSP_CALLBACK_SET_PRESCALE = 0,
diff --git a/firmware/mp3_playback.c b/firmware/mp3_playback.c
index 2bbd08d789..8e19829f56 100644
--- a/firmware/mp3_playback.c
+++ b/firmware/mp3_playback.c
@@ -69,9 +69,7 @@ static void (*callback_for_more)(unsigned char**, size_t*);
69#define MAX_ID3_TAGS (1<<4) /* Must be power of 2 */ 69#define MAX_ID3_TAGS (1<<4) /* Must be power of 2 */
70#define MAX_ID3_TAGS_MASK (MAX_ID3_TAGS - 1) 70#define MAX_ID3_TAGS_MASK (MAX_ID3_TAGS - 1)
71 71
72#ifndef SIMULATOR
73bool audio_is_initialized = false; 72bool audio_is_initialized = false;
74#endif
75 73
76/* FIX: this code pretty much assumes a MAS */ 74/* FIX: this code pretty much assumes a MAS */
77 75
@@ -353,6 +351,7 @@ void mp3_init(int volume, int bass, int treble, int balance, int loudness,
353 (void)mdb_shape; 351 (void)mdb_shape;
354 (void)mdb_enable; 352 (void)mdb_enable;
355 (void)superbass; 353 (void)superbass;
354 audio_is_initialized = true;
356#else 355#else
357#if CONFIG_CODEC == MAS3507D 356#if CONFIG_CODEC == MAS3507D
358 unsigned long val; 357 unsigned long val;
diff --git a/firmware/sound.c b/firmware/sound.c
index ca8b79e4d9..84c022e0c0 100644
--- a/firmware/sound.c
+++ b/firmware/sound.c
@@ -25,9 +25,9 @@
25#include "sound.h" 25#include "sound.h"
26#include "logf.h" 26#include "logf.h"
27#include "system.h" 27#include "system.h"
28#ifndef SIMULATOR
29#include "i2c.h" 28#include "i2c.h"
30#include "mas.h" 29#include "mas.h"
30#ifndef SIMULATOR
31#if CONFIG_CPU == PNX0101 31#if CONFIG_CPU == PNX0101
32#include "pnx0101.h" 32#include "pnx0101.h"
33#endif 33#endif
@@ -41,27 +41,10 @@
41 * find a nice way to handle 1.5db steps -> see wm8751 ifdef in sound_set_bass/treble 41 * find a nice way to handle 1.5db steps -> see wm8751 ifdef in sound_set_bass/treble
42*/ 42*/
43 43
44#define ONE_DB 10
45
46#if !defined(VOLUME_MIN) && !defined(VOLUME_MAX)
47#warning define for VOLUME_MIN and VOLUME_MAX is missing
48#define VOLUME_MIN -700
49#define VOLUME_MAX 0
50#endif
51
52/* volume/balance/treble/bass interdependency main part */
53#define VOLUME_RANGE (VOLUME_MAX - VOLUME_MIN)
54
55#ifndef SIMULATOR
56extern bool audio_is_initialized; 44extern bool audio_is_initialized;
57 45
58#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
59extern unsigned long shadow_io_control_main;
60extern unsigned shadow_codec_reg0;
61#endif
62#endif /* SIMULATOR */
63
64#ifdef SIMULATOR 46#ifdef SIMULATOR
47extern void audiohw_set_volume(int value);
65/* dummy for sim */ 48/* dummy for sim */
66const struct sound_settings_info audiohw_settings[] = { 49const struct sound_settings_info audiohw_settings[] = {
67 [SOUND_VOLUME] = {"dB", 0, 1, VOLUME_MIN / 10, VOLUME_MAX / 10, -25}, 50 [SOUND_VOLUME] = {"dB", 0, 1, VOLUME_MIN / 10, VOLUME_MAX / 10, -25},
@@ -90,7 +73,7 @@ const struct sound_settings_info audiohw_settings[] = {
90 [SOUND_MDB_SHAPE] = {"Hz", 0, 10, 50, 300, 90}, 73 [SOUND_MDB_SHAPE] = {"Hz", 0, 10, 50, 300, 90},
91 [SOUND_MDB_ENABLE] = {"", 0, 1, 0, 1, 0}, 74 [SOUND_MDB_ENABLE] = {"", 0, 1, 0, 1, 0},
92 [SOUND_SUPERBASS] = {"", 0, 1, 0, 1, 0}, 75 [SOUND_SUPERBASS] = {"", 0, 1, 0, 1, 0},
93#endif 76#endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */
94}; 77};
95#endif 78#endif
96 79
@@ -142,7 +125,7 @@ static sound_set_type * const sound_set_fns[] =
142 [SOUND_MDB_SHAPE] = sound_set_mdb_shape, 125 [SOUND_MDB_SHAPE] = sound_set_mdb_shape,
143 [SOUND_MDB_ENABLE] = sound_set_mdb_enable, 126 [SOUND_MDB_ENABLE] = sound_set_mdb_enable,
144 [SOUND_SUPERBASS] = sound_set_superbass, 127 [SOUND_SUPERBASS] = sound_set_superbass,
145#endif 128#endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */
146#if defined(AUDIOHW_HAVE_BASS_CUTOFF) 129#if defined(AUDIOHW_HAVE_BASS_CUTOFF)
147 [SOUND_BASS_CUTOFF] = sound_set_bass_cutoff, 130 [SOUND_BASS_CUTOFF] = sound_set_bass_cutoff,
148#endif 131#endif
@@ -166,7 +149,6 @@ void sound_set_dsp_callback(int (*func)(int, intptr_t))
166} 149}
167#endif 150#endif
168 151
169#ifndef SIMULATOR
170#if CONFIG_CODEC == MAS3507D 152#if CONFIG_CODEC == MAS3507D
171/* convert tenth of dB volume (-780..+180) to dac3550 register value */ 153/* convert tenth of dB volume (-780..+180) to dac3550 register value */
172static int tenthdb2reg(int db) 154static int tenthdb2reg(int db)
@@ -248,6 +230,7 @@ static void set_prescaled_volume(void)
248 dsp_callback(DSP_CALLBACK_SET_SW_VOLUME, 0); 230 dsp_callback(DSP_CALLBACK_SET_SW_VOLUME, 0);
249#endif 231#endif
250 232
233#ifndef SIMULATOR
251#if CONFIG_CODEC == MAS3507D 234#if CONFIG_CODEC == MAS3507D
252 dac_volume(tenthdb2reg(l), tenthdb2reg(r), false); 235 dac_volume(tenthdb2reg(l), tenthdb2reg(r), false);
253#elif defined(HAVE_UDA1380) || defined(HAVE_WM8975) || defined(HAVE_WM8758) \ 236#elif defined(HAVE_UDA1380) || defined(HAVE_WM8975) || defined(HAVE_WM8758) \
@@ -265,13 +248,13 @@ static void set_prescaled_volume(void)
265#elif defined(HAVE_JZ4740_CODEC) 248#elif defined(HAVE_JZ4740_CODEC)
266 audiohw_set_volume(current_volume); 249 audiohw_set_volume(current_volume);
267#endif 250#endif
251#else /* SIMULATOR */
252 audiohw_set_volume(current_volume);
253#endif /* !SIMULATOR */
268} 254}
269#endif /* (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 */ 255#endif /* (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 */
270#endif /* !SIMULATOR */
271 256
272 257
273#ifndef SIMULATOR
274
275#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) 258#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
276unsigned long mdb_shape_shadow = 0; 259unsigned long mdb_shape_shadow = 0;
277unsigned long loudness_shadow = 0; 260unsigned long loudness_shadow = 0;
@@ -398,7 +381,7 @@ void sound_set_treble_cutoff(int value)
398} 381}
399#endif 382#endif
400 383
401#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) 384#if ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F))
402void sound_set_loudness(int value) 385void sound_set_loudness(int value)
403{ 386{
404 if(!audio_is_initialized) 387 if(!audio_is_initialized)
@@ -486,95 +469,6 @@ void sound_set_superbass(int value)
486} 469}
487#endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */ 470#endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */
488 471
489#else /* SIMULATOR */
490int sim_volume;
491void sound_set_volume(int value)
492{
493 /* 128 is SDL_MIX_MAXVOLUME */
494 sim_volume = 128 * (value - VOLUME_MIN / 10) / (VOLUME_RANGE / 10);
495}
496
497void sound_set_balance(int value)
498{
499 (void)value;
500}
501
502void sound_set_bass(int value)
503{
504 (void)value;
505}
506
507void sound_set_treble(int value)
508{
509 (void)value;
510}
511
512void sound_set_channels(int value)
513{
514 (void)value;
515}
516
517void sound_set_stereo_width(int value)
518{
519 (void)value;
520}
521
522#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
523void sound_set_loudness(int value)
524{
525 (void)value;
526}
527
528void sound_set_avc(int value)
529{
530 (void)value;
531}
532
533void sound_set_mdb_strength(int value)
534{
535 (void)value;
536}
537
538void sound_set_mdb_harmonics(int value)
539{
540 (void)value;
541}
542
543void sound_set_mdb_center(int value)
544{
545 (void)value;
546}
547
548void sound_set_mdb_shape(int value)
549{
550 (void)value;
551}
552
553void sound_set_mdb_enable(int value)
554{
555 (void)value;
556}
557
558void sound_set_superbass(int value)
559{
560 (void)value;
561}
562#endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */
563
564#if defined(HAVE_WM8758) || defined(HAVE_WM8985)
565void sound_set_bass_cutoff(int value)
566{
567 (void) value;
568}
569
570void sound_set_treble_cutoff(int value)
571{
572 (void) value;
573}
574#endif /* HAVE_WM8758 */
575
576#endif /* SIMULATOR */
577
578void sound_set(int setting, int value) 472void sound_set(int setting, int value)
579{ 473{
580 sound_set_type* sound_set_val = sound_get_fn(setting); 474 sound_set_type* sound_set_val = sound_get_fn(setting);
@@ -691,13 +585,19 @@ int sound_val2phys(int setting, int value)
691#endif /* !defined(HAVE_AS3514) || defined(SIMULATOR) */ 585#endif /* !defined(HAVE_AS3514) || defined(SIMULATOR) */
692 586
693#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) 587#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
694#ifndef SIMULATOR
695/* This function works by telling the decoder that we have another 588/* This function works by telling the decoder that we have another
696 crystal frequency than we actually have. It will adjust its internal 589 crystal frequency than we actually have. It will adjust its internal
697 parameters and the result is that the audio is played at another pitch. 590 parameters and the result is that the audio is played at another pitch.
698 591
699 The pitch value precision is based on PITCH_SPEED_PRECISION (in dsp.h) 592 The pitch value precision is based on PITCH_SPEED_PRECISION (in dsp.h)
700*/ 593*/
594
595#ifdef SIMULATOR
596static
597#else
598extern
599#endif
600 unsigned long shadow_io_control_main;
701static int last_pitch = PITCH_SPEED_100; 601static int last_pitch = PITCH_SPEED_100;
702 602
703void sound_set_pitch(int32_t pitch) 603void sound_set_pitch(int32_t pitch)
@@ -723,15 +623,4 @@ int32_t sound_get_pitch(void)
723{ 623{
724 return last_pitch; 624 return last_pitch;
725} 625}
726#else /* SIMULATOR */
727void sound_set_pitch(int32_t pitch)
728{
729 (void)pitch;
730}
731
732int32_t sound_get_pitch(void)
733{
734 return PITCH_SPEED_100;
735}
736#endif /* SIMULATOR */
737#endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */ 626#endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */
diff --git a/uisimulator/sdl/sound.c b/uisimulator/sdl/sound.c
index 428983a1b8..aa689b921d 100644
--- a/uisimulator/sdl/sound.c
+++ b/uisimulator/sdl/sound.c
@@ -27,11 +27,15 @@
27#include "debug.h" 27#include "debug.h"
28#include "kernel.h" 28#include "kernel.h"
29#include "sound.h" 29#include "sound.h"
30#include "audiohw.h"
30 31
31#include "pcm.h" 32#include "pcm.h"
32#include "pcm_sampr.h" 33#include "pcm_sampr.h"
33#include "SDL.h" 34#include "SDL.h"
34 35
36static int sim_volume = 0;
37
38#if CONFIG_CODEC == SWCODEC
35static int cvt_status = -1; 39static int cvt_status = -1;
36 40
37static Uint8* pcm_data; 41static Uint8* pcm_data;
@@ -347,3 +351,58 @@ void pcm_play_dma_init(void)
347void pcm_postinit(void) 351void pcm_postinit(void)
348{ 352{
349} 353}
354
355#endif /* CONFIG_CODEC == SWCODEC */
356
357/**
358 * Audio Hardware api. Make them do nothing as we cannot properly simulate with
359 * SDL. if we used DSP we would run code that doesn't actually run on the target
360 **/
361void audiohw_set_volume(int volume)
362{
363 sim_volume = SDL_MIX_MAXVOLUME * ((volume - VOLUME_MIN) / 10) / (VOLUME_RANGE / 10);
364}
365#if defined(AUDIOHW_HAVE_PRESCALER)
366void audiohw_set_prescaler(int value) { (void)value; }
367#endif
368#if defined(AUDIOHW_HAVE_BALANCE)
369void audiohw_set_balance(int value) { (void)value; }
370#endif
371#if defined(AUDIOHW_HAVE_BASS)
372void audiohw_set_bass(int value) { (void)value; }
373#endif
374#if defined(AUDIOHW_HAVE_TREBLE)
375void audiohw_set_treble(int value) { (void)value; }
376#endif
377#if CONFIG_CODEC != SWCODEC
378void audiohw_set_channel(int value) { (void)value; }
379void audiohw_set_stereo_width(int value){ (void)value; }
380#endif
381#if defined(AUDIOHW_HAVE_BASS_CUTOFF)
382void audiohw_set_bass_cutoff(value) { (void)value; }
383#endif
384#if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
385void audiohw_set_treble_cutoff(value) { (void)value; }
386#endif
387#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
388int mas_codec_readreg(int reg)
389{
390 (void)reg;
391 return 0;
392}
393
394int mas_codec_writereg(int reg, unsigned int val)
395{
396 (void)reg;
397 (void)val;
398 return 0;
399}
400int mas_writemem(int bank, int addr, const unsigned long* src, int len)
401{
402 (void)bank;
403 (void)addr;
404 (void)src;
405 (void)len;
406 return 0;
407}
408#endif