OGeek|极客世界-中国程序员成长平台

标题: iphone - 在 iOS5 中将 kAudioUnitSubType_Varispeed 添加到 AUGraph [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:24
标题: iphone - 在 iOS5 中将 kAudioUnitSubType_Varispeed 添加到 AUGraph

我正在尝试将 kAudioUnitSubType 添加到 iOS 5 中的 AUGraph,但是当我添加它并调用 AUGraphInitialize 时,会返回错误代码 -10868 (kAudioUnitErr_FormatNotSupported)。

这是我的 AudioComponentDescription:

AudioComponentDescription varispeedDescription;
varispeedDescription.componentType = kAudioUnitType_FormatConverter;
varispeedDescription.componentSubType = kAudioUnitSubType_Varispeed;
varispeedDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
varispeedDescription.componentFlags = 0;
varispeedDescription.componentFlagsMask = 0;

如果我在初始化图表之前打印图表的状态,我会得到以下信息:

AudioUnitGraph 0x918000:
    Member Nodes:
    node 1: 'auou' 'rioc' 'appl', instance 0x16dba0 O  
    node 2: 'aumx' 'mcmx' 'appl', instance 0x1926f0 O  
    node 3: 'aufc' 'vari' 'appl', instance 0x193b00 O  
    Connections:
    node   2 bus   0 => node   3 bus   0  [ 2 ch,  44100 Hz, 'lpcm' (0x00000C2C)   8.24-bit little-endian signed integer, deinterleaved]
    node   3 bus   0 => node   1 bus   0  [ 2 ch,      0 Hz, 'lpcm' (0x00000029) 32-bit little-endian float, deinterleaved]
    Input Callbacks:
    {0x39a5, 0x172e24} => node   2 bus   0  [2 ch, 44100 Hz]
    {0x39a5, 0x172e24} => node   2 bus   1  [2 ch, 44100 Hz]
  CurrentState:
    mLastUpdateError=0, eventsToProcess=F, isRunning=F

正如您所见,从变速单元到远程 IO 单元的连接显示出一种非常奇怪的格式。更奇怪的是,如果我在模拟器上而不是在我的开发设备上运行它,则显示的格式是 16 位小端整数,去交错。如果我尝试在 Varispeed 单元的输入或输出范围上设置流格式,我会得到相同的错误代码 -10868。

我在输入范围的每个多 channel 混音器总线上设置为流格式的 asbd 如下:

stereoFormat.mSampleRate = sampleRate;
stereoFormat.mFormatID = kAudioFormatLinearPCM;
stereoFormat.mFormatFlags = kAudioFormatFlagsCanonical;
stereoFormat.mFramesPerPacket = 1;
stereoFormat.mChannelsPerFrame = 2;
stereoFormat.mBitsPerChannel = 16;
stereoFormat.mBytesPerPacket = 4;
stereoFormat.mBytesPerFrame = 4;

我没有对音频单元使用规范格式的原因是因为我正在从 AVAssetReader 读取样本,我无法将其配置为输出 8.24 Signed Integer 样本。

如果我从图表中取出 Varispeed 单元并将多 channel 混音器单元连接到远程 IO 单元的输入,则图表会初始化并正常播放。知道我做错了什么吗?



Best Answer-推荐答案


您的 io 单元要求 32 位 float 并从变速单元接收 8.24,因此出现格式错误。

您可以在 varispeed 的输出上设置流格式以匹配 io 单元的输入格式,如下所示:

AudioStreamBasicDescription asbd;
UInt32 asbdSize = sizeof (asbd);
memset (&asbd, 0, sizeof (asbd));

AudioUnitGetProperty(ioaudiounit , kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &asbd, &asbdSize);

AudioUnitSetProperty(varipseedaudiounit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &asbd, sizeof(asbd));

关于iphone - 在 iOS5 中将 kAudioUnitSubType_Varispeed 添加到 AUGraph,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7905889/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4