Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Iphone audiounit problem

View audiounitproblem.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
-(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.