Skip to content

Commit f7e50c2

Browse files
PehrsonsChunMinChang
authored andcommitted
Set output_dev_desc correctly when deciding to skip the mixer
1 parent 4a2ef46 commit f7e50c2

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
@@ -3822,13 +3822,44 @@ impl<'ctx> CoreStreamData<'ctx> {
38223822
return Err(Error::error());
38233823
}
38243824

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

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

0 commit comments

Comments
 (0)