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

Legacy mute causes audio session switch #619

Open
dfed opened this issue Mar 7, 2025 · 7 comments
Open

Legacy mute causes audio session switch #619

dfed opened this issue Mar 7, 2025 · 7 comments
Assignees
Labels
bug Something isn't working Swift

Comments

@dfed
Copy link

dfed commented Mar 7, 2025

Describe the bug
Muting the local participant's microphone when isLegacyMuteMode is enabled mutes all audio, including agent audio and other sound effects being played by AVAudioEngine

SDK Version
2.2.1. This is a regression from 2.0.19. I have not tested releases between these.

iOS/macOS Version
Reproduced on iOS 17.7.2 and iOS 18.4b1

Xcode Version
16.2.0 (Swift 6 mode)

Steps to Reproduce

  1. AudioManager.shared.isLegacyMuteMode = true
  2. Connect to a room.
  3. Call room.localParticipant.setMicrophone(enabled: false)

Expected behavior
Microphone input is muted, and other audio is not muted.

@dfed dfed added the bug Something isn't working label Mar 7, 2025
@hiroshihorie
Copy link
Member

Hi @dfed I'll investigate this today. I've already tested this case so I wonder what's going on 🤔

@hiroshihorie hiroshihorie added the Swift label Mar 7, 2025 — with Linear
@sergeyphi
Copy link

Hi @hiroshihorie I've also noticed this issue.

I've also noticed that the muted state will have it's own volume level that the app will "remember".

I'll expand @dfed's repro steps to show what I mean:

  1. AudioManager.shared.isLegacyMuteMode = true
  2. Connect to a room
  3. Change volume to 1.0 with iPhone buttons
  4. Call room.localParticipant.setMicrophone(enabled: false)
  5. Observe not being able remote participant's audio track (potentially)
  6. Change volume to 0.5 with iPhone buttons
  7. Now you can hear remote participant
  8. room.localParticipant.setMicrophone(enabled: true)
  9. Observe audio volume changed back to 1.0
  10. room.localParticipant.setMicrophone(enabled: false)
  11. Observe audio volume changed to 0.5 (value you set before while muted)

Sharing in case it's useful!

@dfed
Copy link
Author

dfed commented Mar 7, 2025

Fascinating observation! I believe that would indicate we’re changing the the audio session configuration when disabling the microphone.

@hiroshihorie
Copy link
Member

hiroshihorie commented Mar 7, 2025

Thank you, @dfed and @sergeyphi. Yes, the audio session switch is causing the volume level change. When legacyMuteMode is enabled, muting shuts down the recording, which then switches to .playback.

I’ll implement a fix or provide an option to modify this behavior. In a mute/unmute scenario you probably just want to keep it on .playAndRecord. 🙂

@hiroshihorie hiroshihorie changed the title Muting local participant mutes **all audio**, not just microphone Legacy mute causes audio session switch Mar 7, 2025
@hiroshihorie
Copy link
Member

Hi, I'm working on fix in #621 but I've discovered the following.

When maintaining category: .playAndRecord mode: .videoChat and disabling recording,
volume slider remains same which is good ✅ but now the output volume drops significantly ❌

Using this mode without the VoiceProcessing IO unit or AVAudioEngine with voice processing enabled will result in the following:
    - Chat-specific signal processing such as echo cancellation or automatic gain correction will not be loaded
    - Dynamic processing on input and output will be disabled resulting in a lower output playback level. 

If I switch to another mode, even with same category (.playAndRecord mode: .default),
volume slider switches ❌ but the output volume is good ✅

Example:
https://github.com/user-attachments/assets/aee8e81e-2c0a-4012-a871-948be8033879

So I'm a little stuck at the moment.

Another option is to keep the recording on (mic indicator on) but disregard local audio buffers (mute) which I'm sure will work.
But I assume turning off the mic indicator is a requirement ?

@dfed
Copy link
Author

dfed commented Mar 11, 2025

Ahhhhhh right I remember hitting this before we adopted LiveKit – turning off voice processing enables you to turn off the audio indicator but it also makes all audio playback quite quiet.

Dropping output volume is a no-go, since there's no way for the user to work around it. Switching modes changes the volume, which is not great, but at least the user can fix it + develop a mental model around it. I think this is the preferred approach.

Another option is to keep the recording on (mic indicator on) but disregard local audio buffers (mute) which I'm sure will work.

I agree this'll work, but I also agree that this doesn't feel viable.

Edit: what I don't understand is how the modern mute mode avoids this pitfall. What's the setting in the audio stack that enables us to have both consistent volume across mute/unmute as well as voice processing?

@hiroshihorie
Copy link
Member

The "modern mute mode" is using isVoiceProcessingInputMuted which is exactly for this purpose. But unfortunately plays a sound effect, probably for privacy reasons. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Swift
Projects
None yet
Development

No branches or pull requests

3 participants