Commit 6bb66064 authored by smorlat's avatar smorlat

fix bugs in dtmf generator, ios audio unit, and allow setting of dtmf amplitude.

parent 0fc8db73
......@@ -47,6 +47,9 @@ typedef struct _MSDtmfGenCustomTone MSDtmfGenCustomTone;
/**Play a custom tone according to the supplied tone description*/
#define MS_DTMF_GEN_PLAY_CUSTOM MS_FILTER_METHOD(MS_DTMF_GEN_ID,3,MSDtmfGenCustomTone)
/**Sets default amplitude for dtmfs, expressed in the 0..1 range*/
#define MS_DTMF_GEN_SET_DEFAULT_AMPLITUDE MS_FILTER_METHOD(MS_DTMF_GEN_ID,4,float)
/**
* Structure carried by MS_DTMF_GEN_EVENT
......
......@@ -622,7 +622,9 @@ RingStream * ring_start_with_cb(const char *file,int interval,MSSndCard *sndcard
ms_filter_call_method(stream->source,MS_FILTER_GET_NCHANNELS,&tmp);
ms_filter_call_method(stream->gendtmf,MS_FILTER_SET_NCHANNELS,&tmp);
ms_filter_call_method(stream->sndwrite,MS_FILTER_SET_NCHANNELS,&tmp);
stream->ticker=ms_ticker_new();
ms_ticker_set_name(stream->ticker,"Audio (ring) MSTicker");
ms_connection_helper_start(&h);
......@@ -632,6 +634,7 @@ RingStream * ring_start_with_cb(const char *file,int interval,MSSndCard *sndcard
ms_connection_helper_link(&h,stream->write_resampler,0,0);
ms_connection_helper_link(&h,stream->sndwrite,0,-1);
ms_ticker_attach(stream->ticker,stream->source);
return stream;
}
......
......@@ -36,7 +36,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define TRAILLING_SILENCE 500 /*ms*/
#endif
static const int default_amplitude=10000;
struct DtmfGenState{
int rate;
......@@ -48,6 +47,7 @@ struct DtmfGenState{
int silence;
int amplitude;
char dtmf;
float default_amplitude;
};
typedef struct DtmfGenState DtmfGenState;
......@@ -60,7 +60,8 @@ static void dtmfgen_init(MSFilter *f){
s->dtmf=0;
s->nosamples_time=0;
s->silence=0;
s->amplitude=default_amplitude;
s->default_amplitude=0.5;
s->amplitude=(s->default_amplitude*0.7*32767);
f->data=s;
}
......@@ -71,7 +72,7 @@ static void dtmfgen_uninit(MSFilter *f){
static int dtmfgen_put(MSFilter *f, void *arg){
DtmfGenState *s=(DtmfGenState*)f->data;
const char *dtmf=(char*)arg;
s->pos=0;
switch(dtmf[0]){
case '0':
s->lowfreq=941;
......@@ -136,17 +137,22 @@ static int dtmfgen_put(MSFilter *f, void *arg){
case 'D':
s->lowfreq=941;
s->highfreq=1633;
break;
break;
case ' ':
/*ignore*/
return 0;
break;
default:
ms_warning("Not a dtmf key.");
return -1;
}
ms_filter_lock(f);
s->pos=0;
s->lowfreq=s->lowfreq/s->rate;
s->highfreq=s->highfreq/s->rate;
s->dur=s->rate/10; /*100 ms duration */
s->silence=0;
s->amplitude=default_amplitude;
s->amplitude=s->default_amplitude*32767*0.7;
s->dtmf=dtmf[0];
ms_filter_unlock(f);
return 0;
......@@ -196,6 +202,12 @@ static int dtmfgen_set_rate(MSFilter *f, void *arg){
return 0;
}
static int dtmfgen_set_amp(MSFilter *f, void *arg){
DtmfGenState *s=(DtmfGenState*)f->data;
s->default_amplitude=*(float*)arg;
return 0;
}
static void write_dtmf(DtmfGenState *s , int16_t *sample, int nsamples){
int i;
......@@ -263,6 +275,7 @@ MSFilterMethod dtmfgen_methods[]={
{ MS_DTMF_GEN_START , dtmfgen_start },
{ MS_DTMF_GEN_STOP , dtmfgen_stop },
{ MS_DTMF_GEN_PLAY_CUSTOM, dtmfgen_play_tone },
{ MS_DTMF_GEN_SET_DEFAULT_AMPLITUDE, dtmfgen_set_amp },
{ 0 , NULL }
};
......
......@@ -21,6 +21,7 @@
#include <AudioToolbox/AudioToolbox.h>
#include "mediastreamer2/mssndcard.h"
#include "mediastreamer2/msfilter.h"
#include "mediastreamer2/msticker.h"
#define PREFERRED_HW_SAMPLE_RATE 44100
......@@ -215,6 +216,9 @@ static OSStatus au_render_cb (
AUData *d=(AUData*)inRefCon;
if (d->write_started == TRUE) {
ioData->mBuffers[0].mDataByteSize=inNumberFrames*d->bits/8;
ioData->mNumberBuffers=1;
ms_mutex_lock(&d->mutex);
if(ms_bufferizer_get_avail(d->bufferizer) >= inNumberFrames*d->bits/8) {
ms_bufferizer_read(d->bufferizer, ioData->mBuffers[0].mData, inNumberFrames*d->bits/8);
......@@ -223,29 +227,27 @@ static OSStatus au_render_cb (
ms_debug("we are late, bufferizer sise is %i bytes in framezize is %i bytes",ms_bufferizer_get_avail(d->bufferizer),inNumberFrames*d->bits/8);
ms_bufferizer_flush(d->bufferizer);
}
ioData->mBuffers[0].mDataByteSize=inNumberFrames*d->bits/8;
ms_mutex_unlock(&d->mutex);
} else {
ms_mutex_unlock(&d->mutex);
memset(ioData->mBuffers[0].mData, 0,ioData->mBuffers[0].mDataByteSize);
ms_debug("nothing to write, pushing silences, bufferizer sise is %i bytes in framezize is %i bytes mDataByteSize %i"
ms_debug("nothing to write, pushing silences, bufferizer size is %i bytes in framezize is %i bytes mDataByteSize %i"
,ms_bufferizer_get_avail(d->bufferizer)
,inNumberFrames*d->bits/8
,ioData->mBuffers[0].mDataByteSize);
d->n_lost_frame+=inNumberFrames;
}
if (!d->is_ringer) { // no need to read in ringer mode
AudioBufferList readAudioBufferList;
readAudioBufferList.mBuffers[0].mDataByteSize=inNumberFrames*d->bits/8;
readAudioBufferList.mNumberBuffers=1;
readAudioBufferList.mBuffers[0].mData=NULL;
readAudioBufferList.mBuffers[0].mNumberChannels=d->nchannels;
AudioUnitElement inputBus = 1;
au_read_cb(d, ioActionFlags, inTimeStamp, inputBus, inNumberFrames, &readAudioBufferList);
}
}
if (!d->is_ringer) { // no need to read in ringer mode
AudioBufferList readAudioBufferList;
readAudioBufferList.mBuffers[0].mDataByteSize=inNumberFrames*d->bits/8;
readAudioBufferList.mNumberBuffers=1;
readAudioBufferList.mBuffers[0].mData=NULL;
readAudioBufferList.mBuffers[0].mNumberChannels=d->nchannels;
AudioUnitElement inputBus = 1;
au_read_cb(d, ioActionFlags, inTimeStamp, inputBus, inNumberFrames, &readAudioBufferList);
}
return 0;
}
......@@ -261,12 +263,15 @@ static void au_configure(AUData *d) {
UInt32 doNotSetProperty = 0;
auresult = AudioSessionSetActive(true);
check_auresult(auresult,"AudioSessionSetActive");
UInt32 audioCategory =kAudioSessionCategory_PlayAndRecord;
auresult =AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(audioCategory), &audioCategory);
check_auresult(auresult,"Configuring audio session ");
if (d->is_ringer) {
auresult=AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryDefaultToSpeaker,sizeof (doSetProperty),&doSetProperty);
......@@ -502,7 +507,7 @@ static void au_unconfigure_write(AUData *d){
kAudioUnitScope_Global,
outputBus);
}
ms_message("[%i] frames of silence inserted for [%i] ms",d->n_lost_frame,(d->n_lost_frame*1000)/d->rate);
ms_message("[%i] frames of silence inserted for [%i] ms.",d->n_lost_frame,(d->n_lost_frame*1000)/d->rate);
au_unconfigure(d);
ms_mutex_lock(&d->mutex);
ms_bufferizer_flush(d->bufferizer);
......@@ -529,11 +534,9 @@ static void au_read_postprocess(MSFilter *f){
static void au_read_process(MSFilter *f){
AUData *d=(AUData*)((MSSndCard*)f->data)->data;
mblk_t *m;
struct timeval tv;
if (d->io_unit_must_be_started) {
gettimeofday(&tv, 0);
if ((tv.tv_usec % 10) == 0) { /*more or less every 100ms*/
if (f->ticker->time % 100 == 0) { /*more or less every 100ms*/
if (AudioOutputUnitStart(d->io_unit) == 0) {
d->io_unit_must_be_started=FALSE;
};
......
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