- Timestamp:
- May 15, 2011 12:54:28 PM (14 years ago)
- Location:
- pjproject/branches/1.x/pjmedia
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/1.x/pjmedia/include/pjmedia/delaybuf.h
r3553 r3567 65 65 66 66 /** 67 * Delay buffer options. 68 */ 69 typedef enum pjmedia_delay_buf_flag 70 { 71 /** 72 * Use simple FIFO mechanism for the delay buffer, i.e. 73 * without WSOLA for expanding and shrinking audio samples. 74 */ 75 PJMEDIA_DELAY_BUF_SIMPLE_FIFO = 1 76 77 } pjmedia_delay_buf_flag; 78 79 /** 67 80 * Create the delay buffer. Once the delay buffer is created, it will 68 81 * enter learning state unless the delay argument is specified, which … … 80 93 * one frame time, default maximum delay used is 81 94 * 400 ms. 82 * @param options Option flags, must be zero for now. 95 * @param options Options. If PJMEDIA_DELAY_BUF_SIMPLE_FIFO is 96 * specified, then a simple FIFO mechanism 97 * will be used instead of the adaptive 98 * implementation (which uses WSOLA to expand 99 * or shrink audio samples). 100 * See #pjmedia_delay_buf_flag for other options. 83 101 * @param p_b Pointer to receive the delay buffer instance. 84 102 * -
pjproject/branches/1.x/pjmedia/include/pjmedia/echo.h
r3553 r3567 89 89 * canceller will not be called by different threads at the same time. 90 90 */ 91 PJMEDIA_ECHO_NO_LOCK = 16 91 PJMEDIA_ECHO_NO_LOCK = 16, 92 93 /** 94 * If PJMEDIA_ECHO_USE_SIMPLE_FIFO flag is specified, the delay buffer 95 * created for the echo canceller will use simple FIFO mechanism, i.e. 96 * without using WSOLA to expand and shrink audio samples. 97 */ 98 PJMEDIA_ECHO_USE_SIMPLE_FIFO = 32 99 92 100 93 101 } pjmedia_echo_flag; -
pjproject/branches/1.x/pjmedia/src/pjmedia/delaybuf.c
r3553 r3567 100 100 PJ_ASSERT_RETURN(pool && samples_per_frame && clock_rate && channel_count && 101 101 p_b, PJ_EINVAL); 102 PJ_ASSERT_RETURN(options==0, PJ_EINVAL);103 104 PJ_UNUSED_ARG(options);105 102 106 103 if (!name) { … … 127 124 return status; 128 125 129 /* Create WSOLA */ 130 status = pjmedia_wsola_create(pool, clock_rate, samples_per_frame, 1, 131 PJMEDIA_WSOLA_NO_FADING, &b->wsola); 132 if (status != PJ_SUCCESS) 133 return status; 126 if (!(options & PJMEDIA_DELAY_BUF_SIMPLE_FIFO)) { 127 /* Create WSOLA */ 128 status = pjmedia_wsola_create(pool, clock_rate, samples_per_frame, 1, 129 PJMEDIA_WSOLA_NO_FADING, &b->wsola); 130 if (status != PJ_SUCCESS) 131 return status; 132 PJ_LOG(5, (b->obj_name, "Using delay buffer with WSOLA.")); 133 } else { 134 PJ_LOG(5, (b->obj_name, "Using simple FIFO delay buffer.")); 135 } 134 136 135 137 /* Finally, create mutex */ … … 148 150 PJ_DEF(pj_status_t) pjmedia_delay_buf_destroy(pjmedia_delay_buf *b) 149 151 { 150 pj_status_t status ;152 pj_status_t status = PJ_SUCCESS; 151 153 152 154 PJ_ASSERT_RETURN(b, PJ_EINVAL); … … 154 156 pj_lock_acquire(b->lock); 155 157 156 status = pjmedia_wsola_destroy(b->wsola); 157 if (status == PJ_SUCCESS) 158 b->wsola = NULL; 158 if (b->wsola) { 159 status = pjmedia_wsola_destroy(b->wsola); 160 if (status == PJ_SUCCESS) 161 b->wsola = NULL; 162 } 159 163 160 164 pj_lock_release(b->lock); … … 265 269 pj_lock_acquire(b->lock); 266 270 267 update(b, OP_PUT); 271 if (b->wsola) { 272 update(b, OP_PUT); 268 273 269 status = pjmedia_wsola_save(b->wsola, frame, PJ_FALSE); 270 if (status != PJ_SUCCESS) { 271 pj_lock_release(b->lock); 272 return status; 274 status = pjmedia_wsola_save(b->wsola, frame, PJ_FALSE); 275 if (status != PJ_SUCCESS) { 276 pj_lock_release(b->lock); 277 return status; 278 } 273 279 } 274 280 … … 278 284 { 279 285 unsigned erase_cnt; 280 281 /* shrink one frame or just the diff? */ 282 //erase_cnt = b->samples_per_frame; 283 erase_cnt = pjmedia_circ_buf_get_len(b->circ_buf) + 284 b->samples_per_frame - b->max_cnt; 285 286 shrink_buffer(b, erase_cnt); 286 287 if (b->wsola) { 288 /* shrink one frame or just the diff? */ 289 //erase_cnt = b->samples_per_frame; 290 erase_cnt = pjmedia_circ_buf_get_len(b->circ_buf) + 291 b->samples_per_frame - b->max_cnt; 292 293 shrink_buffer(b, erase_cnt); 294 } 287 295 288 296 /* Check if shrinking failed or erased count is less than requested, … … 298 306 pjmedia_circ_buf_adv_read_ptr(b->circ_buf, erase_cnt); 299 307 300 PJ_LOG(4,(b->obj_name," Shrinking failed or insufficient, dropping"301 " %d eldest samples, buf_cnt=%d", erase_cnt, 302 308 PJ_LOG(4,(b->obj_name,"%sDropping %d eldest samples, buf_cnt=%d", 309 (b->wsola? "Shrinking failed or insufficient. ": ""), 310 erase_cnt, pjmedia_circ_buf_get_len(b->circ_buf))); 303 311 } 304 312 } … … 313 321 pj_int16_t frame[]) 314 322 { 315 pj_status_t status ;323 pj_status_t status = PJ_SUCCESS; 316 324 317 325 PJ_ASSERT_RETURN(b && frame, PJ_EINVAL); … … 319 327 pj_lock_acquire(b->lock); 320 328 321 update(b, OP_GET); 329 if (b->wsola) 330 update(b, OP_GET); 322 331 323 332 /* Starvation checking */ … … 327 336 pjmedia_circ_buf_get_len(b->circ_buf))); 328 337 329 status = pjmedia_wsola_generate(b->wsola, frame); 330 331 if (status == PJ_SUCCESS) { 332 TRACE__((b->obj_name,"Successfully generate 1 frame")); 333 if (pjmedia_circ_buf_get_len(b->circ_buf) == 0) { 334 pj_lock_release(b->lock); 335 return PJ_SUCCESS; 336 } 337 338 /* Put generated frame into buffer */ 339 pjmedia_circ_buf_write(b->circ_buf, frame, b->samples_per_frame); 340 341 } else { 338 if (b->wsola) { 339 status = pjmedia_wsola_generate(b->wsola, frame); 340 341 if (status == PJ_SUCCESS) { 342 TRACE__((b->obj_name,"Successfully generate 1 frame")); 343 if (pjmedia_circ_buf_get_len(b->circ_buf) == 0) { 344 pj_lock_release(b->lock); 345 return PJ_SUCCESS; 346 } 347 348 /* Put generated frame into buffer */ 349 pjmedia_circ_buf_write(b->circ_buf, frame, 350 b->samples_per_frame); 351 } 352 } 353 354 if (!b->wsola || status != PJ_SUCCESS) { 342 355 unsigned buf_len = pjmedia_circ_buf_get_len(b->circ_buf); 343 356 344 357 /* Give all what delay buffer has, then pad with zeroes */ 345 PJ_LOG(4,(b->obj_name,"Error generating frame, status=%d", 346 status)); 358 if (b->wsola) 359 PJ_LOG(4,(b->obj_name,"Error generating frame, status=%d", 360 status)); 347 361 348 362 pjmedia_circ_buf_read(b->circ_buf, frame, buf_len); … … 379 393 380 394 /* Reset WSOLA */ 381 pjmedia_wsola_reset(b->wsola, 0); 395 if (b->wsola) 396 pjmedia_wsola_reset(b->wsola, 0); 382 397 383 398 pj_lock_release(b->lock); -
pjproject/branches/1.x/pjmedia/src/pjmedia/echo_common.c
r3553 r3567 145 145 { 146 146 unsigned ptime, lat_cnt; 147 unsigned delay_buf_opt = 0; 147 148 pjmedia_echo_state *ec; 148 149 pj_status_t status; … … 212 213 213 214 /* Create delay buffer to compensate drifts */ 215 if (options & PJMEDIA_ECHO_USE_SIMPLE_FIFO) 216 delay_buf_opt |= PJMEDIA_DELAY_BUF_SIMPLE_FIFO; 214 217 status = pjmedia_delay_buf_create(ec->pool, ec->obj_name, clock_rate, 215 218 samples_per_frame, channel_count, 216 219 (PJMEDIA_SOUND_BUFFER_COUNT+1) * ptime, 217 0, &ec->delay_buf);220 delay_buf_opt, &ec->delay_buf); 218 221 if (status != PJ_SUCCESS) { 219 222 pj_pool_release(pool);
Note: See TracChangeset
for help on using the changeset viewer.