@@ -701,7 +701,6 @@ void audio_transmission_event(lua_State *l, MumbleClient *client) {
701
701
mumble_hook_call (client , "OnAudioStream" , 3 );
702
702
703
703
// Keep track of when an audio buffer is outputting data
704
- static bool stream_active = false;
705
704
bool streamed_audio = false;
706
705
707
706
while (current != NULL ) {
@@ -735,39 +734,29 @@ void audio_transmission_event(lua_State *l, MumbleClient *client) {
735
734
continue ;
736
735
}
737
736
738
- streamed_audio = true;
739
737
sf_count_t input_frame_size = (sf_count_t )(client -> audio_frames * (float )context -> samplerate / 1000.0 );
740
738
size_t input_frames_actual = length / sizeof (float ) / context -> channels ;
741
739
sf_count_t input_frames = input_frames_actual < input_frame_size ? input_frames_actual : input_frame_size ;
742
- size_t missing_frames = (didLoop || biggest_read > 0 ) ? 0 : (input_frame_size - input_frames );
743
740
double resample_ratio = (double )AUDIO_SAMPLE_RATE / context -> samplerate ;
744
741
745
- // Handle the audio output for streamed frames
746
- for (int i = 0 ; i < input_frame_size ; i ++ ) {
747
- if (i < missing_frames ) {
748
- // Insert silence for each channel
749
- for (int j = 0 ; j < context -> channels ; j ++ ) {
750
- input_buffer [i * context -> channels + j ] = 0.0 ;
751
- }
752
- } else {
753
- for (int j = 0 ; j < context -> channels ; j ++ ) {
754
- float sample ;
755
- buffer_readFloat (buffer , & sample );
756
- input_buffer [i * context -> channels + j ] = sample ;
757
- }
742
+ for (int i = 0 ; i < input_frames ; i ++ ) {
743
+ for (int j = 0 ; j < context -> channels ; j ++ ) {
744
+ float sample ;
745
+ buffer_readFloat (buffer , & sample );
746
+ input_buffer [i * context -> channels + j ] = sample ;
758
747
}
759
748
}
760
749
761
750
if (context -> channels == 1 ) {
762
- float * stereo_buffer = convert_mono_to_multi (input_buffer , input_frame_size , AUDIO_PLAYBACK_CHANNELS );
751
+ float * stereo_buffer = convert_mono_to_multi (input_buffer , input_frames , AUDIO_PLAYBACK_CHANNELS );
763
752
if (!stereo_buffer ) {
764
753
free (input_buffer );
765
754
continue ;
766
755
}
767
756
free (input_buffer );
768
757
input_buffer = stereo_buffer ;
769
758
} else if (context -> channels > 2 ) {
770
- float * stereo_buffer = downmix_to_stereo (input_buffer , input_frame_size , context -> channels );
759
+ float * stereo_buffer = downmix_to_stereo (input_buffer , input_frames , context -> channels );
771
760
if (!stereo_buffer ) {
772
761
free (input_buffer );
773
762
continue ;
@@ -777,9 +766,10 @@ void audio_transmission_event(lua_State *l, MumbleClient *client) {
777
766
}
778
767
779
768
float * output_audio = NULL ;
780
- int resampled_frames = resample_audio (context -> src_state , input_buffer , & output_audio , input_frame_size , output_frames , resample_ratio , false);
769
+ int resampled_frames = resample_audio (context -> src_state , input_buffer , & output_audio , input_frames , output_frames , resample_ratio , false);
781
770
free (input_buffer );
782
771
if (resampled_frames > 0 ) {
772
+ streamed_audio = true;
783
773
for (int i = 0 ; i < resampled_frames ; i ++ ) {
784
774
client -> audio_output [i ].l += output_audio [i * 2 ];
785
775
client -> audio_output [i ].r += output_audio [i * 2 + 1 ];
@@ -797,7 +787,7 @@ void audio_transmission_event(lua_State *l, MumbleClient *client) {
797
787
}
798
788
799
789
// All streams output nothing
800
- bool stream_ended = stream_active && !streamed_audio ;
790
+ bool stream_ended = client -> audio_stream_active && !streamed_audio ;
801
791
802
792
// Something isn't looping, and either we stopped reading data or a buffer stream stopped sening data.
803
793
bool end_frame = !didLoop && (biggest_read < output_frames && stream_ended );
@@ -807,7 +797,7 @@ void audio_transmission_event(lua_State *l, MumbleClient *client) {
807
797
encode_and_send_audio (client , output_frames , end_frame );
808
798
}
809
799
810
- stream_active = streamed_audio ;
800
+ client -> audio_stream_active = streamed_audio ;
811
801
812
802
lua_stackguard_exit (l );
813
803
}
0 commit comments