Changeset 648 for pjproject/trunk/pjmedia/src/pjmedia/aec_speex.c
- Timestamp:
- Aug 4, 2006 6:27:19 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/aec_speex.c
r646 r648 27 27 #include <pj/pool.h> 28 28 #include <speex/speex_echo.h> 29 #include <speex/speex_preprocess.h> 29 30 30 31 31 32 #define THIS_FILE "aec_speex.c" 32 #define BUF_COUNT 1633 #define BUF_COUNT 8 33 34 34 35 … … 40 41 struct pjmedia_aec 41 42 { 42 SpeexEchoState *state; 43 SpeexEchoState *state; 44 SpeexPreprocessState *preprocess; 45 43 46 unsigned samples_per_frame; 44 47 unsigned options; 45 48 pj_int16_t *tmp_frame; 49 spx_int32_t *residue; 46 50 47 51 pj_lock_t *lock; /* To protect buffers, if required */ … … 60 64 unsigned clock_rate, 61 65 unsigned samples_per_frame, 62 unsigned tail_ size,66 unsigned tail_ms, 63 67 unsigned options, 64 68 pjmedia_aec **p_aec ) … … 69 73 pj_status_t status; 70 74 75 *p_aec = NULL; 76 71 77 aec = pj_pool_zalloc(pool, sizeof(pjmedia_aec)); 72 78 PJ_ASSERT_RETURN(aec != NULL, PJ_ENOMEM); … … 79 85 aec->options = options; 80 86 81 aec->state = speex_echo_state_init(samples_per_frame,tail_size); 87 aec->state = speex_echo_state_init(samples_per_frame, 88 clock_rate * tail_ms / 1000); 82 89 if (aec->state == NULL) { 90 pj_lock_destroy(aec->lock); 91 return PJ_ENOMEM; 92 } 93 94 aec->preprocess = speex_preprocess_state_init(samples_per_frame, 95 clock_rate); 96 if (aec->preprocess == NULL) { 97 speex_echo_state_destroy(aec->state); 83 98 pj_lock_destroy(aec->lock); 84 99 return PJ_ENOMEM; … … 91 106 92 107 /* Create temporary frame for echo cancellation */ 93 aec->tmp_frame = pj_pool_zalloc(pool, sizeof(pj_int16_t) * 108 aec->tmp_frame = pj_pool_zalloc(pool, 2 * samples_per_frame); 109 PJ_ASSERT_RETURN(aec->tmp_frame != NULL, PJ_ENOMEM); 110 111 /* Create temporary frame to receive residue */ 112 aec->residue = pj_pool_zalloc(pool, sizeof(spx_int32_t) * 94 113 samples_per_frame); 95 PJ_ASSERT_RETURN(aec-> tmp_frame != NULL, PJ_ENOMEM);114 PJ_ASSERT_RETURN(aec->residue != NULL, PJ_ENOMEM); 96 115 97 116 /* Create internal playback buffers */ … … 109 128 clock_rate, 110 129 samples_per_frame, 111 tail_ size * 1000 / clock_rate));130 tail_ms)); 112 131 return PJ_SUCCESS; 113 132 … … 121 140 { 122 141 PJ_ASSERT_RETURN(aec && aec->state, PJ_EINVAL); 142 143 if (aec->lock) 144 pj_lock_acquire(aec->lock); 123 145 124 146 if (aec->state) { 125 147 speex_echo_state_destroy(aec->state); 126 148 aec->state = NULL; 149 } 150 151 if (aec->preprocess) { 152 speex_preprocess_state_destroy(aec->preprocess); 153 aec->preprocess = NULL; 127 154 } 128 155 … … 225 252 void *reserved ) 226 253 { 227 unsigned level0, level1;228 229 254 /* Sanity checks */ 230 255 PJ_ASSERT_RETURN(aec && rec_frm && play_frm && options==0 && … … 234 259 speex_echo_cancel(aec->state, (const spx_int16_t*)rec_frm, 235 260 (const spx_int16_t*)play_frm, 236 (spx_int16_t*)aec->tmp_frame, NULL); 237 238 #if 0 239 level0 = pjmedia_calc_avg_signal(rec_frm, aec->samples_per_frame); 240 level1 = pjmedia_calc_avg_signal(aec->tmp_frame, aec->samples_per_frame); 241 242 if (level1 < level0) { 243 PJ_LOG(5,(THIS_FILE, "Input signal reduced from %d to %d", 244 level0, level1)); 245 } 246 #else 247 PJ_UNUSED_ARG(level0); 248 PJ_UNUSED_ARG(level1); 249 #endif 261 (spx_int16_t*)aec->tmp_frame, 262 aec->residue); 263 264 265 /* Preprocess output */ 266 speex_preprocess(aec->preprocess, (spx_int16_t*)aec->tmp_frame, 267 aec->residue); 250 268 251 269 /* Copy temporary buffer back to original rec_frm */
Note: See TracChangeset
for help on using the changeset viewer.