summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Gmeiner <christian.gmeiner@gmail.com>2008-04-28 08:37:18 +0000
committerChristian Gmeiner <christian.gmeiner@gmail.com>2008-04-28 08:37:18 +0000
commit8391526f794b296e5b6edd5707bbf25b5be73e17 (patch)
treec35e4565831b3a822394e98da32dc79db339345b
parent17f7adb90d232e6dece891790405d1b99b5b8215 (diff)
downloadrockbox-8391526f794b296e5b6edd5707bbf25b5be73e17.tar.gz
rockbox-8391526f794b296e5b6edd5707bbf25b5be73e17.zip
* introduce AUDIOHW_CAPS to define which audio codec can do what kind of operations in hw, e.g. setting bass
* added documentation why and when we need the software based prescaler * implement audiohw_set_bass and audiohw_set_treble for mas35xx * clean up sound_set_bass and sound_set_treble * simplify some #ifdef logic * fix special handling of WM8751 - looking for tester :) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17274 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/drivers/audio/mas35xx.c20
-rw-r--r--firmware/drivers/audio/wm8751.c2
-rw-r--r--firmware/export/audiohw.h35
-rw-r--r--firmware/export/mas35xx.h2
-rw-r--r--firmware/export/uda1380.h4
-rw-r--r--firmware/export/wm8758.h4
-rw-r--r--firmware/export/wm8975.h4
-rw-r--r--firmware/export/wm8985.h4
-rw-r--r--firmware/sound.c74
9 files changed, 95 insertions, 54 deletions
diff --git a/firmware/drivers/audio/mas35xx.c b/firmware/drivers/audio/mas35xx.c
index dac890ddc8..983818bf61 100644
--- a/firmware/drivers/audio/mas35xx.c
+++ b/firmware/drivers/audio/mas35xx.c
@@ -150,3 +150,23 @@ void audiohw_set_stereo_width(int val)
150 set_channel_config(); 150 set_channel_config();
151 } 151 }
152} 152}
153
154void audiohw_set_bass(int val)
155{
156#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
157 unsigned tmp = ((unsigned)(val * 8) & 0xff) << 8;
158 mas_codec_writereg(0x14, tmp);
159#elif CONFIG_CODEC == MAS3507D
160 mas_writereg(MAS_REG_KBASS, bass_table[val+15]);
161#endif
162}
163
164void audiohw_set_treble(int val)
165{
166#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
167 unsigned tmp = ((unsigned)(val * 8) & 0xff) << 8;
168 mas_codec_writereg(0x15, tmp);
169#elif CONFIG_CODEC == MAS3507D
170 mas_writereg(MAS_REG_KTREBLE, treble_table[val+15]);
171#endif
172}
diff --git a/firmware/drivers/audio/wm8751.c b/firmware/drivers/audio/wm8751.c
index 831f16ab17..26123456b6 100644
--- a/firmware/drivers/audio/wm8751.c
+++ b/firmware/drivers/audio/wm8751.c
@@ -79,7 +79,7 @@ static int tone_tenthdb2hw(int value)
79 /* -6.0db..+0db..+9.0db step 1.5db - translate -60..+0..+90 step 15 79 /* -6.0db..+0db..+9.0db step 1.5db - translate -60..+0..+90 step 15
80 to 10..6..0 step -1. 80 to 10..6..0 step -1.
81 */ 81 */
82 value = 10 - (value + 60) / 15; 82 value = (10 - (value + 60) / 15) / 10;
83 83
84 if (value == 6) 84 if (value == 6)
85 value = 0xf; /* 0db -> off */ 85 value = 0xf; /* 0db -> off */
diff --git a/firmware/export/audiohw.h b/firmware/export/audiohw.h
index b3493b86d9..d450613aff 100644
--- a/firmware/export/audiohw.h
+++ b/firmware/export/audiohw.h
@@ -23,6 +23,10 @@
23#include "config.h" 23#include "config.h"
24#include <stdbool.h> 24#include <stdbool.h>
25 25
26/* define some audiohw caps */
27#define TREBLE_CAP (1 << 0)
28#define BASS_CAP (1 << 1)
29
26#ifdef HAVE_UDA1380 30#ifdef HAVE_UDA1380
27#include "uda1380.h" 31#include "uda1380.h"
28#elif defined(HAVE_WM8751) 32#elif defined(HAVE_WM8751)
@@ -49,6 +53,17 @@
49#include "tsc2100.h" 53#include "tsc2100.h"
50#endif 54#endif
51 55
56/* convert caps into defines */
57#ifdef AUDIOHW_CAPS
58#if (AUDIOHW_CAPS & TREBLE_CAP)
59#define AUDIOHW_HAVE_TREBLE
60#endif
61
62#if (AUDIOHW_CAPS & BASS_CAP)
63#define AUDIOHW_HAVE_BASS
64#endif
65#endif /* AUDIOHW_CAPS */
66
52enum { 67enum {
53 SOUND_VOLUME = 0, 68 SOUND_VOLUME = 0,
54 SOUND_BASS, 69 SOUND_BASS,
@@ -141,6 +156,26 @@ void audiohw_mute(bool mute);
141 */ 156 */
142void audiohw_enable_output(bool enable); 157void audiohw_enable_output(bool enable);
143 158
159#ifdef AUDIOHW_HAVE_TREBLE
160/**
161 * Set new treble value.
162 * @param val to set.
163 * NOTE: AUDIOHW_CAPS need to contain
164 * TREBLE_CAP
165 */
166void audiohw_set_treble(int val);
167#endif
168
169#ifdef AUDIOHW_HAVE_BASS
170/**
171 * Set new bass value.
172 * @param val to set.
173 * NOTE: AUDIOHW_CAPS need to contain
174 * BASS_CAP
175 */
176void audiohw_set_bass(int val);
177#endif
178
144#ifdef HAVE_RECORDING 179#ifdef HAVE_RECORDING
145 180
146/** 181/**
diff --git a/firmware/export/mas35xx.h b/firmware/export/mas35xx.h
index a4e2413344..dbe9d38a37 100644
--- a/firmware/export/mas35xx.h
+++ b/firmware/export/mas35xx.h
@@ -24,6 +24,8 @@
24 24
25#include "config.h" 25#include "config.h"
26 26
27#define AUDIOHW_CAPS (BASS_CAP | TREBLE_CAP)
28
27#if CONFIG_CODEC == MAS3507D 29#if CONFIG_CODEC == MAS3507D
28#define VOLUME_MIN -780 30#define VOLUME_MIN -780
29#define VOLUME_MAX 180 31#define VOLUME_MAX 180
diff --git a/firmware/export/uda1380.h b/firmware/export/uda1380.h
index cd27536e87..c23f95265b 100644
--- a/firmware/export/uda1380.h
+++ b/firmware/export/uda1380.h
@@ -24,13 +24,13 @@
24#define VOLUME_MIN -840 24#define VOLUME_MIN -840
25#define VOLUME_MAX 0 25#define VOLUME_MAX 0
26 26
27#define AUDIOHW_CAPS (BASS_CAP | TREBLE_CAP)
28
27extern int tenthdb2master(int db); 29extern int tenthdb2master(int db);
28extern int tenthdb2mixer(int db); 30extern int tenthdb2mixer(int db);
29 31
30extern void audiohw_set_master_vol(int vol_l, int vol_r); 32extern void audiohw_set_master_vol(int vol_l, int vol_r);
31extern void audiohw_set_mixer_vol(int channel1, int channel2); 33extern void audiohw_set_mixer_vol(int channel1, int channel2);
32extern void audiohw_set_bass(int value);
33extern void audiohw_set_treble(int value);
34 34
35/** 35/**
36 * Sets frequency settings for DAC and ADC relative to MCLK 36 * Sets frequency settings for DAC and ADC relative to MCLK
diff --git a/firmware/export/wm8758.h b/firmware/export/wm8758.h
index 61db094684..5e37e203d5 100644
--- a/firmware/export/wm8758.h
+++ b/firmware/export/wm8758.h
@@ -24,15 +24,15 @@
24#define VOLUME_MIN -570 24#define VOLUME_MIN -570
25#define VOLUME_MAX 60 25#define VOLUME_MAX 60
26 26
27#define AUDIOHW_CAPS (BASS_CAP | TREBLE_CAP)
28
27extern int tenthdb2master(int db); 29extern int tenthdb2master(int db);
28extern int tenthdb2mixer(int db); 30extern int tenthdb2mixer(int db);
29 31
30extern void audiohw_set_master_vol(int vol_l, int vol_r); 32extern void audiohw_set_master_vol(int vol_l, int vol_r);
31extern void audiohw_set_lineout_vol(int vol_l, int vol_r); 33extern void audiohw_set_lineout_vol(int vol_l, int vol_r);
32extern void audiohw_set_mixer_vol(int channel1, int channel2); 34extern void audiohw_set_mixer_vol(int channel1, int channel2);
33extern void audiohw_set_bass(int value);
34extern void audiohw_set_bass_cutoff(int value); 35extern void audiohw_set_bass_cutoff(int value);
35extern void audiohw_set_treble(int value);
36extern void audiohw_set_treble_cutoff(int value); 36extern void audiohw_set_treble_cutoff(int value);
37extern void audiohw_set_nsorder(int order); 37extern void audiohw_set_nsorder(int order);
38extern void audiohw_set_sample_rate(int sampling_control); 38extern void audiohw_set_sample_rate(int sampling_control);
diff --git a/firmware/export/wm8975.h b/firmware/export/wm8975.h
index 1ae82061ee..6457f255f6 100644
--- a/firmware/export/wm8975.h
+++ b/firmware/export/wm8975.h
@@ -24,12 +24,12 @@
24#define VOLUME_MIN -730 24#define VOLUME_MIN -730
25#define VOLUME_MAX 60 25#define VOLUME_MAX 60
26 26
27#define AUDIOHW_CAPS (BASS_CAP | TREBLE_CAP)
28
27extern int tenthdb2master(int db); 29extern int tenthdb2master(int db);
28 30
29extern void audiohw_set_master_vol(int vol_l, int vol_r); 31extern void audiohw_set_master_vol(int vol_l, int vol_r);
30extern void audiohw_set_lineout_vol(int vol_l, int vol_r); 32extern void audiohw_set_lineout_vol(int vol_l, int vol_r);
31extern void audiohw_set_bass(int value);
32extern void audiohw_set_treble(int value);
33extern void audiohw_set_nsorder(int order); 33extern void audiohw_set_nsorder(int order);
34extern void audiohw_set_sample_rate(int sampling_control); 34extern void audiohw_set_sample_rate(int sampling_control);
35 35
diff --git a/firmware/export/wm8985.h b/firmware/export/wm8985.h
index 8fa58425bf..8696e3dd6f 100644
--- a/firmware/export/wm8985.h
+++ b/firmware/export/wm8985.h
@@ -24,15 +24,15 @@
24#define VOLUME_MIN -570 24#define VOLUME_MIN -570
25#define VOLUME_MAX 60 25#define VOLUME_MAX 60
26 26
27#define AUDIOHW_CAPS (BASS_CAP | TREBLE_CAP)
28
27extern int tenthdb2master(int db); 29extern int tenthdb2master(int db);
28extern int tenthdb2mixer(int db); 30extern int tenthdb2mixer(int db);
29 31
30extern void audiohw_set_master_vol(int vol_l, int vol_r); 32extern void audiohw_set_master_vol(int vol_l, int vol_r);
31extern void audiohw_set_lineout_vol(int vol_l, int vol_r); 33extern void audiohw_set_lineout_vol(int vol_l, int vol_r);
32extern void audiohw_set_mixer_vol(int channel1, int channel2); 34extern void audiohw_set_mixer_vol(int channel1, int channel2);
33extern void audiohw_set_bass(int value);
34extern void audiohw_set_bass_cutoff(int value); 35extern void audiohw_set_bass_cutoff(int value);
35extern void audiohw_set_treble(int value);
36extern void audiohw_set_treble_cutoff(int value); 36extern void audiohw_set_treble_cutoff(int value);
37extern void audiohw_set_nsorder(int order); 37extern void audiohw_set_nsorder(int order);
38extern void audiohw_set_sample_rate(int sampling_control); 38extern void audiohw_set_sample_rate(int sampling_control);
diff --git a/firmware/sound.c b/firmware/sound.c
index eda223bff0..325c42639a 100644
--- a/firmware/sound.c
+++ b/firmware/sound.c
@@ -222,10 +222,20 @@ static int tenthdb2reg(int db)
222} 222}
223#endif 223#endif
224 224
225#if (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 \ 225
226 || defined HAVE_WM8975 || defined HAVE_WM8758 || defined(HAVE_WM8731) \ 226/* MAS3587F and MAS3539F handle clipping prevention internally so we do not need
227 || defined(HAVE_WM8721) || defined(HAVE_TLV320) || defined(HAVE_WM8751) \ 227 * the prescaler.
228 || defined(HAVE_AS3514) || defined(HAVE_WM8985) || defined(HAVE_TSC2100) 228 */
229#if (CONFIG_CODEC != MAS3587F) && (CONFIG_CODEC != MAS3539F)
230
231/*
232 * The prescaler compensates for any kind of boosts, to prevent clipping.
233 *
234 * It's basically just a measure to make sure that audio does not clip during
235 * tone controls processing, like if i want to boost bass 12 dB, i can decrease
236 * the audio amplitude by -12 dB before processing, then increase master gain
237 * by 12 dB after processing.
238 */
229 239
230/* all values in tenth of dB MAS3507D UDA1380 */ 240/* all values in tenth of dB MAS3507D UDA1380 */
231int current_volume = 0; /* -780..+180 -840.. 0 */ 241int current_volume = 0; /* -780..+180 -840.. 0 */
@@ -352,60 +362,34 @@ void sound_set_bass(int value)
352{ 362{
353 if(!audio_is_initialized) 363 if(!audio_is_initialized)
354 return; 364 return;
355#if defined(HAVE_SW_TONE_CONTROLS) 365
356 current_bass = value * 10; 366#if defined(AUDIOHW_HAVE_BASS)
357 dsp_callback(DSP_CALLBACK_SET_BASS, current_bass);
358 set_prescaled_volume();
359#elif (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
360 unsigned tmp = ((unsigned)(value * 8) & 0xff) << 8;
361 mas_codec_writereg(0x14, tmp);
362#elif CONFIG_CODEC == MAS3507D
363 mas_writereg(MAS_REG_KBASS, bass_table[value+15]);
364 current_bass = value * 10;
365 set_prescaled_volume();
366#elif defined(HAVE_WM8751)
367 current_bass = value;
368 audiohw_set_bass(value); 367 audiohw_set_bass(value);
369 set_prescaled_volume(); 368#else
370#elif defined HAVE_WM8975 || defined HAVE_WM8758 || defined(HAVE_UDA1380) \ 369 dsp_callback(DSP_CALLBACK_SET_BASS, current_bass);
371 || defined HAVE_WM8731 || defined(HAVE_WM8721) || defined(HAVE_WM8985) 370#endif
371
372#if (CONFIG_CODEC != MAS3587F) && (CONFIG_CODEC != MAS3539F)
372 current_bass = value * 10; 373 current_bass = value * 10;
373 audiohw_set_bass(value);
374 set_prescaled_volume(); 374 set_prescaled_volume();
375#elif CONFIG_CPU == PNX0101 375#endif
376 /* TODO: implement for iFP */
377#endif
378 (void)value;
379} 376}
380 377
381void sound_set_treble(int value) 378void sound_set_treble(int value)
382{ 379{
383 if(!audio_is_initialized) 380 if(!audio_is_initialized)
384 return; 381 return;
385#if defined(HAVE_SW_TONE_CONTROLS) 382
386 current_treble = value * 10; 383#if defined(AUDIOHW_HAVE_TREBLE)
387 dsp_callback(DSP_CALLBACK_SET_TREBLE, current_treble);
388 set_prescaled_volume();
389#elif (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
390 unsigned tmp = ((unsigned)(value * 8) & 0xff) << 8;
391 mas_codec_writereg(0x15, tmp);
392#elif CONFIG_CODEC == MAS3507D
393 mas_writereg(MAS_REG_KTREBLE, treble_table[value+15]);
394 current_treble = value * 10;
395 set_prescaled_volume();
396#elif defined(HAVE_WM8751)
397 audiohw_set_treble(value);
398 current_treble = value;
399 set_prescaled_volume();
400#elif defined(HAVE_WM8975) || defined(HAVE_WM8758) || defined(HAVE_UDA1380) \
401 || defined(HAVE_WM8731) || defined(HAVE_WM8721) || defined(HAVE_WM8985)
402 audiohw_set_treble(value); 384 audiohw_set_treble(value);
385#else
386 dsp_callback(DSP_CALLBACK_SET_TREBLE, current_treble);
387#endif
388
389#if (CONFIG_CODEC != MAS3587F) && (CONFIG_CODEC != MAS3539F)
403 current_treble = value * 10; 390 current_treble = value * 10;
404 set_prescaled_volume(); 391 set_prescaled_volume();
405#elif CONFIG_CPU == PNX0101
406 /* TODO: implement for iFP */
407#endif 392#endif
408 (void)value;
409} 393}
410 394
411void sound_set_channels(int value) 395void sound_set_channels(int value)