如何使用音频单元从设备音频输入获取音频 osx
How to get audio from device audio input using audio unit osx
我花了很长时间试图弄清楚如何使用音频单元从用户麦克风中获取声音,以便我可以在音频单元录音回叫中使用它,但我仍然在堆栈中。
- (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].
我希望有人能帮我举一个音频单元和捕捉麦克风输入的例子。谢谢
看来,您的应用权限设置不正确。在功能选项卡下,您应该检查麦克风。请检查一次。
我花了很长时间试图弄清楚如何使用音频单元从用户麦克风中获取声音,以便我可以在音频单元录音回叫中使用它,但我仍然在堆栈中。
- (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].
我希望有人能帮我举一个音频单元和捕捉麦克风输入的例子。谢谢
看来,您的应用权限设置不正确。在功能选项卡下,您应该检查麦克风。请检查一次。