Changeset 3115


Ignore:
Timestamp:
Mar 3, 2010 2:47:35 PM (10 years ago)
Author:
nanang
Message:

Ticket #1042, minor updates related to AEC:

  • Added requirement of AEC minimal latency between reference and echo in aectest sample app.
  • Modified AEC latency in sound port to 3/4 of playback latency.
  • Few cleaned up echo_common.c: unused vars, a bit stricter latency check (to be at least as much as PTIME).
Location:
pjproject/trunk
Files:
3 edited

Legend:

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

    r2757 r3115  
    2525#include <pj/list.h> 
    2626#include <pj/log.h> 
     27#include <pj/math.h> 
    2728#include <pj/pool.h> 
    2829#include "echo_internal.h" 
     
    4748 
    4849    pj_bool_t        lat_ready;     /* lat_buf has been filled in.          */ 
    49     unsigned         lat_target_cnt;/* Target number of frames in lat_buf   */ 
    50     unsigned         lat_buf_cnt;   /* Actual number of frames in lat_buf   */ 
    5150    struct frame     lat_buf;       /* Frame queue for delayed playback     */ 
    5251    struct frame     lat_free;      /* Free frame list.                     */ 
     
    145144                                         pjmedia_echo_state **p_echo ) 
    146145{ 
    147     unsigned ptime; 
     146    unsigned ptime, lat_cnt; 
    148147    pjmedia_echo_state *ec; 
    149148    pj_status_t status; 
     
    195194    /* Create latency buffers */ 
    196195    ptime = samples_per_frame * 1000 / clock_rate; 
    197     if (latency_ms == 0) { 
     196    if (latency_ms > ptime) { 
     197        /* Normalize latency with delaybuf/WSOLA latency */ 
     198        latency_ms -= PJ_MIN(ptime, PJMEDIA_WSOLA_DELAY_MSEC); 
     199    } 
     200    if (latency_ms < ptime) { 
    198201        /* Give at least one frame delay to simplify programming */ 
    199202        latency_ms = ptime; 
    200203    } 
    201     ec->lat_target_cnt = latency_ms / ptime; 
    202     if (ec->lat_target_cnt != 0) { 
    203         unsigned i; 
    204         for (i=0; i < ec->lat_target_cnt; ++i)  { 
    205             struct frame *frm; 
    206  
    207             frm = (struct frame*) pj_pool_alloc(pool, (samples_per_frame<<1) + 
    208                                                       sizeof(struct frame)); 
    209             pj_list_push_back(&ec->lat_free, frm); 
    210         } 
    211     } else { 
    212         ec->lat_ready = PJ_TRUE; 
     204    lat_cnt = latency_ms / ptime; 
     205    while (lat_cnt--)  { 
     206        struct frame *frm; 
     207 
     208        frm = (struct frame*) pj_pool_alloc(pool, (samples_per_frame<<1) + 
     209                                                  sizeof(struct frame)); 
     210        pj_list_push_back(&ec->lat_free, frm); 
    213211    } 
    214212 
  • pjproject/trunk/pjmedia/src/pjmedia/sound_port.c

    r2755 r3115  
    564564            //delay_ms = (si.rec_latency + si.play_latency) * 1000 / 
    565565            //     snd_port->clock_rate; 
    566             delay_ms = prm.output_latency_ms; 
     566            /* Set EC latency to 3/4 of output latency to reduce the 
     567             * possibility of missing/late reference frame. 
     568             */ 
     569            delay_ms = prm.output_latency_ms * 3/4; 
    567570            status = pjmedia_echo_create2(pool, snd_port->clock_rate,  
    568571                                          snd_port->channel_count, 
  • pjproject/trunk/pjsip-apps/src/samples/aectest.c

    r2394 r3115  
    5656"\n" 
    5757" options:\n" 
    58 "  -d  The delay between playback and capture in ms. Default is zero.\n" 
     58"  -d  The delay between playback and capture in ms, at least 25 ms.\n" 
     59"      Default is 25 ms. See note below.                            \n" 
    5960"  -l  Set the echo tail length in ms. Default is 200 ms            \n" 
    6061"  -r  Set repeat count (default=1)                                 \n" 
    6162"  -a  Algorithm: 0=default, 1=speex, 3=echo suppress               \n" 
    62 "  -i  Interactive                                                  \n"; 
     63"  -i  Interactive                                                  \n" 
     64"\n" 
     65" Note that for the AEC internal buffering mechanism, it is required\n" 
     66" that the echoed signal (in REC.WAV) is delayed from the           \n" 
     67" corresponding reference signal (in PLAY.WAV) at least as much as  \n" 
     68" frame time + PJMEDIA_WSOLA_DELAY_MSEC. In this application, frame \n" 
     69" time is 20 ms and default PJMEDIA_WSOLA_DELAY_MSEC is 5 ms, hence \n" 
     70" 25 ms delay is the minimum value.                                 \n"; 
    6371 
    6472/*  
     
    92100    pjmedia_frame play_frame, rec_frame; 
    93101    unsigned opt = 0; 
    94     unsigned latency_ms = 0; 
     102    unsigned latency_ms = 25; 
    95103    unsigned tail_ms = TAIL_LENGTH; 
    96104    pj_timestamp t0, t1; 
     
    102110        case 'd': 
    103111            latency_ms = atoi(pj_optarg); 
     112            if (latency_ms < 25) { 
     113                puts("Invalid delay"); 
     114                puts(desc); 
     115            } 
    104116            break; 
    105117        case 'l': 
     
    128140            repeat = atoi(pj_optarg); 
    129141            if (repeat < 1) { 
    130                 puts("Invalid algorithm"); 
     142                puts("Invalid repeat count"); 
    131143                puts(desc); 
    132144                return 1; 
     
    252264    pj_get_timestamp(&t1); 
    253265 
    254     i = pjmedia_wav_writer_port_get_pos(wav_out) * 1000 /  
     266    i = pjmedia_wav_writer_port_get_pos(wav_out) / sizeof(pj_int16_t) * 1000 /  
    255267        (wav_out->info.clock_rate * wav_out->info.channel_count); 
    256268    PJ_LOG(3,(THIS_FILE, "Processed %3d.%03ds audio", 
Note: See TracChangeset for help on using the changeset viewer.