fix(ios,audio): use AVAudioSession mode .default + correct mono downmix
Two changes that together address the user-reported 'speaker selector not working' AND 'audio quality bad' symptoms on iPhone: 1. AppDelegate.swift: AVAudioSession mode .voiceChat -> .default .voiceChat binds the underlying AudioUnit's output element to a SINGLE physical transducer (the receiver/earpiece) at session- configure time. overrideOutputAudioPort updates AVAudioSession's route metadata so currentRoute.outputs reports Speaker, but the AudioUnit's output binding is stale and audio keeps routing to the original transducer. Net: tapping Speaker in the picker flipped the route in our log but produced no audible change. .voiceChat also enables iOS's telephony processing chain (forced mono output, aggressive AGC, heavy noise gating) which explains the 'garbled / watery / metallic' quality complaints. .default mode uses iOS's standard audio graph: stereo output, no AGC, no telephony post-processing, AudioUnit re-binds live when the route changes. Same mode Music.app and most non-telephony apps use. Trade-off: we lose iOS hardware AEC. If users report speakerphone echo we'll add software AEC (DEC-030). Category options unchanged \u2014 .allowBluetoothHFP + .allowBluetoothA2DP still permit BT headsets in both directions. 2. engine.rs::build_output_stream: mono device downmix fix The mixing path at dev_channels==1 previously wrote only the L channel of AudioHandler's stereo output into the single mono device channel and discarded R entirely. Anything panned right in the stereo voice mix was silently lost \u2014 on .voiceChat speakerphone (forced mono device) this manifested as quiet remote speakers being inaudible. Fix: when dev_channels==1, output = (L + R) * 0.5 instead of just L. The dev_channels>=2 branch is unchanged. With change #1 iOS will typically expose stereo so this branch is rarely hit, but the fix is correct for any genuinely-mono sink (some BT car-audio profiles, USB mono headsets).
This commit is contained in:
@@ -1042,14 +1042,25 @@ where
|
||||
let l = (a_l as f64 + frac * (b_l - a_l) as f64) as f32 * gain;
|
||||
let r = (a_r as f64 + frac * (b_r - a_r) as f64) as f32 * gain;
|
||||
let base = frame_idx * dev_channels;
|
||||
if dev_channels >= 1 {
|
||||
if dev_channels == 1 {
|
||||
// Mono output device (typical on iOS
|
||||
// .voiceChat / phone-call audio path):
|
||||
// downmix L+R to a single channel
|
||||
// rather than dropping the R side.
|
||||
// Without the downmix, anything panned
|
||||
// right in the AudioHandler stereo mix
|
||||
// is silently lost \u2014 on speakerphone
|
||||
// this manifested as quiet remote
|
||||
// speakers being inaudible.
|
||||
out[base] = T::from_f32_sample((l + r) * 0.5);
|
||||
} else {
|
||||
out[base] = T::from_f32_sample(l);
|
||||
}
|
||||
if dev_channels >= 2 {
|
||||
out[base + 1] = T::from_f32_sample(r);
|
||||
}
|
||||
for c in 2..dev_channels {
|
||||
out[base + c] = T::from_f32_sample(0.0);
|
||||
if dev_channels >= 2 {
|
||||
out[base + 1] = T::from_f32_sample(r);
|
||||
}
|
||||
for c in 2..dev_channels {
|
||||
out[base + c] = T::from_f32_sample(0.0);
|
||||
}
|
||||
}
|
||||
pos += resample_ratio;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user