1 使用audiounit声音采集和播放;采集和播放函数,尤其是format之类的最好一起设置;否则会出如下问题,如果采集端和播放端使用的是同一个unit,只配置了该unit的采集部分的属性
[auvp] AUVPAggregate.cpp:1538:Initialize: client-side input and output formats do not match (err=-10875) [auvp] AUVPAggregate.cpp:1572:Initialize: err=-10875 [auvp] AUVPAggregate.cpp:1603:Start: start called on uninitialized unit (err=-10867) [avas] AVAudioSession_MacOS.mm:258:-[AVAudioSession getChannelsFromAU:PortName:PortID:]: ERROR in getting channel layout for auScope 1768845428 element 1 [avas] AVAudioSession_MacOS.mm:258:-[AVAudioSession getChannelsFromAU:PortName:PortID:]: ERROR in getting channel layout for auScope 1869968496 element 0 [avas]AVAudioSession_MacOS.mm:258:-[AVAudioSession getChannelsFromAU:PortName:PortID:]: ERROR in getting channel layout for auScope 1768845428 element 1 ERROR in getting channel layout for auScope 1768845428 element 1 [avas] AVAudioSession_MacOS.mm:258:-[AVAudioSession getChannelsFromAU:PortName:PortID:]: ERROR in getting channel layout for auScope 1869968496 element 0
2 iOS中使用了audiosession,如果用这个代码编译catalyst,可以用session设置如下属性
NSError *error = nil; AVAudioSession *se_Instance = [AVAudioSession sharedInstance]; AVAudioSessionCategory category = AVAudioSessionCategoryPlayAndRecord; AVAudioSessionMode mode = AVAudioSessionModeDefault; AVAudioSessionCategoryOptions options = AVAudioSessionCategoryOptionAllowBluetooth |AVAudioSessionCategoryOptionDefaultToSpeaker; [se_Instance setCategory:category mode:mode options:options error:&error]; [se_Instance setActive:YES error:&error]; if (error) { NSLog(@" setActive, error = %@", error); } }
但是AudioSessionGetProperty这个函数的使用可能会报错,说当前系统不存在或者不支持该函数;那就不要用;
3 如果使用了augraph,并且使用的通知函数进行回调(AudioUnitRenderNotify;)这个函数可能大概率是不会触发的,即便你设置都没有任何错误;所以建议使用property设置的简单采集播放回调;
4 相关博文;见结尾的错误总结
Using the kAudioOutputUnitProperty_CurrentDevice property with the Apple Voice Processing I/O audio unit ( kAudioUnitSubType_VoiceProcessingIO ) on macOS can trip you up if you don't follow these guidelines: The kAudioOutputUnitProperty_CurrentDevice property allows you to select the audio device being used by the I/O unit. @constant kAudioOutputUnitProperty_CurrentDevice Global Scope Value Type: AudioObjectID Access: read/write When using the this property to select an audio device used by the Voice Processing I/O unit on macOS, the following guidelines should be observed: A) Both input and output busses must be enabled. B) The property must be set before initializing the audio unit. C) The property must be set on global scope ( kAudioUnitScope_Global ). D) You must set the desired input device by setting this property on the input element/bus. AudioUnitSetProperty(theVoiceIO, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 1, &deviceID, sizeof(AudioDeviceID)); You must set the desired output device by setting the property on the output element/bus. AudioUnitSetProperty(theVoiceIO, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &deviceID, sizeof(AudioDeviceID)); E) Both input and output devices must be aggregatable, i.e. the device cannot be an aggregated device. A check is also performed for ( safety offset + presentation latency > maximum buffer frame size ) of the other device both ways. F) Setting both the input and output device simultaneously is recommended. Setting the property for one bus and not the other may fail if either the input or output device is not aggregatable. Explicitly setting both makes you aware if the devices can be aggregated. Error -10849 kAudioUnitErr_Initialized is returned if condition B has not been met. Error -10851 kAudioUnitErr_InvalidPropertyValue is returned if the device is an aggregate device, condition E. Error -10875 kAudioUnitErr_FailedInitialization may be returned if condition F has occurred.
5 Mac catalyst程序运行时,main函数崩溃;可能是签名认证的地方选错了,选development就好
6 无采集数据
6.1给APP麦克风权限;APP-target
6.2 info.plist给一下扬声器的权限 Privacy - Microphone Usage Description
6.3 偏好设置->安全隐私->隐私:麦克风,会看到你的APP是被允许的;
7 iOS代码编译Mac-catalyst
需要xcode 12.2及以上;来打开静态库或者动态库程序;然后scheme->any mac(apple silicion ,intel);
project->build setting->architectures->记住编译的是iOS的而不是mac 的;编译好,是支持arm64和x86_64的;