Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.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
Swift 使用AVFoundation和AVAudioNode如何获取一个音频源并将其路由到多个目的地?_Swift_Xcode_Avfoundation - Fatal编程技术网

Swift 使用AVFoundation和AVAudioNode如何获取一个音频源并将其路由到多个目的地?

Swift 使用AVFoundation和AVAudioNode如何获取一个音频源并将其路由到多个目的地?,swift,xcode,avfoundation,Swift,Xcode,Avfoundation,我正在尝试做一些理论上应该非常简单的事情,即从单个AVAudioNode产生的音频,并将其路由到多个输出,这些输出也是AVAudioNode。但是,我没有看到这样的类。这本质上类似于拆分器对象 我想这样做: import AVFoundation class Router{ func connect(){ let node1 = mixerNode() let node2 = mixerNode() let node3 = mixerNode()

我正在尝试做一些理论上应该非常简单的事情,即从单个AVAudioNode产生的音频,并将其路由到多个输出,这些输出也是AVAudioNode。但是,我没有看到这样的类。这本质上类似于拆分器对象

我想这样做:

import AVFoundation
class Router{
func connect(){
        let node1 = mixerNode()
        let node2 = mixerNode()
        let node3 = mixerNode()
        let engine = AVAudioEngine()
        let format = node1.outputFormat(forBus: 0)
        engine.attach(node1)
        engine.attach(node2)
        engine.attach(node3)
        engine.connect(node1, to: node2, format: format)
        engine.connect(node1, to: node3, format: format)
        let connections = engine.outputConnectionPoints(for: node1, outputBus: 0)
        print("Num connections = \(connections.count)")
}
   import AVFoundation
   class someClass{ 
        func connectMultipleNodes(){
            let engine = AVAudioEngine()
            let node1 = AVAudioNode()
            let node2 = AVAudioNode()
            let node3 = AVAudioNode()
            engine.attach(node1)
            engine.attach(node2)
            engine.attach(node3)
            let format = node1.outputFormat(forBus: 0)
            let connection1 = AVAudioConnectionPoint(node: node2, bus: 0)
            let connection2 = AVAudioConnectionPoint(node: node3, bus: 0)
            let connections = [connection1, connection2]
            engine.connect(node1, to: connections, fromBus: 0, format: format)
       }
   }

但是,控制台显示node1仅连接到一个节点,因为它只能有一个输出。有允许多个输出的对象吗?

我知道怎么做了。没有“拆分器”节点。但是,AVAudioEngine允许您使用AVAudioConnection将任何一个节点路由到多个输出目的地,如下所示:

import AVFoundation
class Router{
func connect(){
        let node1 = mixerNode()
        let node2 = mixerNode()
        let node3 = mixerNode()
        let engine = AVAudioEngine()
        let format = node1.outputFormat(forBus: 0)
        engine.attach(node1)
        engine.attach(node2)
        engine.attach(node3)
        engine.connect(node1, to: node2, format: format)
        engine.connect(node1, to: node3, format: format)
        let connections = engine.outputConnectionPoints(for: node1, outputBus: 0)
        print("Num connections = \(connections.count)")
}
   import AVFoundation
   class someClass{ 
        func connectMultipleNodes(){
            let engine = AVAudioEngine()
            let node1 = AVAudioNode()
            let node2 = AVAudioNode()
            let node3 = AVAudioNode()
            engine.attach(node1)
            engine.attach(node2)
            engine.attach(node3)
            let format = node1.outputFormat(forBus: 0)
            let connection1 = AVAudioConnectionPoint(node: node2, bus: 0)
            let connection2 = AVAudioConnectionPoint(node: node3, bus: 0)
            let connections = [connection1, connection2]
            engine.connect(node1, to: connections, fromBus: 0, format: format)
       }
   }