Index: apps/eq_menu.c =================================================================== RCS file: /cvsroot/rockbox/apps/eq_menu.c,v retrieving revision 1.20 diff -u -b -r1.20 eq_menu.c --- apps/eq_menu.c 7 Aug 2006 21:24:19 -0000 1.20 +++ apps/eq_menu.c 11 Aug 2006 00:03:13 -0000 @@ -45,7 +45,8 @@ #include "screen_access.h" #include "keyboard.h" #include "gui/scrollbar.h" - +#include "wm8758.h" +#include "debug.h" /* Key definitions */ #if (CONFIG_KEYPAD == IRIVER_H100_PAD || \ CONFIG_KEYPAD == IRIVER_H300_PAD) @@ -160,19 +161,108 @@ { int i; - bool result = set_bool(str(LANG_EQUALIZER_ENABLED), - &global_settings.eq_enabled); + struct opt_items names[] = { + {(unsigned char*)"Software", 0}, + {(unsigned char*)"Hardware", 0}, + {(unsigned char*)"Disabled", 0} + }; + int val=2; /*Disabled by default*/ + if (global_settings.eq_enabled && !global_settings.eq_hw_enabled) + val=0; + else if (!global_settings.eq_enabled && global_settings.eq_hw_enabled) + val=1; + else if (!global_settings.eq_enabled && !global_settings.eq_hw_enabled) + val=2; + + + bool res=set_option("EQ Enable", &val, INT, names, 3, NULL); + + if (val==0) { + global_settings.eq_enabled=true; + global_settings.eq_hw_enabled=false; + + wm_codec_set_eq_band_1(0, 0x0d); + wm_codec_set_eq_band_2(0, 0x0d, 0); + wm_codec_set_eq_band_3(0, 0x0d, 0); + wm_codec_set_eq_band_4(0, 0x0d, 0); + wm_codec_set_eq_band_5(0, 0x0d); + } + else if (val==1) { + global_settings.eq_enabled=false; + global_settings.eq_hw_enabled=true; + int dist=0; + int gain=0; + unsigned int smallest=0xFFFFFFFF; + for (i=0;i<4;i++) { + dist=abs(WM8758_Band_1_Freqs[i]-global_settings.eq_band0_cutoff); + if (dist < smallest) { + gain=12-(global_settings.eq_band0_gain/20); + wm_codec_set_eq_band_1(i, gain); + smallest=dist; + } + } + smallest=0xFFFFFFFF; + for (i=0;i<4;i++) { + dist=abs(WM8758_Band_2_Freqs[i]-global_settings.eq_band1_cutoff); + if (dist < smallest) { + gain=12-(global_settings.eq_band1_gain/20); + wm_codec_set_eq_band_2(i, gain, 1); + smallest=dist; + } + } + smallest=0xFFFFFFFF; + for (i=0;i<4;i++) { + dist=abs(WM8758_Band_3_Freqs[i]-global_settings.eq_band2_cutoff); + if (dist < smallest) + { + gain=12-(global_settings.eq_band2_gain/20); + wm_codec_set_eq_band_3(i, gain, 1); + smallest=dist; + } + } + smallest=0xFFFFFFFF; + for (i=0;i<4;i++) { + dist=abs(WM8758_Band_4_Freqs[i]-global_settings.eq_band3_cutoff); + if (dist < smallest) { + gain=12-(global_settings.eq_band3_gain/20); + wm_codec_set_eq_band_4(i, gain, 1); + smallest=dist; + } + } + smallest=0xFFFFFFFF; + for (i=0;i<4;i++) { + dist=abs(WM8758_Band_5_Freqs[i]-global_settings.eq_band4_cutoff); + if (dist < smallest) { + gain=12-(global_settings.eq_band4_gain/20); + wm_codec_set_eq_band_5(i, gain); + smallest=dist; + } + } - dsp_set_eq(global_settings.eq_enabled); - dsp_set_eq_precut(global_settings.eq_precut); + } + else if (val == 2) { + global_settings.eq_enabled=false; + global_settings.eq_hw_enabled=false; + wm_codec_set_eq_band_1(0, 0x0d); + wm_codec_set_eq_band_2(0, 0x0d, 0); + wm_codec_set_eq_band_3(0, 0x0d, 0); + wm_codec_set_eq_band_4(0, 0x0d, 0); + wm_codec_set_eq_band_5(0, 0x0d); + } + if (!global_settings.eq_hw_enabled) { + dsp_set_eq(global_settings.eq_enabled); + dsp_set_eq_precut(global_settings.eq_precut); /* Update all bands */ for(i = 0; i < 5; i++) { dsp_set_eq_coefs(i); } - - return result; + } + else { + dsp_set_eq(global_settings.eq_enabled); + } + return res; } static bool eq_precut(void) Index: apps/settings.c =================================================================== RCS file: /cvsroot/rockbox/apps/settings.c,v retrieving revision 1.398 diff -u -b -r1.398 settings.c --- apps/settings.c 31 Jul 2006 19:13:20 -0000 1.398 +++ apps/settings.c 11 Aug 2006 00:03:30 -0000 @@ -538,6 +538,7 @@ /* equalizer */ {1, S_O(eq_enabled), false, "eq enabled", off_on }, +/* (1, S_O(eq_hw_enabled), false, "eq_hw_enabled", off_on},*/ {8, S_O(eq_precut), 0, "eq precut", NULL }, /* 0..32768 Hz */ {15, S_O(eq_band0_cutoff), 60, "eq band 0 cutoff", NULL }, Index: apps/settings.h =================================================================== RCS file: /cvsroot/rockbox/apps/settings.h,v retrieving revision 1.228 diff -u -b -r1.228 settings.h --- apps/settings.h 3 Aug 2006 20:17:14 -0000 1.228 +++ apps/settings.h 11 Aug 2006 00:03:33 -0000 @@ -483,6 +483,7 @@ #if CONFIG_CODEC == SWCODEC bool eq_enabled; /* Enable equalizer */ + bool eq_hw_enabled; unsigned int eq_precut; /* dB */ /* Order is important here, must be cutoff, q, then gain for each band. Index: firmware/drivers/wm8758.c =================================================================== RCS file: /cvsroot/rockbox/firmware/drivers/wm8758.c,v retrieving revision 1.8 diff -u -b -r1.8 wm8758.c --- firmware/drivers/wm8758.c 27 Mar 2006 14:46:15 -0000 1.8 +++ firmware/drivers/wm8758.c 11 Aug 2006 00:03:54 -0000 @@ -41,6 +41,9 @@ #include "wm8758.h" #include "pcf50605.h" +unsigned int eq0; + + void wmcodec_reset(void); #define IPOD_PCM_LEVEL 0x65 /* -6dB */ @@ -137,6 +140,8 @@ wm8758_write(LOUTMIX,0x1); /* Enable mixer */ wm8758_write(ROUTMIX,0x1); /* Enable mixer */ wmcodec_mute(0); + /* these are the defaults the hardware will be set to. Track these since we will be modifying bits based on user input*/ + eq0=0x12C; } else { wmcodec_mute(1); } @@ -272,3 +277,82 @@ (void)enable; } +/* 1 is apply eq/3d effect to output, 0 is input*/ +void wm_codec_set_eqmode(bool in) +{ + eq0&=0x0FF; + if (in) + eq0|=0x100; + wm8758_write(EQ0, eq0); +} +/* frequency valid values are 0, 1, 2, and 3 corresponding to center + frequencies of 80, 105, 135, 175. + + Gain is all done the same as + +0x00 00000 +12db +0x01 00001 +11db +0x02 00010 +10db +0x03 00011 +9db +0x04 00100 +8db +0x05 00101 +7db +0x06 00110 +6db +0x07 00111 +5db +0x08 01000 +4db +0x09 01001 +3db +0x0a 01010 +2db +0x0b 01011 +1db +0x0d 01100 +0db +0x0f 01101 -1db +0x18 11000 -12db +*/ +void wm_codec_set_eq_band_1(unsigned char freq, unsigned char gain) +{ + eq0&=0x100; //save input or output, clear the rest + eq0|=(freq<<5); //tack on the new frequency + eq0|=(gain); //tack on the new gain + wm8758_write(EQ0, eq0); //set it +} +/* frequency valid values are 0, 1, 2, and 3 corresponding to center + frequencies of 230, 300, 385, and 500. +*/ +void wm_codec_set_eq_band_2(unsigned char freq, unsigned char gain, unsigned char bandwidth) +{ + unsigned int eq1=0; + eq1|=(bandwidth<<8); + eq1|=(freq<<5); + eq1|=gain; + wm8758_write(EQ1, eq1); +} +/* frequency valid values are 0, 1, 2, and 3 corresponding to center + frequencies 650, 850, 1.1, 1.4 +*/ +void wm_codec_set_eq_band_3(unsigned char freq, unsigned char gain, unsigned char bandwidth) +{ + unsigned int eq2=0; + eq2|=(bandwidth<<8); + eq2|=(freq<<5); + eq2|=gain; + wm8758_write(EQ2, eq2); +} +/* frequency valid values are 0, 1, 2, and 3 corresponding to center + frequencies 1.8, 2.4, 3.2, 4.1 +*/ +void wm_codec_set_eq_band_4(unsigned char freq, unsigned char gain, unsigned char bandwidth) +{ + unsigned int eq3=0; + eq3|=(bandwidth<<8); + eq3|=(freq<<5); + eq3|=gain; + wm8758_write(EQ3, eq3); +} +/* frequency valid values are 0, 1, 2, and 3 corresponding to center + 5.3, 6.9, 9, 11.7 +*/ +void wm_codec_set_eq_band_5(unsigned char freq, unsigned char gain) +{ + unsigned int eq4=0; + eq4|=(freq<<5); + eq4|=gain; + wm8758_write(EQ4, eq4); +} Index: firmware/export/wm8758.h =================================================================== RCS file: /cvsroot/rockbox/firmware/export/wm8758.h,v retrieving revision 1.2 diff -u -b -r1.2 wm8758.h --- firmware/export/wm8758.h 22 Mar 2006 13:04:49 -0000 1.2 +++ firmware/export/wm8758.h 11 Aug 2006 00:03:55 -0000 @@ -60,6 +60,12 @@ #define PLLK2 0x26 #define PLLK3 0x27 +#define EQ0 0x12 +#define EQ1 0x13 +#define EQ2 0x14 +#define EQ3 0x15 +#define EQ4 0x16 + /* Register settings for the supported samplerates: */ #define WM8758_8000HZ 0x4d #define WM8758_12000HZ 0x61 @@ -72,4 +78,15 @@ #define WM8758_88200HZ 0x7f #define WM8758_96000HZ 0x5d +void wm_codec_set_eq_band_1(unsigned char freq, unsigned char gain); +void wm_codec_set_eq_band_2(unsigned char freq, unsigned char gain, unsigned char bandwidth); +void wm_codec_set_eq_band_3(unsigned char freq, unsigned char gain, unsigned char bandwidth); +void wm_codec_set_eq_band_4(unsigned char freq, unsigned char gain, unsigned char bandwidth); +void wm_codec_set_eq_band_5(unsigned char freq, unsigned char gain); + +static const int WM8758_Band_1_Freqs[]={80, 105, 135, 175}; +static const int WM8758_Band_2_Freqs[]={230, 300, 385, 500}; +static const int WM8758_Band_3_Freqs[]={650, 850, 1.1, 1.4}; +static const int WM8758_Band_4_Freqs[]={1.8, 2.4, 3.2, 4.1}; +static const int WM8758_Band_5_Freqs[]={5.3, 6.9, 9, 11.7}; #endif /* _WM8758_H */