Skip to content

Stereo recording feature for Example iOS ver 2025#1770

Merged
shogo4405 merged 1 commit intomainfrom
feature/audio-stereo-source
Aug 26, 2025
Merged

Stereo recording feature for Example iOS ver 2025#1770
shogo4405 merged 1 commit intomainfrom
feature/audio-stereo-source

Conversation

@shogo4405
Copy link
Copy Markdown
Collaborator

@shogo4405 shogo4405 commented Aug 26, 2025

Description & motivation

  • The stereo streaming example was not working, so I rewrote it as the 2025 edition.
  • The key points to make it work are as follows:
  1. Configure AVAudioSession as shown below.
    // If you set the "mode" parameter, stereo capture is not possible, so it is left unspecified.
    try session.setCategory(.playAndRecord, mode: .videoRecording, options: [.defaultToSpeaker, .allowBluetooth])
    // It looks like this setting is required on iOS 18.5.
    try session.setPreferredInputNumberOfChannels(2)
    try session.setActive(true)
  2. Set the following values in MediaMixer.
    await mixer.configuration { session in
    // It is required for the stereo setting.
    session.automaticallyConfiguresApplicationAudioSession = false
    }
  3. Refer to the code in the PR below for the stereo source.
    func selectAudioSource(_ audioSource: AudioSource) throws {
    setPreferredInputBuiltInMic(true)
    guard let preferredInput = AVAudioSession.sharedInstance().preferredInput,
    let dataSources = preferredInput.dataSources,
    let newDataSource = dataSources.first(where: { $0.dataSourceName == audioSource.dataSourceName }),
    let supportedPolarPatterns = newDataSource.supportedPolarPatterns else {
    throw Error.missingDataSource(audioSource)
    }
    do {
    let isStereoSupported = supportedPolarPatterns.contains(.stereo)
    if isStereoSupported {
    try newDataSource.setPreferredPolarPattern(.stereo)
    }
    try preferredInput.setPreferredDataSource(newDataSource)
    } catch {
    logger.warn(error)
    }
    }
    private func makeAudioSources() -> [AudioSource] {

Type of change

  • New feature (non-breaking change which adds functionality)

Screenshots:

@shogo4405 shogo4405 merged commit a29c7e8 into main Aug 26, 2025
1 check passed
@shogo4405 shogo4405 deleted the feature/audio-stereo-source branch August 26, 2025 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant