Changeset 1971
 Timestamp:
 May 30, 2008 11:24:37 AM (16 years ago)
 Location:
 pjproject/trunk
 Files:

 3 edited
Legend:
 Unmodified
 Added
 Removed

pjproject/trunk/pjlib/include/pj/config_site_sample.h
r1965 r1971 27 27 # undef PJMEDIA_RESAMPLE_IMP 28 28 # define PJMEDIA_RESAMPLE_IMP PJMEDIA_RESAMPLE_LIBRESAMPLE 29 # define PJMEDIA_WSOLA_IMP PJMEDIA_WSOLA_IMP_ NULL29 # define PJMEDIA_WSOLA_IMP PJMEDIA_WSOLA_IMP_WSOLA_LITE 30 30 #endif 31 31 … … 51 51 # define PJMEDIA_RESAMPLE_IMP PJMEDIA_RESAMPLE_NONE 52 52 # define PJMEDIA_HAS_SPEEX_AEC 0 53 # define PJMEDIA_WSOLA_IMP PJMEDIA_WSOLA_IMP_ NULL53 # define PJMEDIA_WSOLA_IMP PJMEDIA_WSOLA_IMP_WSOLA_LITE 54 54 55 55 /* Disable all codecs but G.711 and GSM, for now */ 
pjproject/trunk/pjmedia/include/pjmedia/config.h
r1942 r1971 129 129 #define PJMEDIA_WSOLA_IMP_WSOLA 1 130 130 131 /** 132 * This denotes implementation of WSOLA algorithm with faster waveform 133 * similarity calculation. This implementation provides fair quality of 134 * the result with the main advantage of low processing power requirement. 135 */ 136 #define PJMEDIA_WSOLA_IMP_WSOLA_LITE 2 131 137 132 138 /** 
pjproject/trunk/pjmedia/src/pjmedia/wsola.c
r1941 r1971 29 29 #define THIS_FILE "wsola.c" 30 30 31 32 #if PJMEDIA_WSOLA_IMP==PJMEDIA_WSOLA_IMP_WSOLA 31 #if (PJMEDIA_WSOLA_IMP==PJMEDIA_WSOLA_IMP_WSOLA)  \ 32 (PJMEDIA_WSOLA_IMP==PJMEDIA_WSOLA_IMP_WSOLA_LITE) 33 33 34 /* 34 35 * WSOLA implementation using WSOLA … … 114 115 }; 115 116 117 #if (PJMEDIA_WSOLA_IMP==PJMEDIA_WSOLA_IMP_WSOLA_LITE) 118 119 /* In this implementation, waveform similarity comparison is done by calculating 120 * the difference of total level between template frame and the target buffer 121 * for each template_cnt samples. The smallest difference value assumed to be 122 * the most similar block. This seems to be naive, however some tests show 123 * acceptable results and the processing speed is amazing. 124 * 125 * diff level = (template[1]+..+template[n])  (target[1]+..+target[n]) 126 */ 127 static short *find_pitch(short *frm, short *beg, short *end, 128 unsigned template_cnt, int first) 129 { 130 short *sr, *best=beg; 131 int best_corr = 0x7FFFFFFF; 132 int frm_sum = 0; 133 unsigned i; 134 135 for (i = 0; i<template_cnt; ++i) 136 frm_sum += frm[i]; 137 138 for (sr=beg; sr!=end; ++sr) { 139 int corr = frm_sum; 140 int abs_corr = 0; 141 142 /* Do calculation on 8 samples at once */ 143 for (i = 0; i<template_cnt; i+=8) { 144 corr = (int)sr[i+0] + 145 (int)sr[i+1] + 146 (int)sr[i+2] + 147 (int)sr[i+3] + 148 (int)sr[i+4] + 149 (int)sr[i+5] + 150 (int)sr[i+6] + 151 (int)sr[i+7]; 152 } 153 154 /* Reverse back i if template_cnt is not multiplication of 8, 155 * the remaining samples will be processed below. 156 */ 157 if (i != template_cnt) 158 i = 8; 159 160 for (; i<template_cnt; ++i) 161 corr = (int)sr[i]; 162 163 abs_corr = corr > 0? corr : corr; 164 165 if (first) { 166 if (abs_corr < best_corr) { 167 best_corr = abs_corr; 168 best = sr; 169 } 170 } else { 171 if (abs_corr <= best_corr) { 172 best_corr = abs_corr; 173 best = sr; 174 } 175 } 176 } 177 178 /*TRACE_((THIS_FILE, "found pitch at %u", bestbeg));*/ 179 return best; 180 } 181 182 #endif 116 183 117 184 #if defined(PJ_HAS_FLOATING_POINT) && PJ_HAS_FLOATING_POINT!=0 … … 121 188 #include <math.h> 122 189 190 #if (PJMEDIA_WSOLA_IMP==PJMEDIA_WSOLA_IMP_WSOLA) 191 123 192 static short *find_pitch(short *frm, short *beg, short *end, 124 193 unsigned template_cnt, int first) … … 131 200 unsigned i; 132 201 202 /* Do calculation on 8 samples at once */ 133 203 for (i=0; i<template_cnt; i += 8) { 134 204 corr += ((float)frm[i+0]) * ((float)sr[i+0]) + … … 141 211 ((float)frm[i+7]) * ((float)sr[i+7]); 142 212 } 213 214 /* Reverse back i if template_cnt is not multiplication of 8, 215 * the remaining samples will be processed below. 216 */ 217 if (i != template_cnt) 218 i = 8; 219 143 220 for (; i<template_cnt; ++i) { 144 221 corr += ((float)frm[i]) * ((float)sr[i]); … … 162 239 } 163 240 241 #endif 242 164 243 static void overlapp_add(short dst[], unsigned count, 165 244 short l[], short r[], … … 204 283 enum { WINDOW_MAX_VAL = (1 << WINDOW_BITS)1 }; 205 284 285 #if (PJMEDIA_WSOLA_IMP==PJMEDIA_WSOLA_IMP_WSOLA) 286 206 287 static short *find_pitch(short *frm, short *beg, short *end, 207 288 unsigned template_cnt, int first) … … 215 296 unsigned i; 216 297 298 /* Do calculation on 8 samples at once */ 217 299 for (i=0; i<template_cnt; i+=8) { 218 300 corr += ((int)frm[i+0]) * ((int)sr[i+0]) + … … 225 307 ((int)frm[i+7]) * ((int)sr[i+7]); 226 308 } 309 310 /* Reverse back i if template_cnt is not multiplication of 8, 311 * the remaining samples will be processed below. 312 */ 313 if (i != template_cnt) 314 i = 8; 315 227 316 for (; i<template_cnt; ++i) { 228 317 corr += ((int)frm[i]) * ((int)sr[i]); … … 246 335 } 247 336 337 #endif 338 339 248 340 static void overlapp_add(short dst[], unsigned count, 249 341 short l[], short r[], … … 360 452 wsola>template_size = wsola>samples_per_frame; 361 453 454 /* Make sure minimal template size is 8, this is required by waveform 455 * similarity calculation (find_pitch()). Moreover, smaller template size 456 * will reduce accuracy. 457 */ 458 if (wsola>template_size < 8) 459 wsola>template_size = 8; 460 362 461 wsola>buf = (short*)pj_pool_calloc(pool, wsola>buf_cnt, 363 462 sizeof(short)); … … 470 569 unsigned dist; 471 570 472 if (count <= (del_cnt << 1)) { 571 if ((count  del_cnt) <= frmsz) { 572 //if (count <= (del_cnt << 1)) { 473 573 TRACE_((THIS_FILE, "Not enough samples to compress!")); 474 574 return samples_del; 475 575 } 476 576 477 start = buf + (frmsz >> 1); 577 //start = buf + (frmsz >> 1); 578 start = buf + del_cnt  samples_del; 478 579 end = start + frmsz; 479 580 480 581 if (end + frmsz > buf + count) 481 582 end = buf+countfrmsz; 583 584 pj_assert(start < end); 482 585 483 586 start = find_pitch(buf, start, end, wsola>template_size, 0); … … 818 921 } 819 922 820 821 923 #endif /* #if PJMEDIA_WSOLA_IMP.. */ 822 924
Note: See TracChangeset
for help on using the changeset viewer.