如何使用音频单元osx从设备音频输入获取音频

时间:2018-05-08 07:34:48

标签: macos audiounit

我花了很长时间试图弄清楚如何使用音频单元从用户麦克风获取声音,这样我就可以在音频单元录制回调中使用它,但我仍然是堆栈。

- (OSStatus) setupMicInput {
AudioObjectPropertyAddress addr;
UInt32 size = sizeof(AudioDeviceID);
AudioDeviceID deviceID = 0;

addr.mSelector = kAudioHardwarePropertyDefaultInputDevice;
addr.mScope = kAudioObjectPropertyScopeGlobal;
addr.mElement = kAudioObjectPropertyElementMaster;

OSStatus err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &addr, 0, NULL, &size, &deviceID);
checkStatus(err);

if (err == noErr) {
    err = AudioUnitSetProperty(audioUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &deviceID, size);
}

checkStatus(err);

return err;
}

我收到此错误

2018-05-08 10:07:29.454485+0300 OsxSocketSound[1414:20839] [AudioHAL_Client] AudioHardware.cpp:578:AudioObjectGetPropertyDataSize:  AudioObjectGetPropertyDataSize: no object with given ID 0
2018-05-08 10:07:29.454517+0300 OsxSocketSound[1414:20839] 

[AudioHAL_Client] AudioHardware.cpp:666:AudioObjectGetPropertyData:  AudioObjectGetPropertyData: no object with given ID 0
2018-05-08 10:07:29.454715+0300 OsxSocketSound[1414:20839] 

[AudioHAL_Client] AudioHardware.cpp:3446:AudioDeviceSetProperty:  AudioDeviceSetProperty: no device with given ID
2018-05-08 10:07:29.454738+0300 OsxSocketSound[1414:20839] 1610:  ca_verify_noerr: [AudioDeviceSetProperty(mDeviceID, NULL, 0, isInput, kAudioDevicePropertyIOProcStreamUsage, theSize, theStreamUsage), 560227702].

我希望有人可以帮助我一个音频单元的示例并捕获麦克风输入。感谢

1 个答案:

答案 0 :(得分:3)

似乎您的应用程序权利设置不正确。在功能选项卡下,您应该检查麦克风。请检查一次。