Commit 406b35c8 authored by alex@thinkpad's avatar alex@thinkpad
Browse files

Merged config_var_refactor into lua_fix

--HG--
branch : lua_fix
......@@ -30,11 +30,11 @@
#include "audio-common.c"
#include "boot-hack.h"
static CONFIG_INT( "audio.dgain.l", dgain_l, 0 );
static CONFIG_INT( "audio.dgain.r", dgain_r, 0 );
static CONFIG_INT( "audio.mgain", mgain, 4 );
static CONFIG_INT( "audio.mic-power", mic_power, 1 );
static CONFIG_INT( "audio.o2gain", o2gain, 0 );
static CONFIG_INT_EX( "audio.dgain.l", dgain_l, 0, dgain_on_change );
static CONFIG_INT_EX( "audio.dgain.r", dgain_r, 0, dgain_on_change );
static CONFIG_INT_EX( "audio.mgain", mgain, 4, mgain_on_change );
static CONFIG_INT_EX( "audio.mic-power", mic_power, 1, mic_power_on_change );
static CONFIG_INT ( "audio.o2gain", o2gain, 0 );
int audio_meters_are_drawn()
{
......@@ -353,70 +353,71 @@ audio_gain_to_cmd(
}
static void
audio_3bit_toggle( void * priv, int delta )
static CONFIG_VAR_CHANGE_FUNC(mgain_on_change)
{
unsigned * ptr = priv;
*ptr = (*ptr + delta) & 0x3;
#ifdef FEATURE_ANALOG_GAIN
#ifdef CONFIG_500D
*(var->value) = MOD(new_value, 10);
#else
*(var->value) = new_value & 0x7;
#endif
audio_configure( 1 );
return 1;
#else
return 0;
#endif
}
static void
audio_binary_toggle( void * priv, int delta )
static CONFIG_VAR_CHANGE_FUNC(alc_enable_on_change)
{
unsigned * ptr = priv;
*ptr = !*ptr;
#ifdef FEATURE_AGC_TOGGLE
*(var->value) = new_value;
audio_configure( 1 );
return 1;
#else
return 0;
#endif
}
#ifdef FEATURE_ANALOG_GAIN
static void
audio_mgain_toggle( void * priv, int delta )
static CONFIG_VAR_CHANGE_FUNC(input_choice_on_change)
{
unsigned * ptr = priv;
#ifdef CONFIG_500D
*ptr = MOD((*ptr + delta), 10);
#ifdef FEATURE_INPUT_SOURCE
*(var->value) = new_value;
audio_configure( 1 );
return 1;
#else
*ptr = (*ptr + delta) & 0x7;
return 0;
#endif
audio_configure( 1 );
}
#endif
#ifdef FEATURE_DIGITAL_GAIN
static inline void
audio_dgain_toggle_reverse( void * priv, int delta )
static CONFIG_VAR_CHANGE_FUNC(mic_power_on_change)
{
unsigned dgain = *(unsigned*) priv;
if( dgain <= 0 ) {
dgain = 36;
} else {
dgain -= 6;
}
*(unsigned*) priv = dgain;
#ifdef FEATURE_MIC_POWER
*(var->value) = new_value;
audio_configure( 1 );
return 1;
#else
return 0;
#endif
}
static void
audio_dgain_toggle( void * priv, int delta )
static CONFIG_VAR_CHANGE_FUNC(dgain_on_change)
{
if (delta < 0) // will the compiler optimize it? :)
{
audio_dgain_toggle_reverse( priv, delta );
return;
}
unsigned dgain = *(unsigned*) priv;
dgain += 6;
if( dgain > 40 )
dgain = 0;
*(unsigned*) priv = dgain;
#ifdef FEATURE_DIGITAL_GAIN
*(var->value) = COERCE(new_value, 0, 36);
audio_configure( 1 );
return 1;
#else
return 0;
#endif
}
#ifdef FEATURE_DIGITAL_GAIN
static MENU_UPDATE_FUNC(audio_dgain_display)
{
unsigned val = CURRENT_VALUE;
MENU_SET_VALUE("%d dB", val);
MENU_SET_RINFO("(dB)");
if (alc_enable)
MENU_SET_WARNING(MENU_WARN_NOT_WORKING, "AGC is enabled.");
MENU_SET_ENABLED(val);
......@@ -431,15 +432,6 @@ static MENU_UPDATE_FUNC(audio_lovl_display)
}
#endif
#ifdef FEATURE_INPUT_SOURCE
static void
audio_input_toggle( void * priv, int delta )
{
menu_numeric_toggle(priv, delta, 0, 4);
audio_configure( 1 );
}
#endif
#ifdef FEATURE_MIC_POWER
static MENU_UPDATE_FUNC(audio_micpower_display)
{
......@@ -460,7 +452,6 @@ static struct menu_entry audio_menus[] = {
{
.name = "Analog Gain",
.priv = &mgain,
.select = audio_mgain_toggle,
.icon_type = IT_PERCENT_OFF,
#ifdef CONFIG_500D
// should match gains[]
......@@ -486,7 +477,7 @@ static struct menu_entry audio_menus[] = {
.priv = &dgain_l,
.max = 36,
.icon_type = IT_PERCENT_OFF,
.select = audio_dgain_toggle,
.unit = UNIT_DEC,
.update = audio_dgain_display,
.help = "Digital gain (LEFT). Any nonzero value reduces quality.",
},
......@@ -495,7 +486,7 @@ static struct menu_entry audio_menus[] = {
.priv = &dgain_r,
.max = 36,
.icon_type = IT_PERCENT_OFF,
.select = audio_dgain_toggle,
.unit = UNIT_DEC,
.update = audio_dgain_display,
.help = "Digital gain (RIGHT). Any nonzero value reduces quality.",
},
......@@ -503,7 +494,6 @@ static struct menu_entry audio_menus[] = {
{
.name = "AGC",
.priv = &alc_enable,
.select = audio_binary_toggle,
.max = 1,
.help = "Automatic Gain Control - turn it off :)",
},
......@@ -516,7 +506,6 @@ static struct menu_entry audio_menus[] = {
{
.name = "Input source",
.priv = &input_choice,
.select = audio_input_toggle,
.icon_type = IT_DICE,
.max = 4,
.choices = (const char *[]) {"Internal mic", "L:int R:ext", "External stereo", "L:int R:balanced", "Auto int/ext"},
......@@ -530,7 +519,6 @@ static struct menu_entry audio_menus[] = {
.name = "Wind Filter",
.priv = &enable_filters,
.help = "High pass filter for wind noise reduction.",
.select = audio_binary_toggle,
.max = 1,
.depends_on = DEP_SOUND_RECORDING,
},
......@@ -547,7 +535,6 @@ static struct menu_entry audio_menus[] = {
{
.name = "Mic Power",
.priv = &mic_power,
.select = audio_binary_toggle,
.update = audio_micpower_display,
.max = 1,
.help = "Needed for int. and some other mics, but lowers impedance.",
......@@ -575,7 +562,6 @@ static struct menu_entry audio_menus[] = {
{
.name = "Headphone Mon.",
.priv = &audio_monitoring,
.select = audio_monitoring_toggle,
.max = 1,
.help = "Monitoring via A-V jack. Disable if you use a SD display.",
.depends_on = DEP_SOUND_RECORDING,
......@@ -584,7 +570,6 @@ static struct menu_entry audio_menus[] = {
{
.name = "Headphone Volume",
.priv = &lovl,
.select = audio_3bit_toggle,
.update = audio_lovl_display,
.max = 3,
.icon_type = IT_PERCENT_OFF,
......@@ -674,16 +659,16 @@ void volume_up()
{
int mgain_db = mgain_index2gain(mgain);
if (mgain_db < 32)
audio_mgain_toggle(&mgain, 1);
set_config_var_ptr(&mgain, mgain + 1);
#ifdef FEATURE_DIGITAL_GAIN
else
{
if( MAX(dgain_l, dgain_r) + 6 <= 40 )
{
if( MAX(dgain_l, dgain_r) + 6 <= 40 )
{
audio_dgain_toggle(&dgain_l, 1);
audio_dgain_toggle(&dgain_r, 1);
}
set_config_var_ptr(&dgain_l, dgain_l + 6);
set_config_var_ptr(&dgain_r, dgain_r + 6);
}
}
#endif
volume_display();
}
......@@ -694,14 +679,14 @@ void volume_down()
#ifdef FEATURE_DIGITAL_GAIN
if( MIN(dgain_l, dgain_r) > 0 )
{
audio_dgain_toggle(&dgain_l, -1);
audio_dgain_toggle(&dgain_r, -1);
}
else
{
set_config_var_ptr(&dgain_l, dgain_l - 6);
set_config_var_ptr(&dgain_r, dgain_r - 6);
}
else
#endif
if (mgain_db > 0)
audio_mgain_toggle(&mgain, -1);
set_config_var_ptr(&mgain, mgain + 1);
volume_display();
}
#endif
......
......@@ -46,7 +46,9 @@ int audio_thresholds[] = { 0x7fff, 0x7213, 0x65ab, 0x5a9d, 0x50c2, 0x47fa, 0x402
void audio_configure(int force);
static void volume_display();
#ifdef FEATURE_HEADPHONE_MONITORING
static void audio_monitoring_update();
#endif
static void audio_monitoring_display_headphones_connected_or_not();
static void audio_menus_init();
static void audio_input_toggle( void * priv, int delta );
......@@ -79,13 +81,47 @@ static struct gain_struct gain = {
.sem = (void*) 1,
};
static CONFIG_INT( "audio.lovl", lovl, 0 );
static CONFIG_INT( "audio.alc-enable", alc_enable, 0 );
static CONFIG_VAR_CHANGE_FUNC(lovl_on_change)
{
#ifdef FEATURE_HEADPHONE_OUTPUT_VOLUME
*(var->value) = COERCE(new_value, 0, 3);
audio_monitoring_update();
return 1;
#else
return 0;
#endif
}
static CONFIG_VAR_CHANGE_FUNC(audio_monitoring_var_on_change)
{
#ifdef FEATURE_HEADPHONE_MONITORING
*(var->value) = new_value;
audio_monitoring_update();
return 1;
#else
return 0;
#endif
}
static CONFIG_VAR_CHANGE_FUNC(enable_filters_on_change)
{
#ifdef FEATURE_WIND_FILTER
*(var->value) = new_value;
audio_configure( 1 );
return 1;
#else
return 0;
#endif
}
static CONFIG_INT_EX("audio.lovl", lovl, 0, lovl_on_change );
static CONFIG_INT_EX("audio.alc-enable", alc_enable, 0, alc_enable_on_change );
static int loopback = 1;
static CONFIG_INT( "audio.input-choice", input_choice, 4 ); //0=internal; 1=L int, R ext; 2 = stereo ext; 3 = L int, R ext balanced, 4 = auto (0 or 1)
static CONFIG_INT( "audio.filters", enable_filters, 0 ); //disable the HPF, LPF and pre-emphasis filters
static CONFIG_INT_EX("audio.input-choice", input_choice, 4, input_choice_on_change ); //0=internal; 1=L int, R ext; 2 = stereo ext; 3 = L int, R ext balanced, 4 = auto (0 or 1)
static CONFIG_INT_EX("audio.filters", enable_filters, 0, enable_filters_on_change ); //disable the HPF, LPF and pre-emphasis filters
#define cfg_draw_meters 1
static CONFIG_INT("audio.monitoring", audio_monitoring, 1);
static CONFIG_INT_EX("audio.monitoring", audio_monitoring, 1, audio_monitoring_var_on_change );
static int do_draw_meters = 0;
static struct audio_level audio_levels[2];
......@@ -1004,7 +1040,6 @@ void audio_monitoring_display_headphones_connected_or_not()
PROP_INT(PROP_USBRCA_MONITOR, rca_monitor);
#ifdef FEATURE_HEADPHONE_MONITORING
static void audio_monitoring_update();
static void
audio_monitoring_toggle( void * priv, int delta )
......@@ -1072,7 +1107,7 @@ PROP_HANDLER( PROP_MVR_REC_START )
void input_toggle()
{
#ifdef FEATURE_INPUT_SOURCE
audio_input_toggle(&input_choice, 1);
set_config_var_ptr(&input_choice, input_choice + 1);
NotifyBox(2000, "Input: %s", get_audio_input_string());
#endif
}
......
......@@ -31,17 +31,17 @@
#include "audio-common.c"
// Set defaults
CONFIG_INT( "audio.override_audio", cfg_override_audio, 0 );
CONFIG_INT( "audio.analog_gain", cfg_analog_gain, 0 );
CONFIG_INT( "audio.analog_boost", cfg_analog_boost, 0 ); //test
CONFIG_INT( "audio.enable_dc", cfg_filter_dc, 1 );
CONFIG_INT( "audio.enable_hpf2", cfg_filter_hpf2, 0 );
CONFIG_INT( "audio.hpf2config", cfg_filter_hpf2config,7 );
CONFIG_INT_EX( "audio.override_audio", cfg_override_audio, 0, override_audio_on_change );
CONFIG_INT_EX( "audio.analog_gain", cfg_analog_gain, 0, analog_gain_on_change );
CONFIG_INT_EX( "audio.analog_boost", cfg_analog_boost, 0, analog_boost_on_change ); //test
CONFIG_INT_EX( "audio.enable_dc", cfg_filter_dc, 1, audio_filter_on_change );
CONFIG_INT_EX( "audio.enable_hpf2", cfg_filter_hpf2, 0, audio_filter_on_change );
CONFIG_INT_EX( "audio.hpf2config", cfg_filter_hpf2config,7, filter_hpf2config_on_change );
CONFIG_INT( "audio.dgain", cfg_recdgain, 0 );
CONFIG_INT( "audio.dgain.l", dgain_l, 8 );
CONFIG_INT( "audio.dgain.r", dgain_r, 8 );
CONFIG_INT( "audio.effect.mode", cfg_effect_mode, 0 );
CONFIG_INT_EX( "audio.dgain", cfg_recdgain, 0, recdgain_on_change );
CONFIG_INT_EX( "audio.dgain.l", dgain_l, 8, dgain_on_change );
CONFIG_INT_EX( "audio.dgain.r", dgain_r, 8, dgain_on_change );
CONFIG_INT_EX( "audio.effect.mode", cfg_effect_mode, 0, effect_mode_on_change );
int audio_meters_are_drawn()
......@@ -389,13 +389,6 @@ audio_lovl_toggle( void * priv, int delta )
audio_ic_set_lineout_vol();
}
static void
audio_dgain_toggle( void * priv, int delta )
{
menu_numeric_toggle(priv, delta, 0, 15);
audio_ic_set_RecLRbalance();
}
static int
get_dgain_val(int isL){
......@@ -417,105 +410,109 @@ get_dgain_val(int isL){
return 0;
}
static MENU_UPDATE_FUNC(audio_dgain_display)
static CONFIG_VAR_CHANGE_FUNC(override_audio_on_change)
{
int dgainval = get_dgain_val(entry->priv == &dgain_l ? 1 : 0);
MENU_SET_VALUE("%d dB", dgainval);
if (alc_enable)
MENU_SET_WARNING(MENU_WARN_NOT_WORKING, "AGC is enabled.");
*(var->value) = COERCE(new_value, 0, 1);
audio_configure(2);
return 1;
}
static MENU_UPDATE_FUNC(audio_lovl_display)
static CONFIG_VAR_CHANGE_FUNC(analog_gain_on_change)
{
if (!audio_monitoring)
MENU_SET_WARNING(MENU_WARN_NOT_WORKING, "Headphone monitoring is disabled");
*(var->value) = COERCE(new_value, 0, 5);
audio_ic_set_analog_gain();
return 1;
}
static void
audio_alc_toggle( void * priv, int delta )
static CONFIG_VAR_CHANGE_FUNC(analog_boost_on_change)
{
menu_numeric_toggle(priv, 1, 0, 1);
audio_ic_set_agc();
*(var->value) = COERCE(new_value, 0, 6);
audio_ic_set_micboost();
return 1;
}
static void
audio_input_toggle( void * priv, int delta )
static CONFIG_VAR_CHANGE_FUNC(effect_mode_on_change)
{
menu_numeric_toggle(priv, delta, 0, 4);
if(*(unsigned*)priv == 3) *(unsigned*)priv += delta; //tamporaly disabled Ext:balanced. We can't find it.
audio_ic_set_input(OP_STANDALONE);
*(var->value) = COERCE(new_value, 0, 5);
audio_ic_set_effect_mode();
return 1;
}
static void override_audio_toggle( void * priv, int delta )
static CONFIG_VAR_CHANGE_FUNC(audio_filter_on_change)
{
menu_numeric_toggle(priv, 1, 0, 1);
audio_configure(2);
*(var->value) = COERCE(new_value, 0, 1);
audio_ic_set_filters(OP_STANDALONE);
return 1;
}
static void analog_gain_toggle( void * priv, int delta )
static CONFIG_VAR_CHANGE_FUNC(filter_hpf2config_on_change)
{
menu_numeric_toggle(priv, delta, 0, 5);
audio_ic_set_analog_gain();
*(var->value) = COERCE(new_value, 0, 7);
audio_ic_set_filters(OP_STANDALONE);
return 1;
}
static void analog_boost_toggle( void * priv, int delta )
static CONFIG_VAR_CHANGE_FUNC(recdgain_on_change)
{
menu_numeric_toggle(priv, delta, 0, 6);
audio_ic_set_micboost();
*(var->value) = COERCE(new_value, 0, 126);
audio_ic_set_recdgain();
return 1;
}
static void audio_effect_mode_toggle( void * priv, int delta )
static CONFIG_VAR_CHANGE_FUNC(dgain_on_change)
{
menu_numeric_toggle(priv, delta, 0, 5);
audio_ic_set_effect_mode();
*(var->value) = COERCE(new_value, 0, 15);
audio_ic_set_RecLRbalance();
return 1;
}
/** DSP Filter Function Enable Register p77 HPF1 HPF2 */
static void audio_filter_dc_toggle( void * priv, int delta )
static CONFIG_VAR_CHANGE_FUNC(alc_enable_on_change)
{
menu_numeric_toggle(priv, -1, 0, 1);
audio_ic_set_filters(OP_STANDALONE);
*(var->value) = new_value;
audio_ic_set_agc();
return 1;
}
static MENU_UPDATE_FUNC(audio_filter_dc_display)
static CONFIG_VAR_CHANGE_FUNC(input_choice_on_change)
{
if(cfg_filter_dc == 0){
// what does this mean?!
MENU_SET_WARNING(MENU_WARN_ADVICE, "Now you got under 10Hz, but meter is wrong value signed");
}
if(new_value == 3) return 0; //temporarily disabled Ext:balanced. We can't find it.
*(var->value) = new_value;
audio_ic_set_input(OP_STANDALONE);
return 1;
}
static void audio_filter_hpf2_toggle( void * priv, int delta )
static MENU_UPDATE_FUNC(audio_dgain_display)
{
menu_numeric_toggle(priv, 1, 0, 1);
audio_ic_set_filters(OP_STANDALONE);
int dgainval = get_dgain_val(entry->priv == &dgain_l ? 1 : 0);
MENU_SET_VALUE("%d dB", dgainval);
if (alc_enable)
MENU_SET_WARNING(MENU_WARN_NOT_WORKING, "AGC is enabled.");
}
static void audio_hpf2config_toggle( void * priv, int delta )
static MENU_UPDATE_FUNC(audio_lovl_display)
{
menu_numeric_toggle(priv, delta, 0, 7);
audio_ic_set_filters(OP_STANDALONE);
if (!audio_monitoring)
MENU_SET_WARNING(MENU_WARN_NOT_WORKING, "Headphone monitoring is disabled");
}
static void
audio_filters_toggle( void * priv, int delta )
static MENU_UPDATE_FUNC(audio_input_display)
{
menu_numeric_toggle(priv, 1, 0, 1);
audio_ic_set_filters(OP_STANDALONE);
if(input_choice == 3)
MENU_SET_WARNING(MENU_WARN_NOT_WORKING, "The 'Balanced' option is not working");
}
static void
audio_filters_toggle_reverse( void * priv, int delta )
static MENU_UPDATE_FUNC(audio_filter_dc_display)
{
menu_numeric_toggle(priv, -1, 0, 1);
audio_ic_set_filters(OP_STANDALONE);
if(cfg_filter_dc == 0){
// what does this mean?!
MENU_SET_WARNING(MENU_WARN_ADVICE, "Now you got under 10Hz, but meter is wrong value signed");
}
}
static void
audio_recdgain_toggle( void * priv, int delta )
{
menu_numeric_toggle(priv, -2*delta, 0, 126);
audio_ic_set_recdgain();
menu_numeric_toggle(priv, -2*delta, 0, 126);
}
static int get_cfg_recdgain(){
......@@ -547,14 +544,12 @@ static struct menu_entry audio_menus[] = {
.name = "Override audio settings",
.priv = &cfg_override_audio,
.max = 1,
.select = override_audio_toggle,
.depends_on = DEP_SOUND_RECORDING,
.help = "Override audio setting by ML",
},
{
.name = "Analog gain",
.priv = &cfg_analog_gain,
.select = analog_gain_toggle,
.max = 5,
.icon_type = IT_PERCENT,
.choices = CHOICES("0 dB", "+6 dB", "+15 dB", "+24 dB", "+33 dB", "+35 dB"),
......@@ -564,7 +559,6 @@ static struct menu_entry audio_menus[] = {
{
.name = "Mic Boost",
.priv = &cfg_analog_boost,
.select = analog_boost_toggle,
.max = 6,
.icon_type = IT_PERCENT,
.choices = CHOICES("0 dB","+5 dB","+10 dB","+15 dB","+20 dB","+25 dB","+30 dB"),
......@@ -580,7 +574,6 @@ static struct menu_entry audio_menus[] = {
{
.name = "Record Effect Mode",
.priv = &cfg_effect_mode,
.select = audio_effect_mode_toggle,
.max = 5,
.icon_type = IT_DICE,
.choices = CHOICES("Notch Filter", "EQ", "Notch EQ", "Enhnc REC", "Enhnc RECPLAY", "Loud"),
......@@ -591,7 +584,6 @@ static struct menu_entry audio_menus[] = {
.priv = &cfg_recdgain,
.max = 126,
.icon_type = IT_PERCENT,
.select = audio_recdgain_toggle,
.help = "Record Digital Volume. ",
},
{
......@@ -599,7 +591,6 @@ static struct menu_entry audio_menus[] = {
.priv = &dgain_l,
.max = 15,
.icon_type = IT_PERCENT,
.select = audio_dgain_toggle,
.update = audio_dgain_display,
.help = "Digital gain (LEFT). Any nonzero value reduces quality.",
},
......@@ -608,14 +599,12 @@ static struct menu_entry audio_menus[] = {
.priv = &dgain_r,
.max = 15,
.icon_type = IT_PERCENT,
.select = audio_dgain_toggle,
.update = audio_dgain_display,
.help = "Digital gain (RIGHT). Any nonzero value reduces quality.",
},
{
.name = "AGC",
.priv = &alc_enable,
.select = audio_alc_toggle,
.max = 1,
.help = "Automatic Gain Control - turn it off :)",
//~ .icon_type = IT_DISABLE_SOME_FEATURE_NEG,
......@@ -627,7 +616,7 @@ static struct menu_entry audio_menus[] = {
{
.name = "Input source",
.priv = &input_choice,
.select = audio_input_toggle,
.update = audio_input_display,
.max = 4,
.icon_type = IT_ALWAYS_ON,
.choices = (const char *[]) {"Internal mic", "L:int R:ext", "External stereo", "Balanced (N/A)", "Auto int/ext"},
......@@ -644,7 +633,6 @@ static struct menu_entry audio_menus[] = {
{
.name = "DC filter",
.priv = &cfg_filter_dc,
.select = audio_filter_dc_toggle,
.max = 1,
.update = audio_filter_dc_display,
.help = "first-order hig