Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Runtime/Scripts/RtcSources/Audio/MicrophoneRtcAudioSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ private MicrophoneRtcAudioSource(
using var request = FFIBridge.Instance.NewRequest<NewAudioSourceRequest>();
var newAudioSource = request.request;
newAudioSource.Type = AudioSourceType.AudioSourceNative;
newAudioSource.NumChannels = deviceMicrophoneAudioSource.MicrophoneInfo.channels;
// Clamp to stereo — voice chat only needs mono/stereo, and the
// underlying WebRTC AudioFrame crashes with >8 channels.
newAudioSource.NumChannels = Math.Min(deviceMicrophoneAudioSource.MicrophoneInfo.channels, 2);
newAudioSource.SampleRate = SampleRate.Hz48000.valueHz;

using var options = request.TempResource<AudioSourceOptions>();
Expand Down
8 changes: 7 additions & 1 deletion RustAudio/rust-audio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,13 @@ fn rust_audio_input_stream_new_internal(device_name: &str) -> Result<(StreamId,
.find(|c| c.sample_format() == cpal::SampleFormat::F32)
.ok_or(anyhow!("device doesn't support f32 samples"))?;

let config = config_range.with_max_sample_rate().config();
let mut config = config_range.with_max_sample_rate().config();

// Clamp to stereo — voice chat only needs mono/stereo, and WebRTC's
// AudioFrame asserts num_channels <= kMaxConcurrentChannels (8).
// Multi-channel audio interfaces (e.g. Scarlett 18i20 with 20 channels)
// would otherwise cause a fatal crash.
config.channels = config.channels.min(2);

let next_id = NEXT_STREAM_ID.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
let moved_id = next_id;
Expand Down