Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 如何使用;kAudioUnitSubType“U VoiceProcessingIO”;mac os中核心音频API的子类型?_Macos_Core Audio - Fatal编程技术网

Macos 如何使用;kAudioUnitSubType“U VoiceProcessingIO”;mac os中核心音频API的子类型?

Macos 如何使用;kAudioUnitSubType“U VoiceProcessingIO”;mac os中核心音频API的子类型?,macos,core-audio,Macos,Core Audio,我发现了一个简单的play-thru应用程序示例,它使用macosx中带有kAudioUnitSubType\u VoiceProcessingIO子类型(而不是kAudioUnitSubType\u HALOutput)的内置麦克风/扬声器。core audio api上的评论说,kAudioUnitSubType_VoiceProcessingIO可以在桌面上使用,也可以在iPhone 3.0或更高版本上使用,因此我认为macos肯定有一个例子 你知道样品在哪里吗?或者有人知道如何在maco

我发现了一个简单的play-thru应用程序示例,它使用macosx中带有kAudioUnitSubType\u VoiceProcessingIO子类型(而不是kAudioUnitSubType\u HALOutput)的内置麦克风/扬声器。core audio api上的评论说,kAudioUnitSubType_VoiceProcessingIO可以在桌面上使用,也可以在iPhone 3.0或更高版本上使用,因此我认为macos肯定有一个例子


你知道样品在哪里吗?或者有人知道如何在macos中使用kAudioUnitSubType_VoiceProcessingIO子类型吗?我已经尝试了与iOS相同的方法,但没有成功。

我发现了一些能够启用此IO单元的功能

  • 流格式非常挑剔。一定是这样
    • LinearPCM
    • 旗袍
    • 每个通道32位
    • (我只做了一个频道,但可能需要更多)-
    • 采样率44100(可能与其他人一起使用,可能不使用)
  • 你没有在上面设置EnableIO。默认情况下,IO处于启用状态,并且该属性不可写
  • 在初始化之前设置流格式

  • 与其他核心音频工作一样,您只需检查每个函数调用的错误状态,确定错误是什么,并在每个步骤中进行少量更改,直到最终使其正常工作。

    我根据通道数设置了两个不同的kAudioUnitProperty\u StreamFormat

    size_t bytesPerSample = sizeof (AudioUnitSampleType);
    stereoStreamFormat.mFormatID          = kAudioFormatLinearPCM;
    stereoStreamFormat.mFormatFlags       = kAudioFormatFlagsAudioUnitCanonical;
    stereoStreamFormat.mBytesPerPacket    = bytesPerSample;
    stereoStreamFormat.mFramesPerPacket   = 1;
    stereoStreamFormat.mBytesPerFrame     = bytesPerSample;
    stereoStreamFormat.mChannelsPerFrame  = 2;
    stereoStreamFormat.mBitsPerChannel    = 8 * bytesPerSample;
    stereoStreamFormat.mSampleRate        = graphSampleRate;
    

    将I/O单元用作KaudioUnits子类型_VoiceProcessingIO时,使用此音频流格式

    AudioComponentDescription iOUnitDescription;
    iOUnitDescription.componentType = kAudioUnitType_Output;
    iOUnitDescription.componentSubType = kAudioUnitSubType_VoiceProcessingIO;
    iOUnitDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
    iOUnitDescription.componentFlags = 0;
    iOUnitDescription.componentFlagsMask = 0;
    
    我可以清楚地看到音频输出中断,因为缓冲区的大小小于这个音频单元的大小

    切换回kAudioUnitSubType_RemoteIO

    iOUnitDescription.componentSubType=kAudioUnitSubType\u RemoteIO

    这种干扰消失了

    我正在处理来自麦克风的音频输入,并对音频缓冲区进行实时计算

    在这些方法中,graphSampleRate是平均采样率

    graphSampleRate = [AVAudioSession sharedInstance] sampleRate];
    
    也许我错了

    最后,配置参数值如下所示:

    立体声流格式:

    Sample Rate:              44100
    Format ID:                 lpcm
    Format Flags:              3116
    Bytes per Packet:             4
    Frames per Packet:            1
    Bytes per Frame:              4
    Channels per Frame:           2
    Bits per Channel:            32
    
    Sample Rate:              44100
    Format ID:                 lpcm
    Format Flags:              3116
    Bytes per Packet:             4
    Frames per Packet:            1
    Bytes per Frame:              4
    Channels per Frame:           1
    Bits per Channel:            32
    
    单声道流格式:

    Sample Rate:              44100
    Format ID:                 lpcm
    Format Flags:              3116
    Bytes per Packet:             4
    Frames per Packet:            1
    Bytes per Frame:              4
    Channels per Frame:           2
    Bits per Channel:            32
    
    Sample Rate:              44100
    Format ID:                 lpcm
    Format Flags:              3116
    Bytes per Packet:             4
    Frames per Packet:            1
    Bytes per Frame:              4
    Channels per Frame:           1
    Bits per Channel:            32
    
    多亏我意识到我应该使用这个标志:

    audioFormat.mFormatFlags        = kAudioFormatFlagsCanonical;
    

    谢谢,它也适用于其他采样率(我使用的是16000)。FlagsCanonical格式在MAC OS X Float32中的意思是范围从-1.0到1.0。@sarsonj:您确定可以使用默认的44100以外的采样率工作吗?在尝试设置16000或48000时,我发现kAudioUnitErr\u格式不受支持。我使用的是一个频道,16000,Mac上带有kAudioFormatFlagsCanonical,工作正常。@sarsonj您有没有在OSX上使用audioUnit通过音频播放的示例?我也有同样的问题。我听从你的建议,但这不管用。请帮帮我!可以确认它在OS X 10.12和48000上对我有效。但是,示例格式必须是32位浮点,否则两端的音频都会损坏,输出中会出现无法读取的错误。它也必须是单声道的。