Changeset 2145


Ignore:
Timestamp:
Jul 14, 2008 6:55:01 PM (16 years ago)
Author:
nanang
Message:

Ticket #570: Fixed find_pitch() search range iteration; and fixed wsola_generate() in deciding when to just return a frame from existing extra samples and when to expand/generate samples.

File:
1 edited

Legend:

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

    r2117 r2145  
    162162 
    163163        /* Do calculation on 8 samples at once */ 
    164         for (i = 0; i<template_cnt; i+=8) { 
     164        for (i = 0; i<template_cnt-8; i+=8) { 
    165165            corr -= (int)sr[i+0] + 
    166166                    (int)sr[i+1] + 
     
    173173        } 
    174174 
    175         /* Reverse back i if template_cnt is not multiplication of 8, 
    176          * the remaining samples will be processed below. 
    177          */ 
    178         if (i != template_cnt) 
    179             i -= 8; 
    180  
     175        /* Process remaining samples */ 
    181176        for (; i<template_cnt; ++i) 
    182177            corr -= (int)sr[i]; 
     
    221216 
    222217        /* Do calculation on 8 samples at once */ 
    223         for (i=0; i<template_cnt; i += 8) { 
     218        for (i=0; i<template_cnt-8; i += 8) { 
    224219            corr += ((float)frm[i+0]) * ((float)sr[i+0]) +  
    225220                    ((float)frm[i+1]) * ((float)sr[i+1]) +  
     
    232227        } 
    233228 
    234         /* Reverse back i if template_cnt is not multiplication of 8, 
    235          * the remaining samples will be processed below. 
    236          */ 
    237         if (i != template_cnt) 
    238             i -= 8; 
    239  
     229        /* Process remaining samples. */ 
    240230        for (; i<template_cnt; ++i) { 
    241231            corr += ((float)frm[i]) * ((float)sr[i]); 
     
    317307 
    318308        /* Do calculation on 8 samples at once */ 
    319         for (i=0; i<template_cnt; i+=8) { 
     309        for (i=0; i<template_cnt-8; i+=8) { 
    320310            corr += ((int)frm[i+0]) * ((int)sr[i+0]) +  
    321311                    ((int)frm[i+1]) * ((int)sr[i+1]) +  
     
    328318        } 
    329319 
    330         /* Reverse back i if template_cnt is not multiplication of 8, 
    331          * the remaining samples will be processed below. 
    332          */ 
    333         if (i != template_cnt) 
    334             i -= 8; 
    335  
     320        /* Process remaining samples. */ 
    336321        for (; i<template_cnt; ++i) { 
    337322            corr += ((int)frm[i]) * ((int)sr[i]); 
     
    535520    pjmedia_circ_buf_reset(wsola->buf); 
    536521    pjmedia_circ_buf_set_len(wsola->buf, wsola->hist_size + wsola->min_extra); 
     522    pjmedia_zero_samples(wsola->buf->start, wsola->buf->len);  
    537523 
    538524    return PJ_SUCCESS; 
     
    575561                                templ, start); 
    576562        } else { 
     563            /* Check if pointers are in the valid range */ 
     564            CHECK_(templ >= wsola->buf->buf && 
     565                   templ + wsola->hanning_size <=  
     566                   wsola->buf->buf + wsola->buf->capacity); 
     567            CHECK_(start >= wsola->buf->buf && 
     568                   start + wsola->hanning_size <=  
     569                   wsola->buf->buf + wsola->buf->capacity); 
     570 
    577571            overlapp_add(wsola->merge_buf, wsola->hanning_size, templ,  
    578572                         start, wsola->hanning); 
     
    583577 
    584578        /* Not enough buffer to hold the result */ 
    585         if (reg1_len + dist > wsola->buf_size) 
     579        if (reg1_len + dist > wsola->buf_size) { 
     580            pj_assert(!"WSOLA buffer size may be to small!"); 
    586581            break; 
     582        } 
    587583 
    588584        /* Copy the "tail" (excess frame) to the end */ 
     
    672668 
    673669    buf_len = pjmedia_circ_buf_get_len(wsola->buf); 
    674     CHECK_(buf_len >= (unsigned)(wsola->hist_size + wsola->min_extra)); 
    675670 
    676671    /* Update vars */ 
     
    687682                                          &reg2, &reg2_len); 
    688683 
     684        CHECK_(pjmedia_circ_buf_get_len(wsola->buf) >=  
     685               (unsigned)(wsola->hist_size + (wsola->min_extra<<1))); 
     686 
    689687        if (reg2_len == 0) { 
    690             ola_left = reg1; 
     688            ola_left = reg1 + reg1_len - wsola->min_extra; 
    691689        } else if (reg2_len >= wsola->min_extra) { 
    692690            ola_left = reg2 + reg2_len - wsola->min_extra; 
     
    726724                                            pj_int16_t frm[]) 
    727725{ 
    728     unsigned samples_len; 
     726    unsigned samples_len, samples_req; 
     727 
     728 
    729729    pj_status_t status = PJ_SUCCESS; 
    730730 
     731    CHECK_(pjmedia_circ_buf_get_len(wsola->buf) >= wsola->hist_size +  
     732           wsola->min_extra); 
     733 
     734    /* Calculate how many samples in the buffer */ 
    731735    samples_len = pjmedia_circ_buf_get_len(wsola->buf) - wsola->hist_size; 
     736 
     737    /* Calculate how many samples are required to be available in the buffer */ 
     738    samples_req = wsola->samples_per_frame + (wsola->min_extra << 1); 
     739     
    732740    wsola->ts.u64 += wsola->samples_per_frame; 
    733741 
    734     if (samples_len < (unsigned)wsola->samples_per_frame +  
    735         (unsigned)wsola->min_extra)  
    736     { 
    737         unsigned new_samples; 
    738  
    739         /* Calculate how many samples are needed for a new frame */ 
    740         new_samples = wsola->samples_per_frame + wsola->min_extra -  
    741                       samples_len; 
    742         if (wsola->expand_cnt == 0) 
    743             new_samples += wsola->min_extra; 
    744  
     742    if (samples_len < samples_req) { 
    745743        /* Expand buffer */ 
    746         expand(wsola, new_samples); 
     744        expand(wsola, samples_req - samples_len); 
    747745        TRACE_((THIS_FILE, "Buf size after expanded = %d",  
    748746                pjmedia_circ_buf_get_len(wsola->buf))); 
Note: See TracChangeset for help on using the changeset viewer.