- Timestamp:
- Jul 14, 2008 6:55:01 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/wsola.c
r2117 r2145 162 162 163 163 /* 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) { 165 165 corr -= (int)sr[i+0] + 166 166 (int)sr[i+1] + … … 173 173 } 174 174 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 */ 181 176 for (; i<template_cnt; ++i) 182 177 corr -= (int)sr[i]; … … 221 216 222 217 /* 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) { 224 219 corr += ((float)frm[i+0]) * ((float)sr[i+0]) + 225 220 ((float)frm[i+1]) * ((float)sr[i+1]) + … … 232 227 } 233 228 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. */ 240 230 for (; i<template_cnt; ++i) { 241 231 corr += ((float)frm[i]) * ((float)sr[i]); … … 317 307 318 308 /* 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) { 320 310 corr += ((int)frm[i+0]) * ((int)sr[i+0]) + 321 311 ((int)frm[i+1]) * ((int)sr[i+1]) + … … 328 318 } 329 319 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. */ 336 321 for (; i<template_cnt; ++i) { 337 322 corr += ((int)frm[i]) * ((int)sr[i]); … … 535 520 pjmedia_circ_buf_reset(wsola->buf); 536 521 pjmedia_circ_buf_set_len(wsola->buf, wsola->hist_size + wsola->min_extra); 522 pjmedia_zero_samples(wsola->buf->start, wsola->buf->len); 537 523 538 524 return PJ_SUCCESS; … … 575 561 templ, start); 576 562 } 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 577 571 overlapp_add(wsola->merge_buf, wsola->hanning_size, templ, 578 572 start, wsola->hanning); … … 583 577 584 578 /* 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!"); 586 581 break; 582 } 587 583 588 584 /* Copy the "tail" (excess frame) to the end */ … … 672 668 673 669 buf_len = pjmedia_circ_buf_get_len(wsola->buf); 674 CHECK_(buf_len >= (unsigned)(wsola->hist_size + wsola->min_extra));675 670 676 671 /* Update vars */ … … 687 682 ®2, ®2_len); 688 683 684 CHECK_(pjmedia_circ_buf_get_len(wsola->buf) >= 685 (unsigned)(wsola->hist_size + (wsola->min_extra<<1))); 686 689 687 if (reg2_len == 0) { 690 ola_left = reg1 ;688 ola_left = reg1 + reg1_len - wsola->min_extra; 691 689 } else if (reg2_len >= wsola->min_extra) { 692 690 ola_left = reg2 + reg2_len - wsola->min_extra; … … 726 724 pj_int16_t frm[]) 727 725 { 728 unsigned samples_len; 726 unsigned samples_len, samples_req; 727 728 729 729 pj_status_t status = PJ_SUCCESS; 730 730 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 */ 731 735 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 732 740 wsola->ts.u64 += wsola->samples_per_frame; 733 741 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) { 745 743 /* Expand buffer */ 746 expand(wsola, new_samples);744 expand(wsola, samples_req - samples_len); 747 745 TRACE_((THIS_FILE, "Buf size after expanded = %d", 748 746 pjmedia_circ_buf_get_len(wsola->buf)));
Note: See TracChangeset
for help on using the changeset viewer.