Changeset 1333:986b64dde6be in mediastreamer2
- Timestamp:
- Mar 31, 2011 10:33:27 AM (2 years ago)
- Branch:
- default
- Children:
- 1334:27399177e928, 1336:afbd05489f6e
- File:
-
- 1 edited
-
src/speexec.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/speexec.c
r1332 r1333 31 31 #include <malloc.h> /* for alloca */ 32 32 #endif 33 34 typedef struct _AudioFlowController{ 35 int target_samples; 36 int total_samples; 37 int current_pos; 38 int current_dropped; 39 }AudioFlowController; 40 41 void audio_flow_controller_init(AudioFlowController *ctl){ 42 ctl->target_samples=0; 43 ctl->total_samples=0; 44 ctl->current_pos=0; 45 ctl->current_dropped=0; 46 } 47 48 void audio_flow_controller_set_target(AudioFlowController *ctl, int samples_to_drop, int total_samples){ 49 ctl->target_samples=samples_to_drop; 50 ctl->total_samples=total_samples; 51 ctl->current_pos=0; 52 ctl->current_dropped=0; 53 } 54 55 mblk_t * audio_flow_controller_process(AudioFlowController *ctl, mblk_t *m){ 56 if (ctl->total_samples>0 && ctl->target_samples>0){ 57 int nsamples=(m->b_wptr-m->b_rptr)/2; 58 int th_dropped; 59 int todrop; 60 61 ctl->current_pos+=nsamples; 62 th_dropped=(ctl->target_samples*ctl->current_pos)/ctl->total_samples; 63 todrop=th_dropped-ctl->current_dropped; 64 if (todrop>0){ 65 if (todrop>nsamples) todrop=nsamples; 66 m->b_wptr-=todrop*2; 67 //ms_message("th_dropped=%i, current_dropped=%i, %i samples dropped.",th_dropped,ctl->current_dropped,todrop); 68 ctl->current_dropped+=todrop; 69 } 70 } 71 return m; 72 } 73 33 74 34 75 //#define EC_DUMP 1 … … 41 82 static const float smooth_factor=0.05; 42 83 static const int framesize=128; 84 static const int flow_control_interval_ms=5000; 43 85 44 86 … … 55 97 int nominal_ref_samples; 56 98 int min_ref_samples; 99 AudioFlowController afc; 57 100 #ifdef EC_DUMP 58 101 FILE *echofile; … … 131 174 s->min_ref_samples=-1; 132 175 s->nominal_ref_samples=delay_samples; 176 audio_flow_controller_init(&s->afc); 133 177 } 134 178 … … 156 200 if (f->inputs[0]!=NULL){ 157 201 while((refm=ms_queue_get(f->inputs[0]))!=NULL){ 158 mblk_t *cp=dupmsg( refm);202 mblk_t *cp=dupmsg(audio_flow_controller_process(&s->afc,refm)); 159 203 ms_bufferizer_put(&s->delayed_ref,cp); 160 204 ms_queue_put(f->outputs[0],refm); … … 176 220 refm->b_wptr+=nbytes; 177 221 ms_bufferizer_put(&s->delayed_ref,refm); 222 ms_queue_put(f->outputs[0],dupmsg(refm)); 178 223 if (!s->using_zeroes){ 179 224 ms_warning("Not enough ref samples, using zeroes"); … … 211 256 212 257 /*verify our ref buffer does not become too big, meaning that we are receiving more samples than we are sending*/ 213 if (f->ticker->time % 5000== 0 && s->min_ref_samples!=-1){258 if (f->ticker->time % flow_control_interval_ms == 0 && s->min_ref_samples!=-1){ 214 259 int diff=s->min_ref_samples-s->nominal_ref_samples; 215 260 if (diff>nbytes){ 216 int purge= diff-(nbytes/2);217 ms_warning("echo canceller: we are accumulating too much reference signal, purging now %i bytes",purge);218 ms_bufferizer_skip_bytes(&s->delayed_ref,purge);261 int purge=(diff-(nbytes/2))/2; 262 ms_warning("echo canceller: we are accumulating too much reference signal, need to throw out %i samples",purge); 263 audio_flow_controller_set_target(&s->afc,purge,(flow_control_interval_ms*s->samplerate)/1000); 219 264 } 220 265 s->min_ref_samples=-1;
Note: See TracChangeset
for help on using the changeset viewer.
