Changeset 2208


Ignore:
Timestamp:
Aug 13, 2008 1:50:19 PM (16 years ago)
Author:
bennylp
Message:

More ticket #590: handle the case when mic level is set too high causing echo to be mistakenly treated as local user speaking

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/echo_suppress.c

    r2203 r2208  
    382382 
    383383/* Set state */ 
    384 static void echo_supp_set_state(echo_supp *ec, enum talk_state state) 
    385 { 
     384static void echo_supp_set_state(echo_supp *ec, enum talk_state state,  
     385                                unsigned level) 
     386{ 
     387    PJ_UNUSED_ARG(level); 
     388 
    386389    if (state != ec->talk_state) { 
    387         TRACE_((THIS_FILE, "[%03d.%03d] %s --> %s",  
     390        TRACE_((THIS_FILE, "[%03d.%03d] %s --> %s, level=%u",  
    388391                           (ec->update_cnt * SEGMENT_PTIME / 1000),  
    389392                           ((ec->update_cnt * SEGMENT_PTIME) % 1000), 
    390393                           state_names[ec->talk_state], 
    391                            state_names[state])); 
     394                           state_names[state], level)); 
    392395        ec->talk_state = state; 
    393396    } 
     
    466469        ulaw = pjmedia_linear2ulaw(sum_play_level/ec->templ_cnt) ^ 0xFF; 
    467470        if (ulaw < MIN_SIGNAL_ULAW) { 
    468             echo_supp_set_state(ec, ST_REM_SILENT); 
     471            echo_supp_set_state(ec, ST_REM_SILENT, ulaw); 
    469472            return; 
    470473        } 
     
    472475        /* Bail out if local user is talking */ 
    473476        if (sum_rec_level >= sum_play_level) { 
    474             echo_supp_set_state(ec, ST_LOCAL_TALK); 
     477            echo_supp_set_state(ec, ST_LOCAL_TALK, ulaw); 
    475478            return; 
    476479        } 
    477480 
     481#if 0 
     482        // disabled: not a good idea if mic throws out loud echo 
    478483        /* Also bail out if we suspect there's a doubletalk */ 
    479484        ulaw = pjmedia_linear2ulaw(sum_rec_level/ec->templ_cnt) ^ 0xFF; 
    480485        if (ulaw > MIN_SIGNAL_ULAW) { 
    481             echo_supp_set_state(ec, ST_DOUBLETALK); 
     486            echo_supp_set_state(ec, ST_DOUBLETALK, ulaw); 
    482487            return; 
    483488        } 
     489#endif 
    484490 
    485491        /* Calculate correlation and save to temporary array */ 
     
    493499 
    494500    /* We seem to have good signal, we can update the EC state */ 
    495     echo_supp_set_state(ec, ST_REM_TALK); 
     501    echo_supp_set_state(ec, ST_REM_TALK, MIN_SIGNAL_ULAW); 
    496502 
    497503    /* Accummulate the correlation value to the history and at the same 
     
    646652                 */ 
    647653                factor = 1.0; 
    648                 echo_supp_set_state(ec, ST_LOCAL_TALK); 
    649             } else { 
     654                echo_supp_set_state(ec, ST_LOCAL_TALK, rec_level); 
     655            } else if (rec_level >= play_level) { 
    650656                /* Seems that both are talking. Scale the mic signal 
    651657                 * down a little bit to reduce echo, while allowing both 
     
    653659                 */ 
    654660                factor = (float)(ec->avg_factor[ec->tail_index] * 2); 
    655                 echo_supp_set_state(ec, ST_DOUBLETALK); 
     661                echo_supp_set_state(ec, ST_DOUBLETALK, rec_level); 
     662            } else { 
     663                /* Speaker is active, but we've picked up large signal in 
     664                 * the microphone. Assume that this is an echo, so bring  
     665                 * the level down to minimum too. 
     666                 */ 
     667                factor = ec->min_factor[ec->tail_index] / 2; 
     668                echo_supp_set_state(ec, ST_REM_TALK, play_level); 
    656669            } 
    657670        } else { 
     
    662675                 */ 
    663676                factor = ec->avg_factor[ec->tail_index] * 3 / 2; 
    664                 echo_supp_set_state(ec, ST_REM_SILENT); 
     677                echo_supp_set_state(ec, ST_REM_SILENT, rec_level); 
    665678            } else { 
    666679                /* Mic is idle, but there's something playing in speaker. 
     
    668681                 */ 
    669682                factor = ec->min_factor[ec->tail_index] / 2; 
    670                 echo_supp_set_state(ec, ST_REM_TALK); 
     683                echo_supp_set_state(ec, ST_REM_TALK, play_level); 
    671684            } 
    672685        } 
Note: See TracChangeset for help on using the changeset viewer.