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