Post

Replies

Boosts

Views

Activity

Reply to Choose specific input channel as a mono input from external USB device in AVAudioSession/AVAudioEngine
I had the same question asked on stack overflow as well and received a working answer there. https://stackoverflow.com/questions/75684026/choose-specific-input-channel-as-a-mono-input-from-usb-device-in-avaudiosession/76079369#76079369 It seems to be a pretty simple one by setting channel map on auAudioUnit of the input node. engine.inputNode.auAudioUnit.channelMap = [1, 1] 1 is the channel 1 in this case. If you need to use channel 0 it would be [0, 0] and same would apply for other channels.
Apr ’23
Reply to Choose specific input channel as a mono input from external USB device in AVAudioSession/AVAudioEngine
Unfortunately solution I've mentioned seemed to be working at the first glance but later I've discovered pan wasn't working since it was lowering the volume of 2nd channel and since it was streaming in both speakers value of below 0 was lowering the overall volume resulting in silence at -1. Also, tested with more than 2 channel input interface and it wasn't streaming 3rd and above channels. I believe channel map is not what we want here. This is how I fixed panning initially but then noticed it was passing through all the inputs as mono. I've just tested it in an empty project in app delegate and posting whole code that you could just run and see in action. @main class AppDelegate: UIResponder, UIApplicationDelegate { let engine = AVAudioEngine() var inputNode: AVAudioInputNode { engine.inputNode } var inputFormat: AVAudioFormat { inputNode.inputFormat(forBus: 0) } var outputNode: AVAudioOutputNode { engine.outputNode } var outputFormat: AVAudioFormat { outputNode.outputFormat(forBus: 0) } var mainMixerNode: AVAudioMixerNode { engine.mainMixerNode } let mixerNode: AVAudioMixerNode = .init() func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { engine.attach(mixerNode) let layoutTag: AudioChannelLayoutTag = kAudioChannelLayoutTag_Mono let layout = AVAudioChannelLayout(layoutTag: layoutTag)! let monoFormat: AVAudioFormat = .init(standardFormatWithSampleRate: inputFormat.sampleRate, channelLayout: layout) engine.connect(inputNode, to: mixerNode, format: inputFormat) engine.connect(mixerNode, to: mainMixerNode, format: monoFormat) try! engine.start() mixerNode.pan = -0.4 return true } } Also, it didn't work when I tested with 10 input channel audio interface. It was only streaming first two signals. I've tested the same audio interface with Garage Band and it works there. Wonder how Apple does it and the same time doesn't provide us with a straightforward interface to do so. Ideally it should be possible to switch from AVAudioSession but it doesn't have that feature. I've looked through all the docs of AVAudioSession, AVAudioEngine and whatnot but couldn't find anything there.
Apr ’23