• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 无法在格式转换器音频单元上设置格式

[复制链接]
菜鸟教程小白 发表于 2022-12-12 16:15:42 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在尝试设置一个非常简单的 AU 图形 - 只是一个 RemoteIO 附加到它的变速以用于输出。不幸的是,我似乎无法在变速单元上设置音频格式。我见过的其他例子似乎只是设置格式没有问题。我得到的确切错误是不支持的格式。但是,RemoteIO 单元内的格式转换器会很高兴地采用我的格式,这是一种非常简单的 16khz mono 16bit signed int PCM 格式。

这是我目前正在尝试制作的代码:

 // Describe the output unit.
AudioComponentDescription inputDescription = {0};   
inputDescription.componentType = kAudioUnitType_Output;
inputDescription.componentSubType = kAudioUnitSubType_RemoteIO;
inputDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
AUNode ioNode;
CheckError(self, AUGraphAddNode(_graph, &inputDescription, &ioNode), "Couldn't add ioNode to AU graph");

AudioComponentDescription varispeedDescription = {0};
varispeedDescription.componentType = kAudioUnitType_FormatConverter;
varispeedDescription.componentSubType = kAudioUnitSubType_Varispeed;
varispeedDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
AUNode varispeedNode;
CheckError(self, AUGraphAddNode(_graph, &varispeedDescription, &varispeedNode), "Couldn't add varispeed node to AU graph");

CheckError(self, AUGraphOpen(_graph), "Couldn't open AU graph");
AudioUnit varispeedUnit;
CheckError(self, AUGraphNodeInfo(_graph, varispeedNode, NULL, &varispeedUnit), "Couldn't get varispeed audio unit");

CheckError(self, AUGraphNodeInfo(_graph, ioNode, NULL, &_ioUnit), "Couldn't get io unit");

// Enable input
// TODO: Conditionally disable input if option has not been specified
UInt32 one = 1;
CheckError(self, AudioUnitSetProperty(_ioUnit,
                                 kAudioOutputUnitProperty_EnableIO,
                                 kAudioUnitScope_Input,
                                 kInputBus,
                                 &one,
                                 sizeof(one)), "Couldn't enable IO on the input scope of output unit");

// TODO: check this works on iOS!
_format.mBitsPerChannel = 16;
_format.mBytesPerFrame = 2;
_format.mBytesPerPacket = 2;
_format.mChannelsPerFrame = 1;
_format.mFramesPerPacket = 1;
_format.mReserved = 0;
_format.mSampleRate = 16000.0;
_format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
_format.mFormatID = kAudioFormatLinearPCM;

self.samplingRate = _format.mSampleRate;
UInt32 size;
size = sizeof(AudioStreamBasicDescription);
CheckError(self, AudioUnitSetProperty(_ioUnit,
                                kAudioUnitProperty_StreamFormat,
                                kAudioUnitScope_Output,
                                kInputBus,
                                &_format,
                                size),
           "Couldn't set the ASBD on the audio unit (after setting its sampling rate)");
size = sizeof(AudioStreamBasicDescription);
CheckError(self, AudioUnitSetProperty(varispeedUnit,
                                      kAudioUnitProperty_StreamFormat,
                                      kAudioUnitScope_Output,
                                      0,
                                      &_format,
                                      size),
           "Couldn't set the ASBD on the audio unit (after setting its sampling rate)");
size = sizeof(AudioStreamBasicDescription);
CheckError(self, AudioUnitSetProperty(varispeedUnit,
                                      kAudioUnitProperty_StreamFormat,
                                      kAudioUnitScope_Input,
                                      0,
                                      &_format,
                                      size),
           "Couldn't set the ASBD on the audio unit (after setting its sampling rate)");

我也尝试过简单地设置 RemoteIO 输出总线的输入格式,这对于转换器的输出格式效果很好,但它仍然不接受我的格式作为转换器的输入格式。

如何将变速和 RemoteIO 与我想要的格式联系起来?



Best Answer-推荐答案


我在一个旧邮件列表中发现 Varispeed 单元仅是 float ,实际上并不进行格式转换,尽管主要类型是 FormatConverter。解决方案是使用具有专用转换器子类型的另一个转换器将我自己的格式转换为 Varispeed 想要的 FP 格式。 Varispeed 的格式限制实际上并没有据我所知在任何地方都有记录,所以我不知道它真正想要什么格式,除了扬声器输出格式对我有用,它应该是浮点线性 PCM 格式。

仅供引用,Varispeed 单元不会进行任何音高校正,这在更改播放速率时听起来很荒谬。您可以改用 NewTimePitch 单元,它响应相同的变速参数,但结果听起来不像废话。

关于ios - 无法在格式转换器音频单元上设置格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32518697/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap