Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate audio channel map before applying #1379

Merged

Conversation

levs42
Copy link
Contributor

@levs42 levs42 commented Feb 15, 2024

Description & motivation

Feature: Add audio channel map validation

Here's a case I'm trying to solve:

  1. User connects an audio device with 2 input channels
  2. User sets the output channel map to [0, 1]
  3. User disconnects the input device, so now input has only 1 channel from the default mic
  4. Audio converter crashes here because it tries to map the second channel that isn't available anymore

There are other situations like this, for instance, just setting stream.audioSettings.channelMap = [3].
The problem here is that audio input and output formats are not exposed outside of the library and channelMap cannot be corrected before it's applied to the converter.

Theoretically, both formats or the converted itself could be exposed, but it has some downsides. For example, need to add extra delegate methods to IOAudioResamplerDelegate -> IOAudioUnitDelegate -> IOMixerDelegate -> IOStreamDelegate. So I choose an option to automatically validate the current channelMap to make sure that:

  1. The length of the array is equal to the number of output channels
  2. The array doesn't contain invalid input channels

Type of change

Please delete options that are not relevant.

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

Screenshots:

@shogo4405
Copy link
Owner

Since crashes are not acceptable, I thought validation was necessary. For reference, since the input audio format is exposed via stream.audioInputFormat.

@shogo4405 shogo4405 added this to the 1.7.4 milestone Feb 16, 2024
@shogo4405 shogo4405 merged commit 44770d6 into shogo4405:main Feb 16, 2024
1 check passed
@levs42 levs42 deleted the feature/channel-map-validation branch March 16, 2024 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants