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

标题: iOS 音频单元,将立体声源中的每个立体声 channel 输出到 3D 混音器 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 16:38
标题: iOS 音频单元,将立体声源中的每个立体声 channel 输出到 3D 混音器

Apple 的 3D Mixer Audio Unit 指南指出:

To use a stereo source, you may treat its left and right channels as two independent single-channel sources, and then feed each side of the stereo stream to its own input bus.

https://developer.apple.com/library/ios/qa/qa1695/_index.html

但是,我不知道如何将立体声音频单元的每个 channel 发送到 3D 混音器。如何做到这一点?



Best Answer-推荐答案


基本上,你需要做类似的事情

@interface AudioEngine () {
    AVAudioEngine                       *_engine;
    AVAudioEnvironmentNode              *_environment;
    AVAudioPCMBuffer                    *_ouputBuffer;
    NSMutableArray <AVAudioPlayerNode*> *_PlayerArray;
    AVAudioPlayerNode                   *_soundPlayer;
    AVAudioPCMBuffer                    *_soundBuffer;
    bool                                _multichannelOutputEnabled

;

加载一个文件并从缓冲区中抓取它。 要将立体声分成多声道,您需要类似

outputLayoutTag = kAudioChannelLayoutTag_AudioUnit_2;
_multichannelOutputEnabled = true;

这个'_multichannelOutputEnabled = true;'通常设置为false

然后设置算法以对您的 channel 执行某些操作

AVAudio3DMixingRenderingAlgorithm renderingTHIS = _multichannelOutputEnabled ? 
AVAudio3DMixingRenderingAlgorithmSoundField : AVAudio3DMixingRenderingAlgorithmEqualPowerPanning;
        newPlayer.renderingAlgorithm = renderingTHIS;

在 View Controller 的某个地方,您可能会将类似的东西与游戏中的对象相关联

[self.epicAudioEngine.updateListenerOrientation:AVAudioMake3DAngularOrientation([ang.x,ang.y,ang.z])

[self updateEulerAnglesAndListenerFromDeltaX:dX DeltaY:dY]

查看 libavformat、libavutil 的 ffmpeg 源代码,了解如何处理音频

关于iOS 音频单元,将立体声源中的每个立体声 channel 输出到 3D 混音器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37580255/






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