Index: apps/gui/gwps.c =================================================================== RCS file: /cvsroot/rockbox/apps/gui/gwps.c,v retrieving revision 1.17 diff -u -b -r1.17 gwps.c --- apps/gui/gwps.c 9 Dec 2005 01:11:14 -0000 1.17 +++ apps/gui/gwps.c 6 Jan 2006 13:06:00 -0000 @@ -35,6 +35,7 @@ #include "gwps-common.h" #include "audio.h" #include "usb.h" +#include "mas.h" #include "status.h" #include "main_menu.h" #include "ata.h" @@ -123,24 +124,11 @@ restore = true; } - while ( 1 ) - { - bool audio_paused = (audio_status() & AUDIO_STATUS_PAUSE)?true:false; - /* did someone else (i.e power thread) change audio pause mode? */ - if (wps_state.paused != audio_paused) { - wps_state.paused = audio_paused; - - /* if another thread paused audio, we are probably in car mode, - about to shut down. lets save the settings. */ - if (wps_state.paused) { - settings_save(); -#if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF) - ata_flush(); -#endif - } - } + wps_state.paused = audio_status() & AUDIO_STATUS_PAUSE ? true : false; + while ( 1 ) /* wps main loop */ + { #ifdef HAVE_LCD_BITMAP /* when the peak meter is enabled we want to have a few extra updates to make it look smooth. On the @@ -218,6 +206,110 @@ if (!audio_status()) exit = true; + /* did someone else (i.e power thread) change audio pause mode? */ + if (wps_state.paused != ((audio_status() & AUDIO_STATUS_PAUSE) ? true : false)) { + wps_state.paused = wps_state.paused ? false : true; /* toggle state to that of audio_status() */ + + /* if another thread paused audio, we are probably in car mode, + about to shut down. lets save the settings. */ + if (wps_state.paused) { + settings_save(); +#if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF) + ata_flush(); +#endif + } + } + + /* the following code pauses audio, when there is a line-in signal. */ + /* it is active only if the recording trigger is enabled. Also it's */ + /* thresholds and times are taken from there. Only that the times */ + /* are multiple of the above timeout period 200ms, i guess. And the */ + /* index is used dirctly. This should result in about 0-2,2s secs */ + /* The logic is slightly twisted the start Threshold is for start of*/ + /* mute (pause) and vice versa. */ + +#define SQRROOTOFAVGSMP 3 /* 2^3 -> taking 4 Left, and 4 right samples, if BUTTON_NONE */ + + if (global_settings.line_in_scale > 0 + && global_settings.rec_trigger_mode != TRIG_MODE_OFF) + { + static int adc_pause_cnt; /* for 'measuring' the time in 200ms */ + static bool adc_pause; /* did we pause for adc input already? */ + int threshold; /* the threshold to compare adc quick peak values agains */ + + long int i_lev = 0; /* the avg'ed value of the ADC quick peak values */ + int rpc = 0; /* counter for avg'ing */ + + while( 1 ) /* avg loop, reading left and right, evtl. wait and repeat */ + { + i_lev += mas_codec_readreg( MAS_REG_QPEAK_L + (rpc&1)); + /* take only l+r sample without a wait, if button != BUTTON_NONE */ + if(rpc == (button != BUTTON_NONE ? 1 :((1 << SQRROOTOFAVGSMP) - 1))) break; + if(rpc++&1) sleep(1); /* wait a tick after reading l+r */ + } + i_lev >>= (button != BUTTON_NONE ? 1 : SQRROOTOFAVGSMP); /* calculate avg */ + + if (!adc_pause) + { + threshold = global_settings.rec_start_thres < 0 ? + /* dB: */( global_settings.rec_start_thres < -89 ? 0 : + peak_meter_db2sample((global_settings.rec_start_thres + 1) * 100) ) : + /* linear %:*/ global_settings.rec_start_thres * MAX_PEAK / 100; + + if (wps_state.paused) /* we're already put to pause state */ + adc_pause_cnt = 0; /* reset counter */ + else if ( (int)i_lev < threshold ) /* input signal < mute level? */ + adc_pause_cnt = 0; /* reset counter */ + else if(!(adc_pause_cnt >= global_settings.rec_start_duration)) /* not yed long enough? (might be 0!) */ + { + if (button == BUTTON_NONE) /* do not count key up and downs */ + adc_pause_cnt++; + } + else + { + adc_pause = wps_state.paused = true; + audio_pause(); + adc_pause_cnt = 0; /* done, reset counter */ + } + } + else /* adc_pause */ + { + threshold = global_settings.rec_stop_thres < 0 ? + /* dB: */( global_settings.rec_stop_thres < -89 ? 0 : + peak_meter_db2sample((global_settings.rec_stop_thres + 1) * 100) ) : + /* linear %:*/ global_settings.rec_stop_thres * MAX_PEAK / 100; + + if(!wps_state.paused) /* pause already released? */ + { + adc_pause_cnt = 0; /* reset counter */ + adc_pause = false; /* unmute, too */ + } + else if ( (int)i_lev > threshold ) + adc_pause_cnt = 0; /* reset counter */ + else if(!(adc_pause_cnt >= global_settings.rec_stop_postrec)) /* not yet long enough? (might be 0!) */ + { + if (button == BUTTON_NONE) /* do not count key up and downs */ + adc_pause_cnt++; + } + else + { + adc_pause = wps_state.paused = false; + audio_resume(); + adc_pause_cnt = 0; /* done, reset counter */ + } + } + +#if defined DEBUGLINE && defined SHOW_ADC_PAUSEING + { + char s[15]; + snprintf(s, sizeof s, "%4d%%%2d %d %d", (int) (100 * i_lev / threshold), + adc_pause_cnt, adc_pause ? 1 : 0, audio_status() ); + lcd_puts(0,3,s); + lcd_update(); + } +#endif + } + switch(button) { #ifdef WPS_CONTEXT @@ -694,7 +786,7 @@ } if (button != BUTTON_NONE) lastbutton = button; - } + } /* wps main loop */ return 0; /* unreachable - just to reduce compiler warnings */ }