Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Iphone audiounit problem
-(int) initAudioSession{
AudioComponentDescription desc;
AudioUnitElement inputBus = 1;
AudioUnitElement outputBus = 0;
gdgdtg
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_VoiceProcessingIO;
// desc.componentSubType = kAudioUnitSubType_RemoteIO;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
voiceUnitComponent = AudioComponentFindNext(NULL, &desc);
if(voiceUnitComponent == NULL)
{
NSLog(@"Unable to find voice unit audio component!");
return -1;
}
OSStatus conf_status = AudioComponentInstanceNew(voiceUnitComponent, &(self->voiceUnit));
if(conf_status != noErr)
{
NSLog(@"Unable to create the AudioUnit!");
return -1;
}
UInt32 flag = 1;
conf_status = AudioUnitSetProperty(voiceUnit,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Input,
inputBus,
&flag,
sizeof(flag));
if(conf_status != noErr)
{
NSLog(@"Unable to set audiosession state to Active");
return -32;
}
// Enable IO for playback
conf_status = AudioUnitSetProperty(voiceUnit,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Output,
outputBus,
&flag,
sizeof(flag));
if(conf_status != noErr)
{
NSLog(@"Unable to set audiosession state to Active");
return -32;
}
streamDesc.mSampleRate = SAMPLE_RATE;
streamDesc.mFormatID = kAudioFormatALaw;
conf_status = AudioUnitSetProperty(voiceUnit, // The audio unit to set property value for
kAudioUnitProperty_StreamFormat, // The audio unit property identifier
kAudioUnitScope_Output, // The audio unit scope for the property
inputBus, // The audio unit element for the property
&(streamDesc), // The value to apply to the property
sizeof(streamDesc)); // The size of the value
if(conf_status != noErr)
{
NSLog(@"Unable to set the AudioUnit properties on the inputstream!");
return -2;
}
conf_status = AudioUnitInitialize(voiceUnit);
if(conf_status != noErr)
{
NSLog(@"Unable to initialize the AudioUnit");
return -4;
}
conf_status = AudioUnitSetProperty(voiceUnit, // The audio unit to set property value for
kAudioUnitProperty_StreamFormat, // The audio unit property identifier
kAudioUnitScope_Input, // The audio unit scope for the property
outputBus, // The audio unit element for the property
&(streamDesc), // The value to apply to the property
sizeof(streamDesc)); // The size of the value
if(conf_status != noErr)
{
NSLog(@"Unable to initialize the AudioUnit on the output stream");
return -8;
}
AURenderCallbackStruct outputBusRenderCallbackStruct;
outputBusRenderCallbackStruct.inputProc = outputBusRenderCallack;
outputBusRenderCallbackStruct.inputProcRefCon = self;
conf_status = AudioUnitSetProperty(voiceUnit, // The audio unit to set property value for
kAudioUnitProperty_SetRenderCallback, // The audio unit property identifier
kAudioUnitScope_Input, // The audio unit scope for the property
outputBus, // The audio unit element for the property
&outputBusRenderCallbackStruct, // The value to apply to the property
sizeof(outputBusRenderCallbackStruct)); // The size of the value
if(conf_status != noErr)
{
NSLog(@"Unable to set callback for output");
return -16;
}
AURenderCallbackStruct inputBusRenderCallbackStruct;
inputBusRenderCallbackStruct.inputProc = inputBusInputCallback;
inputBusRenderCallbackStruct.inputProcRefCon = self;
conf_status = AudioUnitSetProperty(voiceUnit, // The audio unit to set property value for
kAudioOutputUnitProperty_SetInputCallback, // The audio unit property identifier
kAudioUnitScope_Output, // The audio unit scope for the property
inputBus, // The audio unit element for the property
&inputBusRenderCallbackStruct, // The value to apply to the property
sizeof(inputBusRenderCallbackStruct)); // The size of the value
if(conf_status != noErr)
{
NSLog(@"Unable to set callback for output");
return -32;
}
NSLog(@"init audiounit complete");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.