我正在开发一个音频捕获申请。 • 如何使用8千赫取样率,利用音像股APIC,以单一芯片捕捉MacOS X的录音?
这是我所尝试的法典。
Component component;
ComponentDescription description;
OSStatus err = noErr;
UInt32 param;
AURenderCallbackStruct callback;
description.componentType = kAudioUnitType_Output;
description.componentSubType = kAudioUnitSubType_HALOutput;
description.componentManufacturer = kAudioUnitManufacturer_Apple;
description.componentFlags = 0;
description.componentFlagsMask = 0;
if(component = FindNextComponent(NULL, &description))
{
err = OpenAComponent(component, &fAudioUnit);
if(err != noErr)
{
fAudioUnit = NULL;
return err;
}
}
param = 1;
err = AudioUnitSetProperty(fAudioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, ¶m, sizeof(UInt32));
if(err == noErr)
{
param = 0;
err = AudioUnitSetProperty(fAudioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, 0, ¶m, sizeof(UInt32));
}
param = sizeof(AudioDeviceID);
err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice, ¶m, &fInputDeviceID);
if(err != noErr)
{
fprintf(stderr, "failed to get default input device
");
return err;
}
err = AudioUnitSetProperty(fAudioUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &fInputDeviceID, sizeof(AudioDeviceID));
if(err != noErr)
{
fprintf(stderr, "failed to set AU input device
");
return err;
}
callback.inputProc = AudioInputProc;
callback.inputProcRefCon = NULL;
err = AudioUnitSetProperty(fAudioUnit, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global, 0, &callback, sizeof(AURenderCallbackStruct));
param = sizeof(AudioStreamBasicDescription);
err = AudioUnitGetProperty(fAudioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &fDeviceFormat, ¶m);
if(err != noErr)
{
printf("failed to get input device ASBD
");
return err;
}
fDeviceFormat.mSampleRate = 8000.0;
fDeviceFormat.mChannelsPerFrame = 1;
fDeviceFormat.mBitsPerChannel = 16;
fDeviceFormat.mFormatID = kAudioFormatLinearPCM;
fDeviceFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
err = AudioUnitSetProperty(fAudioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &fDeviceFormat, sizeof(AudioStreamBasicDescription));
if(err != noErr)
{
printf( "failed to set input device ASBD= %4.4s
",(char *)&err);
if(err == kAudioUnitErr_FormatNotSupported)
{
printf("kAudioUnitErr_FormatNotSupported
");
}
return err;
}
err = AudioUnitGetProperty(fAudioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &fDeviceFormat, ¶m);
if(err != noErr)
{
printf( "failed to get input device ASBD
");
return err;
}
param = sizeof(UInt32);
err = AudioUnitGetProperty(fAudioUnit, kAudioDevicePropertyBufferFrameSize, kAudioUnitScope_Global, 0, &fAudioSamples, ¶m);
if(err != noErr)
{
fprintf(stderr, "failed to get audio sample size
");
return err;
}
err = AudioUnitInitialize(fAudioUnit);
if(err != noErr)
{
fprintf(stderr, "failed to initialize AU
");
return err;
}
在此,我无法将取样率和每样样本的比照率从32个改为16个。 请帮助我这样做。
增资 在这方面。