diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2013-04-05 04:36:05 -0400 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2013-04-11 22:55:16 +0200 |
commit | f5a5b946867677de76c405ee72e2ea47e36e4c83 (patch) | |
tree | 8fb97a35059a16681b726973b4a5e13d41f96a35 /firmware/target/mips/ingenic_jz47xx/codec-jz4740.c | |
parent | a9049a79d706dba61837ad02c7d7e3475cb6c193 (diff) | |
download | rockbox-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/target/mips/ingenic_jz47xx/codec-jz4740.c')
-rw-r--r-- | firmware/target/mips/ingenic_jz47xx/codec-jz4740.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/firmware/target/mips/ingenic_jz47xx/codec-jz4740.c b/firmware/target/mips/ingenic_jz47xx/codec-jz4740.c index ab9efc91b0..065433e12a 100644 --- a/firmware/target/mips/ingenic_jz47xx/codec-jz4740.c +++ b/firmware/target/mips/ingenic_jz47xx/codec-jz4740.c | |||
@@ -24,11 +24,12 @@ | |||
24 | #include "sound.h" | 24 | #include "sound.h" |
25 | #include "jz4740.h" | 25 | #include "jz4740.h" |
26 | #include "system.h" | 26 | #include "system.h" |
27 | #include "pcm_sw_volume.h" | ||
27 | 28 | ||
28 | /* TODO */ | 29 | /* TODO */ |
29 | const struct sound_settings_info audiohw_settings[] = { | 30 | const struct sound_settings_info audiohw_settings[] = { |
30 | #ifdef HAVE_SW_VOLUME_CONTROL | 31 | #ifdef HAVE_SW_VOLUME_CONTROL |
31 | [SOUND_VOLUME] = {"dB", 0, 1, SW_VOLUME_MIN, 6, 0}, | 32 | [SOUND_VOLUME] = {"dB", 0, 1, -74, 6, -25}, |
32 | #else | 33 | #else |
33 | [SOUND_VOLUME] = {"dB", 0, 1, 0, 6, 0}, | 34 | [SOUND_VOLUME] = {"dB", 0, 1, 0, 6, 0}, |
34 | #endif | 35 | #endif |
@@ -293,16 +294,24 @@ void audiohw_init(void) | |||
293 | i2s_codec_init(); | 294 | i2s_codec_init(); |
294 | } | 295 | } |
295 | 296 | ||
296 | void audiohw_set_volume(int v) | 297 | void audiohw_set_master_vol(int vol_l, int vol_r) |
297 | { | 298 | { |
298 | if(v >= 0) | 299 | #ifdef HAVE_SW_VOLUME_CONTROL |
299 | { | 300 | /* SW volume for <= 1.0 gain, HW at unity, < VOLUME_MIN == MUTE */ |
300 | /* 0 <= v <= 60 */ | 301 | int sw_volume_l = vol_l < VOLUME_MIN ? PCM_MUTE_LEVEL : MIN(vol_l, 0); |
301 | unsigned int codec_volume = ICDC_CDCCR2_HPVOL(v / 20); | 302 | int sw_volume_r = vol_r < VOLUME_MIN ? PCM_MUTE_LEVEL : MIN(vol_r, 0); |
303 | pcm_set_master_volume(sw_volume_l, sw_volume_r); | ||
304 | #endif /* HAVE_SW_VOLUME_CONTROL */ | ||
302 | 305 | ||
303 | if((REG_ICDC_CDCCR2 & ICDC_CDCCR2_HPVOL(0x3)) != codec_volume) | 306 | /* NOTE: the channel being cut if balance is not equal will need |
304 | REG_ICDC_CDCCR2 = (REG_ICDC_CDCCR2 & ~ICDC_CDCCR2_HPVOL(0x3)) | codec_volume; | 307 | adjusting downward so maintain proportion if using volume boost */ |
305 | } | 308 | |
309 | /* HW volume for > 1.0 gain */ | ||
310 | int v = MAX(vol_l, vol_r); | ||
311 | unsigned int hw_volume = v > 0 ? ICDC_CDCCR2_HPVOL(v / 20) : 0; | ||
312 | |||
313 | if((REG_ICDC_CDCCR2 & ICDC_CDCCR2_HPVOL(0x3)) != hw_volume) | ||
314 | REG_ICDC_CDCCR2 = (REG_ICDC_CDCCR2 & ~ICDC_CDCCR2_HPVOL(0x3)) | hw_volume; | ||
306 | } | 315 | } |
307 | 316 | ||
308 | void audiohw_set_frequency(int freq) | 317 | void audiohw_set_frequency(int freq) |