From 54b15bc41f8d7eb582516cd207b6d712cfd32d92 Mon Sep 17 00:00:00 2001 From: Valentin Date: Tue, 30 Aug 2011 19:09:17 +0200 Subject: [PATCH] Implementation of notifications and dtmf tones systems --- include/mediastreamer2/dtmfgen.h | 4 +++- src/dtmfgen.c | 30 +++++++++++++++++++++++------- tests/tones.c | 6 ++++-- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/include/mediastreamer2/dtmfgen.h b/include/mediastreamer2/dtmfgen.h index 17a89fb..cea83ba 100644 --- a/include/mediastreamer2/dtmfgen.h +++ b/include/mediastreamer2/dtmfgen.h @@ -38,7 +38,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. **/ struct _MSDtmfGenCustomTone{ int duration; /**silence=0; s->default_amplitude=0.5; s->amplitude=(s->default_amplitude*0.7*32767); + s->interval=0; f->data=s; } @@ -154,6 +156,7 @@ static int dtmfgen_put(MSFilter *f, void *arg){ s->silence=0; s->amplitude=s->default_amplitude*32767*0.7; s->dtmf=dtmf[0]; + s->interval=0; ms_filter_unlock(f); return 0; } @@ -161,15 +164,19 @@ static int dtmfgen_put(MSFilter *f, void *arg){ static int dtmfgen_play_tone(MSFilter *f, void *arg){ DtmfGenState *s=(DtmfGenState*)f->data; MSDtmfGenCustomTone *def=(MSDtmfGenCustomTone*)arg; - ms_message("Playing tone of frequency %i, duration=%i, amplitude=%f",def->frequency,def->duration,def->amplitude); + if (def->interval > 0) + ms_message("Playing tones of frequencies %i - %i, duration=%i, amplitude=%f with interval %i",def->lowfreq,def->highfreq,def->duration,def->amplitude, def->interval); + else + ms_message("Playing tone of frequencies %i - %i, duration=%i, amplitude=%f",def->lowfreq,def->highfreq,def->duration,def->amplitude); ms_filter_lock(f); s->pos=0; s->dur=(s->rate*def->duration)/1000; - s->lowfreq=((float)def->frequency)/(float)s->rate; - s->highfreq=0; + s->lowfreq=((float)def->lowfreq)/(float)s->rate; + s->highfreq=((float)def->highfreq)/(float)s->rate; s->silence=0; s->amplitude=((float)def->amplitude)* 0.7*32767.0; s->dtmf='?'; + s->interval=def->interval; ms_filter_unlock(f); return 0; @@ -179,6 +186,7 @@ static int dtmfgen_start(MSFilter *f, void *arg){ if (dtmfgen_put(f,arg)==0){ DtmfGenState *s=(DtmfGenState*)f->data; s->dur=5*s->rate; + s->interval=0; return 0; } return -1; @@ -191,6 +199,7 @@ static int dtmfgen_stop(MSFilter *f, void *arg){ if (s->posdur=min_duration; else s->dur=0; + s->interval=0; ms_filter_unlock(f); return 0; } @@ -220,8 +229,12 @@ static void write_dtmf(DtmfGenState *s , int16_t *sample, int nsamples){ } if (s->pos>=s->dur){ s->pos=0; - s->dtmf=0; - s->silence=TRAILLING_SILENCE; + if (s->interval > 0) { + s->silence=s->interval; + } else { + s->dtmf=0; + s->silence=TRAILLING_SILENCE; + } } } @@ -257,9 +270,12 @@ static void dtmfgen_process(MSFilter *f){ } }else{ s->nosamples_time=0; - s->silence=0; + if (s->interval > 0) { + s->silence-=f->ticker->interval; + if (s->silence<0) s->silence=0; + } else s->silence=0; while((m=ms_queue_get(f->inputs[0]))!=NULL){ - if (s->dtmf!=0){ + if (s->dtmf!=0 && s->silence==0){ nsamples=(m->b_wptr-m->b_rptr)/2; write_dtmf(s, (int16_t*)m->b_rptr,nsamples); } diff --git a/tests/tones.c b/tests/tones.c index 5008147..5a2c94a 100644 --- a/tests/tones.c +++ b/tests/tones.c @@ -64,7 +64,8 @@ int main(int argc, char *argv[]){ MSToneDetectorDef expected_tone; char dtmf='*'; - tone.frequency=2000; + tone.lowfreq=2000; + tone.highfreq=0; tone.duration=400; tone.amplitude=0.6; @@ -85,7 +86,8 @@ int main(int argc, char *argv[]){ ms_sleep(1); ms_filter_call_method(gen,MS_DTMF_GEN_PLAY_CUSTOM,&tone); ms_sleep(1); - tone.frequency=1500; + tone.lowfreq=1500; + tone.highfreq=0; tone.amplitude=1.0; ms_filter_call_method(gen,MS_DTMF_GEN_PLAY_CUSTOM,&tone); ms_sleep(1); -- 1.7.5.4