Skip to content

Commit

Permalink
[AudioQueueCaptureSession] support channelsPerFrame configuration.
Browse files Browse the repository at this point in the history
If  `channelsPerFrame` is nil, `AVAudioSession.sharedInstance().inputNumberOfChannels` is used.
  • Loading branch information
YuAo committed Aug 19, 2021
1 parent 5aaeaa3 commit 51517a1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Sources/VideoIO/AudioQueueCaptureSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public class AudioQueueCaptureSession {

public let sampleRate: Double

private let channelsPerFrame: UInt32?

private weak var delegate: AudioQueueCaptureSessionDelegate?
private let delegateQueue: DispatchQueue

Expand All @@ -72,7 +74,8 @@ public class AudioQueueCaptureSession {

private var clientInfo: ClientInfo?

public init(sampleRate: Double = 44100, delegate: AudioQueueCaptureSessionDelegate, delegateQueue: DispatchQueue = .main) {
public init(sampleRate: Double = 44100, channelsPerFrame: UInt32? = nil, delegate: AudioQueueCaptureSessionDelegate, delegateQueue: DispatchQueue = .main) {
self.channelsPerFrame = channelsPerFrame
self.sampleRate = sampleRate
self.delegate = delegate
self.delegateQueue = delegateQueue
Expand Down Expand Up @@ -142,7 +145,7 @@ public class AudioQueueCaptureSession {
if AVAudioSession.sharedInstance().isInputAvailable {
var recordFormat = AudioStreamBasicDescription()
recordFormat.mSampleRate = sampleRate
recordFormat.mChannelsPerFrame = UInt32(AVAudioSession.sharedInstance().inputNumberOfChannels)
recordFormat.mChannelsPerFrame = channelsPerFrame ?? UInt32(AVAudioSession.sharedInstance().inputNumberOfChannels)
recordFormat.mFormatID = kAudioFormatLinearPCM
recordFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked
recordFormat.mBitsPerChannel = 16
Expand Down

0 comments on commit 51517a1

Please sign in to comment.