From f0e1cf038f6265fe71d5c3658e553b08c0eec163 Mon Sep 17 00:00:00 2001 From: Andree Buschmann Date: Sun, 30 May 2010 18:29:04 +0000 Subject: [PATCH] Submit FS#11240 by Raphael Jakse. Allows to reduce volume on WM8985 to -89 dB (e.g. used for Cowon D2). Below -57 dB the line out is affected. The manual is updated accordingly. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26413 a1c6a512-1295-4272-9138-f99709370657 --- docs/CREDITS | 1 + firmware/drivers/audio/wm8985.c | 75 ++++++++++++++++----- firmware/export/wm8985.h | 2 +- manual/appendix/config_file_options.tex | 2 +- manual/configure_rockbox/sound_settings.tex | 3 +- 5 files changed, 63 insertions(+), 20 deletions(-) diff --git a/docs/CREDITS b/docs/CREDITS index dde1f751e5..f7b0c5bc20 100644 --- a/docs/CREDITS +++ b/docs/CREDITS @@ -542,6 +542,7 @@ Luca Leonardo Scorcia Gerhard Zintel Adrián Cereto Massagué Chris Savery +Raphaël Jakse The libmad team The wavpack team diff --git a/firmware/drivers/audio/wm8985.c b/firmware/drivers/audio/wm8985.c index da08b44402..a76e20e57b 100644 --- a/firmware/drivers/audio/wm8985.c +++ b/firmware/drivers/audio/wm8985.c @@ -42,6 +42,7 @@ #define ADCCTL 0x0e #define LADCVOL 0x0f #define RADCVOL 0x10 +#define RDACVOL_DACVU 0x100 #define EQ1 0x12 #define EQ2 0x13 @@ -88,7 +89,7 @@ #define BIASCTL 0x3d const struct sound_settings_info audiohw_settings[] = { - [SOUND_VOLUME] = {"dB", 0, 1, -58, 6, -25}, + [SOUND_VOLUME] = {"dB", 0, 1, -90, 6, -25}, [SOUND_BASS] = {"dB", 0, 1, -12, 12, 0}, [SOUND_TREBLE] = {"dB", 0, 1, -12, 12, 0}, [SOUND_BALANCE] = {"%", 0, 1,-100, 100, 0}, @@ -111,21 +112,48 @@ const struct sound_settings_info audiohw_settings[] = { unsigned int eq1_reg; unsigned int eq5_reg; -/* convert tenth of dB volume (-57..6) to master volume register value */ +/* convert tenth of dB volume (-89..6) to master volume register value */ int tenthdb2master(int db) { - /* +6 to -57dB in 1dB steps == 64 levels = 6 bits */ - /* 0111111 == +6dB (0x3f) = 63) */ - /* 0111001 == 0dB (0x39) = 57) */ - /* 0000001 == -56dB (0x01) = */ - /* 0000000 == -57dB (0x00) */ - - /* 1000000 == Mute (0x40) */ + /* Might have no sense, taken from wm8758.c : + att DAC AMP result + +6dB 0 +6 96 + 0dB 0 0 90 + -57dB 0 -57 33 + -58dB -1 -57 32 + -89dB -32 -57 1 + -90dB -oo -oo 0 */ if (db < VOLUME_MIN) { - return 0x40; + return 0; } else { - return((db/10)+57); + return (db-VOLUME_MIN)/10 + 1; + } +} + + /* helper function coming from wm8758.c that calculates the register setting for amplifier and + DAC volume out of the input from tenthdb2master() */ +static void get_volume_params(int db, int *dac, int *amp) +{ + /* should never happen, set max volume for amp and dac */ + if (db > 96) { + *dac = 255; + *amp = 63; + } + /* set dac to max and set volume for amp (better snr) */ + else if (db > 32) { + *dac = 255; + *amp = (db-90)+57; + } + /* set amp to min and reduce dac output */ + else if (db > 0) { + *dac = (db-33)*2 + 255; + *amp = 0; + } + /* mute all */ + else { + *dac = 0x00; + *amp = 0x40; } } @@ -190,16 +218,29 @@ void audiohw_postinit(void) void audiohw_set_headphone_vol(int vol_l, int vol_r) { - /* OUT1 */ - wmcodec_write(LOUT1VOL, 0x080 | vol_l); - wmcodec_write(ROUT1VOL, 0x180 | vol_r); + int dac_l, amp_l, dac_r, amp_r; + get_volume_params(vol_l, &dac_l, &_l); + get_volume_params(vol_r, &dac_r, &_r); + + /* set DAC + Important: DAC is global and will also affect lineout */ + wmcodec_write(LDACVOL, dac_l); + wmcodec_write(RDACVOL, dac_r | RDACVOL_DACVU); + + /* set headphone amp OUT1 */ + wmcodec_write(LOUT1VOL, amp_l | 0x080); + wmcodec_write(ROUT1VOL, amp_r | 0x180); } void audiohw_set_lineout_vol(int vol_l, int vol_r) { - /* OUT2 */ - wmcodec_write(LOUT2VOL, vol_l); - wmcodec_write(ROUT2VOL, 0x100 | vol_r); + int dac_l, amp_l, dac_r, amp_r; + get_volume_params(vol_l, &dac_l, &_l); + get_volume_params(vol_r, &dac_r, &_r); + + /* set lineout amp OUT2 */ + wmcodec_write(LOUT2VOL, amp_l); + wmcodec_write(ROUT2VOL, amp_r | 0x100); } void audiohw_set_aux_vol(int vol_l, int vol_r) diff --git a/firmware/export/wm8985.h b/firmware/export/wm8985.h index c6b8e3825f..4538b5edc5 100644 --- a/firmware/export/wm8985.h +++ b/firmware/export/wm8985.h @@ -23,7 +23,7 @@ #define _WM8985_H /* volume/balance/treble/bass interdependency */ -#define VOLUME_MIN -570 +#define VOLUME_MIN -890 #define VOLUME_MAX 60 #ifdef COWON_D2 diff --git a/manual/appendix/config_file_options.tex b/manual/appendix/config_file_options.tex index e70a020e26..c4c1dfa223 100644 --- a/manual/appendix/config_file_options.tex +++ b/manual/appendix/config_file_options.tex @@ -16,7 +16,7 @@ \opt{h100,h300}{-84 to 0}% \opt{ipodnano}{-72 to +6}% \opt{ipodnano2g}{-74 to +6}% - \opt{ipodvideo}{-89 to +6}% + \opt{ipodvideo,cowond2}{-89 to +6}% \opt{x5}{-73 to +6} \opt{e200,e200v2}{-74 to +6} \opt{ipodcolor,vibe500}{-74 to +6}% diff --git a/manual/configure_rockbox/sound_settings.tex b/manual/configure_rockbox/sound_settings.tex index b239efbb1e..7d13c2fe3a 100644 --- a/manual/configure_rockbox/sound_settings.tex +++ b/manual/configure_rockbox/sound_settings.tex @@ -22,13 +22,14 @@ change to customise your listening experience. \opt{h100,h300}{minimum of -84~dB to a maximum of 0~dB.}% \opt{x5,m5,ipod3g,ipod4g,gigabeatf,mrobe100}{minimum of -73~dB to a maximum of +6~dB.}% \opt{ipodnano}{minimum of -72~dB to a maximum of +6~dB.}% - \opt{ipodvideo}{minimum of -89~dB to a maximum of +6~dB.}% + \opt{ipodvideo,cowond2}{minimum of -89~dB to a maximum of +6~dB.}% \opt{ipodnano2g,ipodcolor,ipod1g2g,h10,h10_5gb,sansa,sansaAMS}{minimum of -74~dB to a maximum of +6~dB.}% \opt{gigabeats}{minimum of -90~dB to a maximum of +6~dB.}% \opt{gigabeatf,vibe500}{minimum of -74~dB to a maximum of +6~dB.}% \opt{ipodvideo}{\\Remark: Lowering the volume below -57~dB will also affect the line-out and the recording gain.} + \opt{cowond2}{\\Remark: Lowering the volume below -57~dB will also affect the line-out.} \section{Bass} This setting emphasises