Commit 759628cf authored by Simon Morlat's avatar Simon Morlat

merge patch to allow repeated tones.

parent f9fb9465
......@@ -40,6 +40,7 @@ struct _MSDtmfGenCustomTone{
int duration; /**<Duration of the tone in milliseconds*/
int frequency; /**<Frequency of the tone to be played */
float amplitude; /**<Amplitude of the tone, 1.0 being the 0dbm normalized level*/
int interval; /**<Interval 'between tones' in milliseconds*/
};
typedef struct _MSDtmfGenCustomTone MSDtmfGenCustomTone;
......
......@@ -48,6 +48,7 @@ struct DtmfGenState{
int amplitude;
char dtmf;
float default_amplitude;
int interval;
};
typedef struct DtmfGenState DtmfGenState;
......@@ -62,6 +63,7 @@ static void dtmfgen_init(MSFilter *f){
s->silence=0;
s->default_amplitude=0.2;
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 frequency %i Hz, duration=%i, amplitude=%f with interval %i",def->frequency,def->duration,def->amplitude, def->interval);
else
ms_message("Playing tone of frequency %i Hz, duration=%i, amplitude=%f",def->frequency,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->lowfreq=((float)def->freq)/(float)s->rate;
s->highfreq=0;
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->pos<min_duration)
s->dur=min_duration;
else s->dur=0;
s->interval=0;
ms_filter_unlock(f);
return 0;
}
......@@ -220,9 +229,13 @@ static void write_dtmf(DtmfGenState *s , int16_t *sample, int nsamples){
}
if (s->pos>=s->dur){
s->pos=0;
if (s->interval > 0) {
s->silence=s->interval;
} else {
s->dtmf=0;
s->silence=TRAILLING_SILENCE;
}
}
}
static void dtmfgen_process(MSFilter *f){
......@@ -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);
}
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment