@@ -172,10 +172,11 @@ enum obs_module_load_state obs_source_load_state(const char *id)
172172
173173static void allocate_audio_output_buffer (struct obs_source * source )
174174{
175- size_t size = sizeof (float ) * AUDIO_OUTPUT_FRAMES * MAX_AUDIO_CHANNELS * MAX_AUDIO_MIXES ;
175+ size_t size = sizeof (float ) * AUDIO_OUTPUT_FRAMES * MAX_AUDIO_CHANNELS *
176+ (MAX_AUDIO_MIXES + MAX_AUDIO_MONITORING_MIXES );
176177 float * ptr = bzalloc (size );
177178
178- for (size_t mix = 0 ; mix < MAX_AUDIO_MIXES ; mix ++ ) {
179+ for (size_t mix = 0 ; mix < ( MAX_AUDIO_MIXES + MAX_AUDIO_MONITORING_MIXES ) ; mix ++ ) {
179180 size_t mix_pos = mix * AUDIO_OUTPUT_FRAMES * MAX_AUDIO_CHANNELS ;
180181
181182 for (size_t i = 0 ; i < MAX_AUDIO_CHANNELS ; i ++ ) {
@@ -5224,7 +5225,7 @@ static void apply_audio_actions(obs_source_t *source, size_t channels, size_t sa
52245225
52255226 pthread_mutex_unlock (& source -> audio_actions_mutex );
52265227
5227- for (size_t mix = 0 ; mix < MAX_AUDIO_MIXES ; mix ++ ) {
5228+ for (size_t mix = 0 ; mix < ( MAX_AUDIO_MIXES + MAX_AUDIO_MONITORING_MIXES ) ; mix ++ ) {
52285229 if ((source -> audio_mixers & (1 << mix )) != 0 )
52295230 multiply_vol_data (source , mix , channels , vol_data );
52305231 }
@@ -5259,11 +5260,12 @@ static void apply_audio_volume(obs_source_t *source, uint32_t mixers, size_t cha
52595260
52605261 if (vol == 0.0f || mixers == 0 ) {
52615262 memset (source -> audio_output_buf [0 ][0 ], 0 ,
5262- AUDIO_OUTPUT_FRAMES * sizeof (float ) * MAX_AUDIO_CHANNELS * MAX_AUDIO_MIXES );
5263+ AUDIO_OUTPUT_FRAMES * sizeof (float ) * MAX_AUDIO_CHANNELS *
5264+ (MAX_AUDIO_MIXES + MAX_AUDIO_MONITORING_MIXES ));
52635265 return ;
52645266 }
52655267
5266- for (size_t mix = 0 ; mix < MAX_AUDIO_MIXES ; mix ++ ) {
5268+ for (size_t mix = 0 ; mix < ( MAX_AUDIO_MIXES + MAX_AUDIO_MONITORING_MIXES ) ; mix ++ ) {
52675269 uint32_t mix_and_val = (1 << mix );
52685270 if ((source -> audio_mixers & mix_and_val ) != 0 && (mixers & mix_and_val ) != 0 )
52695271 multiply_output_audio (source , mix , channels , vol );
@@ -5276,7 +5278,7 @@ static void custom_audio_render(obs_source_t *source, uint32_t mixers, size_t ch
52765278 bool success ;
52775279 uint64_t ts ;
52785280
5279- for (size_t mix = 0 ; mix < MAX_AUDIO_MIXES ; mix ++ ) {
5281+ for (size_t mix = 0 ; mix < ( MAX_AUDIO_MIXES + MAX_AUDIO_MONITORING_MIXES ) ; mix ++ ) {
52805282 for (size_t ch = 0 ; ch < channels ; ch ++ ) {
52815283 audio_data .output [mix ].data [ch ] = source -> audio_output_buf [mix ][ch ];
52825284 }
@@ -5293,7 +5295,7 @@ static void custom_audio_render(obs_source_t *source, uint32_t mixers, size_t ch
52935295 if (!success || !source -> audio_ts || !mixers )
52945296 return ;
52955297
5296- for (size_t mix = 0 ; mix < MAX_AUDIO_MIXES ; mix ++ ) {
5298+ for (size_t mix = 0 ; mix < ( MAX_AUDIO_MIXES + MAX_AUDIO_MONITORING_MIXES ) ; mix ++ ) {
52975299 uint32_t mix_bit = 1 << mix ;
52985300
52995301 if ((mixers & mix_bit ) == 0 )
@@ -5355,7 +5357,7 @@ static inline void process_audio_source_tick(obs_source_t *source, uint32_t mixe
53555357
53565358 pthread_mutex_unlock (& source -> audio_buf_mutex );
53575359
5358- for (size_t mix = 1 ; mix < MAX_AUDIO_MIXES ; mix ++ ) {
5360+ for (size_t mix = 1 ; mix < ( MAX_AUDIO_MIXES + MAX_AUDIO_MONITORING_MIXES ) ; mix ++ ) {
53595361 uint32_t mix_and_val = (1 << mix );
53605362
53615363 if (audio_submix ) {
@@ -5435,7 +5437,7 @@ void obs_source_get_audio_mix(const obs_source_t *source, struct obs_source_audi
54355437 if (!obs_ptr_valid (audio , "audio" ))
54365438 return ;
54375439
5438- for (size_t mix = 0 ; mix < MAX_AUDIO_MIXES ; mix ++ ) {
5440+ for (size_t mix = 0 ; mix < ( MAX_AUDIO_MIXES + MAX_AUDIO_MONITORING_MIXES ) ; mix ++ ) {
54395441 for (size_t ch = 0 ; ch < MAX_AUDIO_CHANNELS ; ch ++ ) {
54405442 audio -> output [mix ].data [ch ] = source -> audio_output_buf [mix ][ch ];
54415443 }
@@ -5519,10 +5521,30 @@ void obs_source_set_monitoring_type(obs_source_t *source, enum obs_monitoring_ty
55195521 }
55205522
55215523 source -> monitoring_type = type ;
5524+
5525+ #ifdef _WIN32
5526+ // On windows, assign to the extra asio monitoring track (track 7) all sources which have not type
5527+ // OBS_MONITORING_TYPE_NONE.
5528+ if (type != OBS_MONITORING_TYPE_NONE ) {
5529+ source -> audio_mixers |= 1 << (MAX_AUDIO_MIXES + MAX_AUDIO_MONITORING_MIXES - 1 );
5530+ } else {
5531+ source -> audio_mixers &= ~(1 << (MAX_AUDIO_MIXES + MAX_AUDIO_MONITORING_MIXES - 1 ));
5532+ }
5533+ #endif
55225534}
55235535
55245536enum obs_monitoring_type obs_source_get_monitoring_type (const obs_source_t * source )
55255537{
5538+ #ifdef _WIN32
5539+ // If type is OBS_MONITORING_TYPE_NONE, unselect the extra asio monitoring track (track 7) on windows.
5540+ uint32_t mixers = obs_source_get_audio_mixers (source );
5541+ if (source -> monitoring_type == OBS_MONITORING_TYPE_NONE && mixers ) {
5542+ if (mixers & 1 << (MAX_AUDIO_MIXES + MAX_AUDIO_MONITORING_MIXES - 1 )) {
5543+ mixers &= ~(1 << (MAX_AUDIO_MIXES + MAX_AUDIO_MONITORING_MIXES - 1 ));
5544+ obs_source_set_audio_mixers ((obs_source_t * )source , mixers );
5545+ }
5546+ }
5547+ #endif
55265548 return obs_source_valid (source , "obs_source_get_monitoring_type" ) ? source -> monitoring_type
55275549 : OBS_MONITORING_TYPE_NONE ;
55285550}
0 commit comments