summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2013-04-20 04:06:13 -0400
committerMichael Sevakis <jethead71@rockbox.org>2013-04-22 20:38:17 -0400
commite61e9c61d0ba6990576d59efca07afa13fd97566 (patch)
tree4b17b22dd4f56568666e25292f38224529ec7113 /firmware/drivers
parent91b33d5a3e92d62cf6fb6be875437d35b632caf5 (diff)
downloadrockbox-e61e9c61d0ba6990576d59efca07afa13fd97566.tar.gz
rockbox-e61e9c61d0ba6990576d59efca07afa13fd97566.zip
Do some cleanup, adjustment and a couple fixes to recent sound changes.
* SOUND_x enum can be generated by audiohw_settings.h along with settings entries and sound_val2phys. * VOLUME_MIN and VOLUME_MAX are no longer necessary within sound.c. If you need them, they are for target-defined purposes. * Fix up SDL volume implementation in sdl.c. Move sim volume calculation code to pcm-sdl.c. * Min trigger tresholds were based upon VOLUME_MIN for some reason. These setting have nothing to do with playback volume. Since it is no longer present, set these at -89dB which is the minimum peak meter sensitivity setting. * Fix an oversight in wm8758.c. I forgot to add the dB->register conversion to audiohw_set_volume. Change-Id: Ie1df33f1793eee75e6793f16bc7bddd16edb7f75
Diffstat (limited to 'firmware/drivers')
-rw-r--r--firmware/drivers/audio/aic3x.c6
-rw-r--r--firmware/drivers/audio/ak4537.c4
-rw-r--r--firmware/drivers/audio/as3514.c17
-rw-r--r--firmware/drivers/audio/cs42l55.c2
-rw-r--r--firmware/drivers/audio/dummy_codec.c6
-rw-r--r--firmware/drivers/audio/rk27xx_codec.c2
-rw-r--r--firmware/drivers/audio/sdl.c20
-rw-r--r--firmware/drivers/audio/tlv320.c2
-rw-r--r--firmware/drivers/audio/tsc2100.c6
-rw-r--r--firmware/drivers/audio/uda1341.c2
-rw-r--r--firmware/drivers/audio/wm8731.c2
-rw-r--r--firmware/drivers/audio/wm8751.c2
-rw-r--r--firmware/drivers/audio/wm8758.c10
-rw-r--r--firmware/drivers/audio/wm8975.c2
-rw-r--r--firmware/drivers/audio/wm8978.c21
-rw-r--r--firmware/drivers/audio/wm8985.c4
16 files changed, 57 insertions, 51 deletions
diff --git a/firmware/drivers/audio/aic3x.c b/firmware/drivers/audio/aic3x.c
index 60330f1779..9b705db7f5 100644
--- a/firmware/drivers/audio/aic3x.c
+++ b/firmware/drivers/audio/aic3x.c
@@ -37,17 +37,17 @@ static char volume_left = 0, volume_right = 0;
37static int vol_tenthdb2hw(int db) 37static int vol_tenthdb2hw(int db)
38{ 38{
39 /* 0 to -63.0dB in 1dB steps, aic3x can goto -63.5 in 0.5dB steps */ 39 /* 0 to -63.0dB in 1dB steps, aic3x can goto -63.5 in 0.5dB steps */
40 if (db < VOLUME_MIN) 40 if (db <= -640)
41 { 41 {
42 return 0x7E; 42 return 0x7E;
43 } 43 }
44 else if (db >= VOLUME_MAX) 44 else if (db >= 0)
45 { 45 {
46 return 0x00; 46 return 0x00;
47 } 47 }
48 else 48 else
49 { 49 {
50 return (-((db)/5)); /* VOLUME_MIN is negative */ 50 return (-((db)/5));
51 } 51 }
52} 52}
53 53
diff --git a/firmware/drivers/audio/ak4537.c b/firmware/drivers/audio/ak4537.c
index 1628af8a5c..90d264e445 100644
--- a/firmware/drivers/audio/ak4537.c
+++ b/firmware/drivers/audio/ak4537.c
@@ -67,9 +67,9 @@ static void codec_set_active(int active)
67/* convert tenth of dB volume (-1270..0) to master volume register value */ 67/* convert tenth of dB volume (-1270..0) to master volume register value */
68static int vol_tenthdb2hw(int db) 68static int vol_tenthdb2hw(int db)
69{ 69{
70 if (db < VOLUME_MIN) 70 if (db <= -1280)
71 return 0xff; /* mute */ 71 return 0xff; /* mute */
72 else if (db >= VOLUME_MAX) 72 else if (db >= 0)
73 return 0x00; 73 return 0x00;
74 else 74 else
75 return ((-db)/5); 75 return ((-db)/5);
diff --git a/firmware/drivers/audio/as3514.c b/firmware/drivers/audio/as3514.c
index e1c7f6575e..1f79277423 100644
--- a/firmware/drivers/audio/as3514.c
+++ b/firmware/drivers/audio/as3514.c
@@ -31,6 +31,16 @@
31#include "i2s.h" 31#include "i2s.h"
32#include "ascodec.h" 32#include "ascodec.h"
33 33
34#if CONFIG_CPU == AS3525v2
35/* Headphone volume goes from -81.0 ... +6dB */
36#define VOLUME_MIN -820
37#define VOLUME_MAX 60
38#else
39/* Headphone volume goes from -73.5 ... +6dB */
40#define VOLUME_MIN -740
41#define VOLUME_MAX 60
42#endif
43
34/* 44/*
35 * This drivers supports: 45 * This drivers supports:
36 * as3514 , as used in the PP targets 46 * as3514 , as used in the PP targets
@@ -99,13 +109,12 @@ static void as3514_write_masked(unsigned int reg, unsigned int bits,
99/* convert tenth of dB volume to master volume register value */ 109/* convert tenth of dB volume to master volume register value */
100static int vol_tenthdb2hw(int db) 110static int vol_tenthdb2hw(int db)
101{ 111{
102 /* +6 to -73.5dB (or -81.0 dB) in 1.5dB steps == 53 (or 58) levels */ 112 if (db <= VOLUME_MIN) {
103 if (db < VOLUME_MIN) {
104 return 0x0; 113 return 0x0;
105 } else if (db > VOLUME_MAX) { 114 } else if (db > VOLUME_MAX) {
106 return (VOLUME_MAX-VOLUME_MIN)/15; 115 return (VOLUME_MAX - VOLUME_MIN) / 15;
107 } else { 116 } else {
108 return((db-VOLUME_MIN)/15); /* VOLUME_MIN is negative */ 117 return (db - VOLUME_MIN) / 15;
109 } 118 }
110} 119}
111 120
diff --git a/firmware/drivers/audio/cs42l55.c b/firmware/drivers/audio/cs42l55.c
index 6c6e17abd4..02c80daf7d 100644
--- a/firmware/drivers/audio/cs42l55.c
+++ b/firmware/drivers/audio/cs42l55.c
@@ -38,7 +38,7 @@ static int vol_tenthdb2hw(int db)
38 /* 0001100 == +12dB (0xc) */ 38 /* 0001100 == +12dB (0xc) */
39 /* 0000000 == 0dB (0x0) */ 39 /* 0000000 == 0dB (0x0) */
40 /* 1000100 == -60dB (0x44, this is actually -58dB) */ 40 /* 1000100 == -60dB (0x44, this is actually -58dB) */
41 if (db < VOLUME_MIN) return HPACTL_HPAMUTE; 41 if (db <= -600) return HPACTL_HPAMUTE;
42 return (db / 10) & HPACTL_HPAVOL_MASK; 42 return (db / 10) & HPACTL_HPAVOL_MASK;
43} 43}
44 44
diff --git a/firmware/drivers/audio/dummy_codec.c b/firmware/drivers/audio/dummy_codec.c
index 3e73137eb9..fbbe836499 100644
--- a/firmware/drivers/audio/dummy_codec.c
+++ b/firmware/drivers/audio/dummy_codec.c
@@ -40,9 +40,9 @@ void audiohw_set_frequency(int fsel)
40#ifdef HAVE_SW_VOLUME_CONTROL 40#ifdef HAVE_SW_VOLUME_CONTROL
41void audiohw_set_volume(int vol_l, int vol_r) 41void audiohw_set_volume(int vol_l, int vol_r)
42{ 42{
43 /* SW volume for <= 1.0 gain, HW at unity, < VOLUME_MIN == MUTE */ 43 /* SW volume for <= 1.0 gain, HW at unity, <= DUMMY_VOLUME_MIN == MUTE */
44 int sw_volume_l = vol_l < VOLUME_MIN ? PCM_MUTE_LEVEL : MIN(vol_l, 0); 44 int sw_volume_l = vol_l <= DUMMY_VOLUME_MIN ? PCM_MUTE_LEVEL : vol_l;
45 int sw_volume_r = vol_r < VOLUME_MIN ? PCM_MUTE_LEVEL : MIN(vol_r, 0); 45 int sw_volume_r = vol_r <= DUMMY_VOLUME_MIN ? PCM_MUTE_LEVEL : vol_r;
46 pcm_set_master_volume(sw_volume_l, sw_volume_r); 46 pcm_set_master_volume(sw_volume_l, sw_volume_r);
47} 47}
48#endif /* HAVE_SW_VOLUME_CONTROL */ 48#endif /* HAVE_SW_VOLUME_CONTROL */
diff --git a/firmware/drivers/audio/rk27xx_codec.c b/firmware/drivers/audio/rk27xx_codec.c
index 8f294ba9f3..2b0f2dbb22 100644
--- a/firmware/drivers/audio/rk27xx_codec.c
+++ b/firmware/drivers/audio/rk27xx_codec.c
@@ -58,7 +58,7 @@ static int vol_tenthdb2hw(int tdb)
58 * depending on gain region. 58 * depending on gain region.
59 */ 59 */
60 60
61 if (tdb < VOLUME_MIN) 61 if (tdb <= -340)
62 return 32; 62 return 32;
63 else if (tdb < -115) 63 else if (tdb < -115)
64 return -(((tdb + 115)/20) - 20); /* 2.0 dB steps */ 64 return -(((tdb + 115)/20) - 20); /* 2.0 dB steps */
diff --git a/firmware/drivers/audio/sdl.c b/firmware/drivers/audio/sdl.c
index c14ba0c583..f35cec8cb7 100644
--- a/firmware/drivers/audio/sdl.c
+++ b/firmware/drivers/audio/sdl.c
@@ -23,6 +23,12 @@
23#include "config.h" 23#include "config.h"
24#include "sound.h" 24#include "sound.h"
25#include "pcm_sampr.h" 25#include "pcm_sampr.h"
26#if CONFIG_CODEC == SWCODEC
27#include "fixedpoint.h"
28#ifdef HAVE_SW_VOLUME_CONTROL
29#include "pcm_sw_volume.h"
30#endif
31#endif
26 32
27/** 33/**
28 * Audio Hardware api. Make them do nothing as we cannot properly simulate with 34 * Audio Hardware api. Make them do nothing as we cannot properly simulate with
@@ -30,8 +36,6 @@
30 **/ 36 **/
31 37
32#ifdef HAVE_SW_VOLUME_CONTROL 38#ifdef HAVE_SW_VOLUME_CONTROL
33#include "pcm_sw_volume.h"
34
35void audiohw_set_volume(int vol_l, int vol_r) 39void audiohw_set_volume(int vol_l, int vol_r)
36{ 40{
37 pcm_set_master_volume(vol_l, vol_r); 41 pcm_set_master_volume(vol_l, vol_r);
@@ -39,21 +43,13 @@ void audiohw_set_volume(int vol_l, int vol_r)
39 43
40#else /* ndef HAVE_SW_VOLUME_CONTROL */ 44#else /* ndef HAVE_SW_VOLUME_CONTROL */
41 45
42extern void pcm_set_mixer_volume(int);
43 46
44void audiohw_set_volume(int volume) 47void audiohw_set_volume(int volume)
45{ 48{
46#if CONFIG_CODEC == SWCODEC 49#if CONFIG_CODEC == SWCODEC
47#if !(CONFIG_PLATFORM & PLATFORM_MAEMO5) 50 extern void pcm_set_mixer_volume(int volume);
48 if (volume < VOLUME_MIN)
49 volume = 0;
50 else
51 volume = SDL_MIX_MAXVOLUME * (volume - VOLUME_MIN + ONE_DB) /
52 (VOLUME_RANGE + ONE_DB);
53#endif /* !(CONFIG_PLATFORM & PLATFORM_MAEMO5) */
54
55 pcm_set_mixer_volume(volume); 51 pcm_set_mixer_volume(volume);
56#endif /* CONFIG_CODEC == SWCODEC */ 52#endif
57 (void)volume; 53 (void)volume;
58} 54}
59#endif /* HAVE_SW_VOLUME_CONTROL */ 55#endif /* HAVE_SW_VOLUME_CONTROL */
diff --git a/firmware/drivers/audio/tlv320.c b/firmware/drivers/audio/tlv320.c
index 6118734d37..9fa676f3d5 100644
--- a/firmware/drivers/audio/tlv320.c
+++ b/firmware/drivers/audio/tlv320.c
@@ -40,7 +40,7 @@ static int vol_tenthdb2hw(int db)
40 /* 0110000 == -73dB (0x30) */ 40 /* 0110000 == -73dB (0x30) */
41 /* 0101111 == mute (0x2f) */ 41 /* 0101111 == mute (0x2f) */
42 42
43 if (db < VOLUME_MIN) { 43 if (db <= -740) {
44 return 0x2f; 44 return 0x2f;
45 } else { 45 } else {
46 return((db/10)+73+0x30); 46 return((db/10)+73+0x30);
diff --git a/firmware/drivers/audio/tsc2100.c b/firmware/drivers/audio/tsc2100.c
index fda192a62a..b74d445056 100644
--- a/firmware/drivers/audio/tsc2100.c
+++ b/firmware/drivers/audio/tsc2100.c
@@ -34,12 +34,12 @@ static bool is_muted = false;
34static int vol_tenthdb2hw(int db) 34static int vol_tenthdb2hw(int db)
35{ 35{
36 /* 0 to -63.0dB in 1dB steps, tsc2100 can goto -63.5 in 0.5dB steps */ 36 /* 0 to -63.0dB in 1dB steps, tsc2100 can goto -63.5 in 0.5dB steps */
37 if (db < VOLUME_MIN) { 37 if (db <= -640) {
38 return 0x7E; 38 return 0x7E;
39 } else if (db >= VOLUME_MAX) { 39 } else if (db >= 0) {
40 return 0x00; 40 return 0x00;
41 } else { 41 } else {
42 return(-((db)/5)); /* VOLUME_MIN is negative */ 42 return(-((db)/5));
43 } 43 }
44} 44}
45 45
diff --git a/firmware/drivers/audio/uda1341.c b/firmware/drivers/audio/uda1341.c
index e15cd39bfc..75573105de 100644
--- a/firmware/drivers/audio/uda1341.c
+++ b/firmware/drivers/audio/uda1341.c
@@ -31,7 +31,7 @@
31/* convert tenth of dB volume (-600..0) to volume register value */ 31/* convert tenth of dB volume (-600..0) to volume register value */
32static int vol_tenthdb2hw(int db) 32static int vol_tenthdb2hw(int db)
33{ 33{
34 if (db < -600) 34 if (db <= -610)
35 return 63; 35 return 63;
36 else /* 1 dB steps */ 36 else /* 1 dB steps */
37 return -(db / 10) + 1; 37 return -(db / 10) + 1;
diff --git a/firmware/drivers/audio/wm8731.c b/firmware/drivers/audio/wm8731.c
index f84edc55da..5c1e623a35 100644
--- a/firmware/drivers/audio/wm8731.c
+++ b/firmware/drivers/audio/wm8731.c
@@ -101,7 +101,7 @@ static int vol_tenthdb2hw(int db)
101 /* 1111001 == 0dB (0x79) */ 101 /* 1111001 == 0dB (0x79) */
102 /* 0110000 == -73dB (0x30) */ 102 /* 0110000 == -73dB (0x30) */
103 /* 0101111 == mute (0x2f) */ 103 /* 0101111 == mute (0x2f) */
104 if (db < VOLUME_MIN) { 104 if (db <= -740) {
105 return 0x2f; 105 return 0x2f;
106 } else { 106 } else {
107 return((db/10)+0x30+73); 107 return((db/10)+0x30+73);
diff --git a/firmware/drivers/audio/wm8751.c b/firmware/drivers/audio/wm8751.c
index feba05e504..476c6c342a 100644
--- a/firmware/drivers/audio/wm8751.c
+++ b/firmware/drivers/audio/wm8751.c
@@ -117,7 +117,7 @@ static int vol_tenthdb2hw(int db)
117 /* 1111001 == 0dB (0x79) */ 117 /* 1111001 == 0dB (0x79) */
118 /* 0110000 == -73dB (0x30) */ 118 /* 0110000 == -73dB (0x30) */
119 /* 0101111..0000000 == mute (<= 0x2f) */ 119 /* 0101111..0000000 == mute (<= 0x2f) */
120 if (db < VOLUME_MIN) 120 if (db <= -740)
121 return 0x0; 121 return 0x0;
122 else 122 else
123 return (db / 10) + 73 + 0x30; 123 return (db / 10) + 73 + 0x30;
diff --git a/firmware/drivers/audio/wm8758.c b/firmware/drivers/audio/wm8758.c
index 3f3ac79229..f7d7a5bc22 100644
--- a/firmware/drivers/audio/wm8758.c
+++ b/firmware/drivers/audio/wm8758.c
@@ -38,7 +38,7 @@ static unsigned short eq1_reg = EQ1_EQ3DMODE | EQ_GAIN_VALUE(0);
38static unsigned short eq5_reg = EQ_GAIN_VALUE(0); 38static unsigned short eq5_reg = EQ_GAIN_VALUE(0);
39 39
40/* convert tenth of dB volume (-89..6) to master volume register value */ 40/* convert tenth of dB volume (-89..6) to master volume register value */
41int tenthdb2master(int db) 41static int vol_tenthdb2hw(int db)
42{ 42{
43 /* att DAC AMP result 43 /* att DAC AMP result
44 +6dB 0 +6 96 44 +6dB 0 +6 96
@@ -47,10 +47,10 @@ int tenthdb2master(int db)
47 -58dB -1 -57 32 47 -58dB -1 -57 32
48 -89dB -32 -57 1 48 -89dB -32 -57 1
49 -90dB -oo -oo 0 */ 49 -90dB -oo -oo 0 */
50 if (db < VOLUME_MIN) { 50 if (db <= -900) {
51 return 0; 51 return 0;
52 } else { 52 } else {
53 return (db-VOLUME_MIN)/10 + 1; 53 return db / 10 - -90;
54 } 54 }
55} 55}
56 56
@@ -137,6 +137,10 @@ void audiohw_postinit(void)
137void audiohw_set_volume(int vol_l, int vol_r) 137void audiohw_set_volume(int vol_l, int vol_r)
138{ 138{
139 int dac_l, amp_l, dac_r, amp_r; 139 int dac_l, amp_l, dac_r, amp_r;
140
141 vol_l = vol_tenthdb2hw(vol_l);
142 vol_r = vol_tenthdb2hw(vol_r);
143
140 get_volume_params(vol_l, &dac_l, &amp_l); 144 get_volume_params(vol_l, &dac_l, &amp_l);
141 get_volume_params(vol_r, &dac_r, &amp_r); 145 get_volume_params(vol_r, &dac_r, &amp_r);
142 146
diff --git a/firmware/drivers/audio/wm8975.c b/firmware/drivers/audio/wm8975.c
index 4905445aea..931dae9c6f 100644
--- a/firmware/drivers/audio/wm8975.c
+++ b/firmware/drivers/audio/wm8975.c
@@ -79,7 +79,7 @@ static int vol_tenthdb2hw(int db)
79 /* 0110000 == -73dB (0x30 */ 79 /* 0110000 == -73dB (0x30 */
80 /* 0101111..0000000 == mute (0x2f) */ 80 /* 0101111..0000000 == mute (0x2f) */
81 81
82 if (db < VOLUME_MIN) { 82 if (db <= -740) {
83 return 0x0; 83 return 0x0;
84 } else { 84 } else {
85 return((db/10)+73+0x30); 85 return((db/10)+73+0x30);
diff --git a/firmware/drivers/audio/wm8978.c b/firmware/drivers/audio/wm8978.c
index 3a86ef204e..69ae608e5d 100644
--- a/firmware/drivers/audio/wm8978.c
+++ b/firmware/drivers/audio/wm8978.c
@@ -155,20 +155,17 @@ static void wmc_write_masked(unsigned int reg, unsigned int bits,
155 * (000000...111111) */ 155 * (000000...111111) */
156static int vol_tenthdb2hw(int db) 156static int vol_tenthdb2hw(int db)
157{ 157{
158 /* -90dB to +6dB 1dB steps (96 levels) 7bits */ 158 /* att DAC AMP result
159 /* 1100000 == +6dB (0x60,96) */ 159 +6dB 0 +6 96
160 /* 1101010 == 0dB (0x5a,90) */ 160 0dB 0 0 90
161 /* 1000001 == -57dB (0x21,33,DAC) */ 161 -57dB 0 -57 33
162 /* 0000001 == -89dB (0x01,01) */ 162 -58dB -1 -57 32
163 /* 0000000 == -90dB (0x00,00,Mute) */ 163 -89dB -32 -57 1
164 if (db < VOLUME_MIN) 164 -90dB -oo -oo 0 */
165 { 165 if (db <= -900)
166 return 0x0; 166 return 0x0;
167 }
168 else 167 else
169 { 168 return db / 10 - -90;
170 return (db - VOLUME_MIN) / 10;
171 }
172} 169}
173 170
174void audiohw_preinit(void) 171void audiohw_preinit(void)
diff --git a/firmware/drivers/audio/wm8985.c b/firmware/drivers/audio/wm8985.c
index 2d49e706c8..fab7354685 100644
--- a/firmware/drivers/audio/wm8985.c
+++ b/firmware/drivers/audio/wm8985.c
@@ -104,10 +104,10 @@ static int vol_tenthdb2hw(int db)
104 -89dB -32 -57 1 104 -89dB -32 -57 1
105 -90dB -oo -oo 0 */ 105 -90dB -oo -oo 0 */
106 106
107 if (db < VOLUME_MIN) { 107 if (db <= -900) {
108 return 0; 108 return 0;
109 } else { 109 } else {
110 return (db-VOLUME_MIN)/10 + 1; 110 return db / 10 - -90;
111 } 111 }
112} 112}
113 113