Skip to content

Commit 8a43771

Browse files
committed
Set output_dev_desc correctly when deciding to skip the mixer
1 parent c74e829 commit 8a43771

File tree

1 file changed

+32
-28
lines changed

1 file changed

+32
-28
lines changed

src/backend/mod.rs

+32-28
Original file line numberDiff line numberDiff line change
@@ -3819,13 +3819,44 @@ impl<'ctx> CoreStreamData<'ctx> {
38193819
return Err(Error::error());
38203820
}
38213821

3822+
// Simple case of stereo output, map to the stereo pair (that might not be the first
3823+
// two channels). Fall back to regular mixing if this fails.
3824+
let mut maybe_need_mixer = true;
3825+
if self.output_stream_params.channels() == 2
3826+
&& self.output_stream_params.layout() == ChannelLayout::STEREO
3827+
{
3828+
let layout = AudioChannelLayout {
3829+
mChannelLayoutTag: kAudioChannelLayoutTag_Stereo,
3830+
..Default::default()
3831+
};
3832+
let r = audio_unit_set_property(
3833+
self.output_unit,
3834+
kAudioUnitProperty_AudioChannelLayout,
3835+
kAudioUnitScope_Input,
3836+
AU_OUT_BUS,
3837+
&layout,
3838+
mem::size_of::<AudioChannelLayout>(),
3839+
);
3840+
if r != NO_ERR {
3841+
cubeb_log!(
3842+
"AudioUnitSetProperty/output/kAudioUnitProperty_AudioChannelLayout rv={}",
3843+
r
3844+
);
3845+
}
3846+
maybe_need_mixer = r != NO_ERR;
3847+
}
3848+
38223849
// Notice: when we are using aggregate device, the output_hw_desc.mChannelsPerFrame is
38233850
// the total of all the output channel count of the devices added in the aggregate device.
38243851
// Due to our aggregate device settings, the data recorded by the input device's output
38253852
// channels will be appended at the end of the raw data given by the output callback.
38263853
let params = unsafe {
38273854
let mut p = *self.output_stream_params.as_ptr();
3828-
p.channels = output_hw_desc.mChannelsPerFrame;
3855+
p.channels = if maybe_need_mixer {
3856+
output_hw_desc.mChannelsPerFrame
3857+
} else {
3858+
self.output_stream_params.channels()
3859+
};
38293860
if using_voice_processing_unit {
38303861
// VPIO will always use the sample rate of the input hw for both input and output,
38313862
// as reported to us. (We can override it but we cannot improve quality this way).
@@ -3877,33 +3908,6 @@ impl<'ctx> CoreStreamData<'ctx> {
38773908
device_layout
38783909
);
38793910

3880-
// Simple case of stereo output, map to the stereo pair (that might not be the first
3881-
// two channels). Fall back to regular mixing if this fails.
3882-
let mut maybe_need_mixer = true;
3883-
if self.output_stream_params.channels() == 2
3884-
&& self.output_stream_params.layout() == ChannelLayout::STEREO
3885-
{
3886-
let layout = AudioChannelLayout {
3887-
mChannelLayoutTag: kAudioChannelLayoutTag_Stereo,
3888-
..Default::default()
3889-
};
3890-
let r = audio_unit_set_property(
3891-
self.output_unit,
3892-
kAudioUnitProperty_AudioChannelLayout,
3893-
kAudioUnitScope_Input,
3894-
AU_OUT_BUS,
3895-
&layout,
3896-
mem::size_of::<AudioChannelLayout>(),
3897-
);
3898-
if r != NO_ERR {
3899-
cubeb_log!(
3900-
"AudioUnitSetProperty/output/kAudioUnitProperty_AudioChannelLayout rv={}",
3901-
r
3902-
);
3903-
}
3904-
maybe_need_mixer = r != NO_ERR;
3905-
}
3906-
39073911
if maybe_need_mixer {
39083912
// The mixer will be set up when
39093913
// 0. not playing simply stereo, or failing to set the channel layout to the stereo

0 commit comments

Comments
 (0)