From f5a5b946867677de76c405ee72e2ea47e36e4c83 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Fri, 5 Apr 2013 04:36:05 -0400 Subject: 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 Tested-by: Michael Sevakis --- firmware/target/mips/ingenic_jz47xx/codec-jz4740.c | 27 ++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'firmware/target') 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 @@ #include "sound.h" #include "jz4740.h" #include "system.h" +#include "pcm_sw_volume.h" /* TODO */ const struct sound_settings_info audiohw_settings[] = { #ifdef HAVE_SW_VOLUME_CONTROL - [SOUND_VOLUME] = {"dB", 0, 1, SW_VOLUME_MIN, 6, 0}, + [SOUND_VOLUME] = {"dB", 0, 1, -74, 6, -25}, #else [SOUND_VOLUME] = {"dB", 0, 1, 0, 6, 0}, #endif @@ -293,16 +294,24 @@ void audiohw_init(void) i2s_codec_init(); } -void audiohw_set_volume(int v) +void audiohw_set_master_vol(int vol_l, int vol_r) { - if(v >= 0) - { - /* 0 <= v <= 60 */ - unsigned int codec_volume = ICDC_CDCCR2_HPVOL(v / 20); +#ifdef HAVE_SW_VOLUME_CONTROL + /* SW volume for <= 1.0 gain, HW at unity, < VOLUME_MIN == MUTE */ + int sw_volume_l = vol_l < VOLUME_MIN ? PCM_MUTE_LEVEL : MIN(vol_l, 0); + int sw_volume_r = vol_r < VOLUME_MIN ? PCM_MUTE_LEVEL : MIN(vol_r, 0); + pcm_set_master_volume(sw_volume_l, sw_volume_r); +#endif /* HAVE_SW_VOLUME_CONTROL */ - if((REG_ICDC_CDCCR2 & ICDC_CDCCR2_HPVOL(0x3)) != codec_volume) - REG_ICDC_CDCCR2 = (REG_ICDC_CDCCR2 & ~ICDC_CDCCR2_HPVOL(0x3)) | codec_volume; - } + /* NOTE: the channel being cut if balance is not equal will need + adjusting downward so maintain proportion if using volume boost */ + + /* HW volume for > 1.0 gain */ + int v = MAX(vol_l, vol_r); + unsigned int hw_volume = v > 0 ? ICDC_CDCCR2_HPVOL(v / 20) : 0; + + if((REG_ICDC_CDCCR2 & ICDC_CDCCR2_HPVOL(0x3)) != hw_volume) + REG_ICDC_CDCCR2 = (REG_ICDC_CDCCR2 & ~ICDC_CDCCR2_HPVOL(0x3)) | hw_volume; } void audiohw_set_frequency(int freq) -- cgit v1.2.3