Commit 8282f57f authored by Simon Morlat's avatar Simon Morlat

start porting audio unit filter to mac

parent 6f0c042a
......@@ -128,6 +128,9 @@ static MSSndCard *au_duplicate(MSSndCard *obj){
}
#define check_auresult(au,method) \
if (au!=0) ms_error("AudioUnit error for %s: ret=%i",method,au)
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
static void au_interuption_listener(void* inClientData, UInt32 inInterruptionState) {
if (((MSSndCard*)inClientData)->data == NULL) return;
......@@ -153,21 +156,31 @@ static void au_interuption_listener(void* inClientData, UInt32 inInterruptionSta
}
}
#endif
static MSSndCard *au_card_new(const char* name){
MSSndCard *card=ms_snd_card_new_with_name(&au_card_desc,name);
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
OSStatus auresult = AudioSessionInitialize(NULL, NULL, au_interuption_listener, card);
if (auresult != kAudioSessionAlreadyInitialized) {
check_auresult(auresult,"AudioSessionInitialize");
}
#endif
return card;
}
static void au_detect(MSSndCardManager *m){
MSSndCard *card;
ms_debug("au_detect");
MSSndCard *card=au_card_new(AU_CARD_RECEIVER);
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
card=au_card_new(AU_CARD_RECEIVER);
ms_snd_card_manager_add_card(m,card);
card=au_card_new(AU_CARD_SPEAKER);
ms_snd_card_manager_add_card(m,card);
#else
card=au_card_new("Audio Unit");
#endif
ms_snd_card_manager_add_card(m,card);
}
static OSStatus au_read_cb (
......@@ -263,7 +276,7 @@ static void au_configure(AUData *d) {
UInt32 doNotSetProperty = 0;
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
auresult = AudioSessionSetActive(true);
check_auresult(auresult,"AudioSessionSetActive");
......@@ -280,13 +293,19 @@ static void au_configure(AUData *d) {
} else {
ms_message("Configuring audio session default route to receiver");
}
#endif
if (d->started == TRUE) {
//nothing else to do
return;
}
au_description.componentType = kAudioUnitType_Output;
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
au_description.componentSubType = kAudioUnitSubType_VoiceProcessingIO;
#else
au_description.componentSubType = kAudioUnitSubType_HALOutput;
#endif
au_description.componentManufacturer = kAudioUnitManufacturer_Apple;
au_description.componentFlags = 0;
au_description.componentFlagsMask = 0;
......@@ -382,6 +401,7 @@ static void au_configure(AUData *d) {
);
check_auresult(auresult,"kAudioUnitProperty_SetRenderCallback,kAudioUnitScope_Input");
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
const Float64 preferredSampleRate = d->rate;//PREFERRED_HW_SAMPLE_RATE; /*optimum to minimize delay, must put a software resampler to deal with 8khz*/
auresult=AudioSessionSetProperty(kAudioSessionProperty_PreferredHardwareSampleRate
......@@ -406,6 +426,7 @@ static void au_configure(AUData *d) {
if (auresult != 0) ms_message("kAudioSessionProperty_PreferredHardwareIOBufferDuration returns %i ",auresult);
#endif
Float64 delay;
UInt32 delaySize = sizeof(delay);
......@@ -428,6 +449,8 @@ static void au_configure(AUData *d) {
ms_message("I/O unit latency [%f], quality [%i]",delay,quality);
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
Float32 hwoutputlatency;
UInt32 hwoutputlatencySize=sizeof(hwoutputlatency);
auresult=AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareOutputLatency
......@@ -452,6 +475,11 @@ static void au_configure(AUData *d) {
,&hwsamplerate);
ms_message("current hw output latency [%f] input [%f] iobuf[%f] sample rate [%f]",hwoutputlatency,hwinputlatency,hwiobuf,hwsamplerate);
#else
auresult=AudioUnitInitialize(d->io_unit);
check_auresult(auresult,"AudioUnitInitialize");
#endif
auresult=AudioOutputUnitStart(d->io_unit);
check_auresult(auresult,"AudioOutputUnitStart");
d->started=TRUE;
......@@ -666,4 +694,5 @@ void ms_au_register_card() {
* register audio unit plugin should be move to linphone code
*/
ms_snd_card_manager_register_desc(ms_snd_card_manager_get(),&au_card_desc);
}
}
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