summaryrefslogtreecommitdiff
path: root/firmware/sound.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2013-04-05 04:36:05 -0400
committerMichael Sevakis <jethead71@rockbox.org>2013-04-11 22:55:16 +0200
commitf5a5b946867677de76c405ee72e2ea47e36e4c83 (patch)
tree8fb97a35059a16681b726973b4a5e13d41f96a35 /firmware/sound.c
parenta9049a79d706dba61837ad02c7d7e3475cb6c193 (diff)
downloadrockbox-f5a5b946867677de76c405ee72e2ea47e36e4c83.tar.gz
rockbox-f5a5b946867677de76c405ee72e2ea47e36e4c83.zip
Implement universal in-PCM-driver software volume control.
Implements double-buffered volume, balance and prescaling control in the main PCM driver when HAVE_SW_VOLUME_CONTROL is defined ensuring that all PCM is volume controlled and level changes are low in latency. Supports -73 to +6 dB using a 15-bit factor so that no large-integer math is needed. Low-level hardware drivers do not have to implement it themselves but parameters can be changed (currently defined in pcm-internal.h) to work best with a particular SoC or to provide different volume ranges. Volume and prescale calls should be made in the codec driver. It should appear as a normal hardware interface. PCM volume calls expect .1 dB units. Change-Id: Idf6316a64ef4fb8abcede10707e1e6c6d01d57db Reviewed-on: http://gerrit.rockbox.org/423 Reviewed-by: Michael Sevakis <jethead71@rockbox.org> Tested-by: Michael Sevakis <jethead71@rockbox.org>
Diffstat (limited to 'firmware/sound.c')
-rw-r--r--firmware/sound.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/firmware/sound.c b/firmware/sound.c
index e442e87f8c..2ffef0e72b 100644
--- a/firmware/sound.c
+++ b/firmware/sound.c
@@ -26,6 +26,9 @@
26#include "logf.h" 26#include "logf.h"
27#include "system.h" 27#include "system.h"
28#include "i2c.h" 28#include "i2c.h"
29#ifdef HAVE_SW_VOLUME_CONTROL
30#include "pcm_sw_volume.h"
31#endif /* HAVE_SW_VOLUME_CONTROL */
29 32
30/* TODO 33/* TODO
31 * find a nice way to handle 1.5db steps -> see wm8751 ifdef in sound_set_bass/treble 34 * find a nice way to handle 1.5db steps -> see wm8751 ifdef in sound_set_bass/treble
@@ -215,7 +218,7 @@ static void set_prescaled_volume(void)
215 dsp_callback(DSP_CALLBACK_SET_PRESCALE, prescale); 218 dsp_callback(DSP_CALLBACK_SET_PRESCALE, prescale);
216#endif 219#endif
217 220
218 if (current_volume == VOLUME_MIN) 221 if (current_volume <= VOLUME_MIN)
219 prescale = 0; /* Make sure the chip gets muted at VOLUME_MIN */ 222 prescale = 0; /* Make sure the chip gets muted at VOLUME_MIN */
220 223
221 l = r = current_volume + prescale; 224 l = r = current_volume + prescale;
@@ -231,13 +234,11 @@ static void set_prescaled_volume(void)
231 r += ((r - (VOLUME_MIN - ONE_DB)) * current_balance) / VOLUME_RANGE; 234 r += ((r - (VOLUME_MIN - ONE_DB)) * current_balance) / VOLUME_RANGE;
232 } 235 }
233 236
234#ifdef HAVE_SW_VOLUME_CONTROL
235 dsp_callback(DSP_CALLBACK_SET_SW_VOLUME, 0);
236#endif
237
238/* ypr0 with sdl has separate volume controls */ 237/* ypr0 with sdl has separate volume controls */
239#if !defined(HAVE_SDL_AUDIO) || defined(SAMSUNG_YPR0) 238#if !defined(HAVE_SDL_AUDIO) || defined(SAMSUNG_YPR0)
240#if CONFIG_CODEC == MAS3507D 239#if defined(HAVE_SW_VOLUME_CONTROL) || defined(HAVE_JZ4740_CODEC)
240 audiohw_set_master_vol(l, r);
241#elif CONFIG_CODEC == MAS3507D
241 dac_volume(tenthdb2reg(l), tenthdb2reg(r), false); 242 dac_volume(tenthdb2reg(l), tenthdb2reg(r), false);
242#elif defined(HAVE_UDA1380) || defined(HAVE_WM8975) || defined(HAVE_WM8758) \ 243#elif defined(HAVE_UDA1380) || defined(HAVE_WM8975) || defined(HAVE_WM8758) \
243 || defined(HAVE_WM8711) || defined(HAVE_WM8721) || defined(HAVE_WM8731) \ 244 || defined(HAVE_WM8711) || defined(HAVE_WM8721) || defined(HAVE_WM8731) \
@@ -253,7 +254,7 @@ static void set_prescaled_volume(void)
253 254
254#elif defined(HAVE_TLV320) || defined(HAVE_WM8978) || defined(HAVE_WM8985) || defined(HAVE_IMX233_CODEC) || defined(HAVE_AIC3X) 255#elif defined(HAVE_TLV320) || defined(HAVE_WM8978) || defined(HAVE_WM8985) || defined(HAVE_IMX233_CODEC) || defined(HAVE_AIC3X)
255 audiohw_set_headphone_vol(tenthdb2master(l), tenthdb2master(r)); 256 audiohw_set_headphone_vol(tenthdb2master(l), tenthdb2master(r));
256#elif defined(HAVE_JZ4740_CODEC) || defined(HAVE_SDL_AUDIO) || defined(ANDROID) 257#elif defined(HAVE_SDL_AUDIO) || defined(ANDROID)
257 audiohw_set_volume(current_volume); 258 audiohw_set_volume(current_volume);
258#endif 259#endif
259#else /* HAVE_SDL_AUDIO */ 260#else /* HAVE_SDL_AUDIO */