@@ -3822,13 +3822,44 @@ impl<'ctx> CoreStreamData<'ctx> {
3822
3822
return Err ( Error :: error ( ) ) ;
3823
3823
}
3824
3824
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
+
3825
3852
// Notice: when we are using aggregate device, the output_hw_desc.mChannelsPerFrame is
3826
3853
// the total of all the output channel count of the devices added in the aggregate device.
3827
3854
// Due to our aggregate device settings, the data recorded by the input device's output
3828
3855
// channels will be appended at the end of the raw data given by the output callback.
3829
3856
let params = unsafe {
3830
3857
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
+ } ;
3832
3863
if using_voice_processing_unit {
3833
3864
// VPIO will always use the sample rate of the input hw for both input and output,
3834
3865
// as reported to us. (We can override it but we cannot improve quality this way).
@@ -3880,33 +3911,6 @@ impl<'ctx> CoreStreamData<'ctx> {
3880
3911
device_layout
3881
3912
) ;
3882
3913
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
-
3910
3914
if maybe_need_mixer {
3911
3915
// The mixer will be set up when
3912
3916
// 0. not playing simply stereo, or failing to set the channel layout to the stereo
0 commit comments