Changeset 2757 for pjproject/trunk


Ignore:
Timestamp:
Jun 9, 2009 1:05:18 PM (15 years ago)
Author:
nanang
Message:

Ticket #830: Fixed noise from EC by keeping the playing frames unmodified (pjmedia_delay_buf_put() may modify the input frames and there is a case that the modified frames are not aligned anymore).

File:
1 edited

Legend:

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

    r2755 r2757  
    5353 
    5454    pjmedia_delay_buf   *delay_buf; 
     55    pj_int16_t      *frm_buf; 
    5556}; 
    5657 
     
    153154    ec->pool = pool; 
    154155    ec->obj_name = pool->obj_name; 
     156    ec->samples_per_frame = samples_per_frame; 
     157    ec->frm_buf = (pj_int16_t*)pj_pool_alloc(pool, samples_per_frame<<1); 
    155158    pj_list_init(&ec->lat_buf); 
    156159    pj_list_init(&ec->lat_free); 
     
    275278                                           pj_int16_t *play_frm ) 
    276279{ 
     280    /* Playing frame should be stored, as it will be used by echo_capture()  
     281     * as reference frame, delay buffer is used for storing the playing frames 
     282     * as in case there was clock drift between mic & speaker. 
     283     * 
     284     * Ticket #830: 
     285     * Note that pjmedia_delay_buf_put() may modify the input frame and those 
     286     * modified frames may not be smooth, i.e: if there were two or more 
     287     * consecutive pjmedia_delay_buf_get() before next pjmedia_delay_buf_put(), 
     288     * so we'll just feed the delay buffer with the copy of playing frame, 
     289     * instead of the original playing frame. However this will cause the EC  
     290     * uses slight 'different' frames (for reference) than actually played  
     291     * by the speaker. 
     292     */ 
     293    pjmedia_copy_samples(echo->frm_buf, play_frm,  
     294                         echo->samples_per_frame); 
     295    pjmedia_delay_buf_put(echo->delay_buf, echo->frm_buf); 
     296 
    277297    if (!echo->lat_ready) { 
    278298        /* We've not built enough latency in the buffer, so put this frame 
     
    284304            echo->lat_ready = PJ_TRUE; 
    285305            PJ_LOG(5,(echo->obj_name, "Latency bufferring complete")); 
    286             pjmedia_delay_buf_put(echo->delay_buf, play_frm); 
    287306            return PJ_SUCCESS; 
    288307        } 
     
    291310        pj_list_erase(frm); 
    292311 
    293         pjmedia_copy_samples(frm->buf, play_frm, echo->samples_per_frame); 
     312        /* Move one frame from delay buffer to the latency buffer. */ 
     313        pjmedia_delay_buf_get(echo->delay_buf, echo->frm_buf); 
     314        pjmedia_copy_samples(frm->buf, echo->frm_buf, echo->samples_per_frame); 
    294315        pj_list_push_back(&echo->lat_buf, frm); 
    295  
    296     } else { 
    297         /* Latency buffer is ready (full), so we put this frame in the 
    298          * delay buffer. 
    299          */ 
    300         pjmedia_delay_buf_put(echo->delay_buf, play_frm); 
    301316    } 
    302317 
Note: See TracChangeset for help on using the changeset viewer.