Ignore:
Timestamp:
Nov 23, 2006 10:19:46 AM (17 years ago)
Author:
bennylp
Message:

Updated Speex to their latest SVN (1.2-beta). AEC seems
to work much better now and take less CPU, so I increased
default tail length in PJSUA to 800ms.

File:
1 edited

Legend:

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

    r822 r823  
    3131 
    3232#define THIS_FILE       "echo_speex.c" 
    33 #define BUF_COUNT       20 
    34 #define MIN_PREFETCH    4 
    35 #define MAX_PREFETCH    12 
     33#define BUF_COUNT       16 
     34#define MIN_PREFETCH    2 
     35#define MAX_PREFETCH    (BUF_COUNT*2/3) 
    3636 
    3737 
     
    148148                  "[count=%d, seq=%d]", 
    149149                  fq->max_count, timestamp / fq->samples_per_frame)); 
     150        //pjmedia_frame_queue_init(fq, fq->seq_delay, fq->prefetch_count); 
    150151        return PJ_ETOOMANY; 
    151152    } 
     
    290291    speex_ec *echo; 
    291292    int sampling_rate; 
    292     int disabled, enabled; 
    293293    pj_status_t status; 
    294294 
     
    323323    } 
    324324 
     325    /* Set sampling rate */ 
     326    sampling_rate = clock_rate; 
     327    speex_echo_ctl(echo->state, SPEEX_ECHO_SET_SAMPLING_RATE,  
     328                   &sampling_rate); 
     329 
    325330    echo->preprocess = speex_preprocess_state_init(samples_per_frame,  
    326331                                                   clock_rate); 
     
    332337 
    333338    /* Disable all preprocessing, we only want echo cancellation */ 
     339#if 0 
    334340    disabled = 0; 
    335341    enabled = 1; 
     
    342348    speex_preprocess_ctl(echo->preprocess, SPEEX_PREPROCESS_SET_DEREVERB,  
    343349                         &disabled); 
    344  
    345     /* Set sampling rate */ 
    346     sampling_rate = clock_rate; 
    347     speex_echo_ctl(echo->state, SPEEX_ECHO_SET_SAMPLING_RATE,  
    348                    &sampling_rate); 
     350#endif 
     351 
     352    /* Control echo cancellation in the preprocessor */ 
     353   speex_preprocess_ctl(echo->preprocess, SPEEX_PREPROCESS_SET_ECHO_STATE,  
     354                        echo->state); 
     355 
    349356 
    350357    /* Create temporary frame for echo cancellation */ 
     
    444451    } 
    445452 
    446     pjmedia_frame_queue_put(echo->frame_queue, play_frm,  
    447                             echo->samples_per_frame*2, echo->play_ts); 
     453    if (pjmedia_frame_queue_put(echo->frame_queue, play_frm,  
     454                                echo->samples_per_frame*2,  
     455                                echo->play_ts) != PJ_SUCCESS) 
     456    { 
     457        int seq_delay; 
     458 
     459        /* On full reset frame queue */ 
     460        seq_delay = ((int)echo->play_ts - (int)echo->rec_ts) /  
     461                        (int)echo->samples_per_frame; 
     462        pjmedia_frame_queue_init(echo->frame_queue, seq_delay, 
     463                                 echo->prefetch); 
     464 
     465        /* And re-put */ 
     466        pjmedia_frame_queue_put(echo->frame_queue, play_frm,  
     467                                echo->samples_per_frame*2,  
     468                                echo->play_ts); 
     469    } 
    448470 
    449471    pj_lock_release(echo->lock); 
     
    495517         
    496518        if (pjmedia_frame_queue_empty(echo->frame_queue)) { 
    497             int seq_delay, prefetch; 
     519            int seq_delay; 
    498520 
    499521            seq_delay = ((int)echo->play_ts - (int)echo->rec_ts) /  
    500522                            (int)echo->samples_per_frame; 
    501             prefetch = pjmedia_frame_queue_get_prefetch(echo->frame_queue); 
    502             //++prefetch; 
    503             pjmedia_frame_queue_init(echo->frame_queue, seq_delay, prefetch); 
     523            pjmedia_frame_queue_init(echo->frame_queue, seq_delay,  
     524                                     echo->prefetch); 
    504525            status = -1; 
    505526 
     
    538559 
    539560    /* Cancel echo, put output in temporary buffer */ 
    540     speex_echo_cancel(echo->state, (const spx_int16_t*)rec_frm,  
    541                       (const spx_int16_t*)play_frm,  
    542                       (spx_int16_t*)echo->tmp_frame,  
    543                       echo->residue); 
     561    speex_echo_cancellation(echo->state, (const spx_int16_t*)rec_frm, 
     562                            (const spx_int16_t*)play_frm, 
     563                            (spx_int16_t*)echo->tmp_frame); 
    544564 
    545565 
    546566    /* Preprocess output */ 
    547     speex_preprocess(echo->preprocess, (spx_int16_t*)echo->tmp_frame,  
    548                      echo->residue); 
     567    speex_preprocess_run(echo->preprocess, (spx_int16_t*)echo->tmp_frame); 
    549568 
    550569    /* Copy temporary buffer back to original rec_frm */ 
Note: See TracChangeset for help on using the changeset viewer.