@@ -910,15 +910,29 @@ GENERIC_INTERLEAVE_WITH_NULLS_FUNCTION(32)
910
910
//GENERIC_INTERLEAVE_WITH_NULLS_FUNCTION(64) (we don't have any 64-bit audio data types at the moment.)
911
911
#undef GENERIC_INTERLEAVE_WITH_NULLS_FUNCTION
912
912
913
- static void InterleaveAudioChannels (void * output , const void * const * channel_buffers , int num_samples , const SDL_AudioSpec * spec )
913
+ static void InterleaveAudioChannels (void * output , const void * const * channel_buffers , int channels , int num_samples , const SDL_AudioSpec * spec )
914
914
{
915
- const int channels = spec -> channels ;
916
-
917
915
bool have_null_channel = false;
918
- for (int i = 0 ; i < channels ; i ++ ) {
919
- if (channel_buffers [i ] == NULL ) {
920
- have_null_channel = true;
921
- break ;
916
+ const void * channels_full [16 ];
917
+
918
+ // if didn't specify enough channels, pad out a channel array with NULLs.
919
+ if ((channels >= 0 ) && (channels < spec -> channels )) {
920
+ have_null_channel = true;
921
+ SDL_assert (SDL_IsSupportedChannelCount (spec -> channels ));
922
+ SDL_assert (spec -> channels <= SDL_arraysize (channels_full ));
923
+ SDL_memcpy (channels_full , channel_buffers , channels * sizeof (* channel_buffers ));
924
+ SDL_memset (channels_full + channels , 0 , (spec -> channels - channels ) * sizeof (* channel_buffers ));
925
+ channel_buffers = (const void * const * ) channels_full ;
926
+ }
927
+
928
+ channels = spec -> channels ; // it's either < 0, needs to be clamped to spec->channels, or we just padded it out to spec->channels with channels_full.
929
+
930
+ if (!have_null_channel ) {
931
+ for (int i = 0 ; i < channels ; i ++ ) {
932
+ if (channel_buffers [i ] == NULL ) {
933
+ have_null_channel = true;
934
+ break ;
935
+ }
922
936
}
923
937
}
924
938
@@ -943,7 +957,7 @@ static void InterleaveAudioChannels(void *output, const void * const *channel_bu
943
957
}
944
958
}
945
959
946
- bool SDL_PutAudioStreamPlanarData (SDL_AudioStream * stream , const void * const * channel_buffers , int num_samples )
960
+ bool SDL_PutAudioStreamPlanarData (SDL_AudioStream * stream , const void * const * channel_buffers , int num_channels , int num_samples )
947
961
{
948
962
if (!stream ) {
949
963
return SDL_InvalidParamError ("stream" );
@@ -980,7 +994,7 @@ bool SDL_PutAudioStreamPlanarData(SDL_AudioStream *stream, const void * const *c
980
994
981
995
const int len = SDL_AUDIO_FRAMESIZE (spec ) * num_samples ;
982
996
#if DEBUG_AUDIOSTREAM
983
- SDL_Log ("AUDIOSTREAM: wants to put %d bytes of separated data" , len );
997
+ SDL_Log ("AUDIOSTREAM: wants to put %d bytes of planar data" , len );
984
998
#endif
985
999
986
1000
// Is the data small enough to just interleave it on the stack and put it through the normal interface?
@@ -999,7 +1013,7 @@ bool SDL_PutAudioStreamPlanarData(SDL_AudioStream *stream, const void * const *c
999
1013
callback = FreeAllocatedAudioBuffer ;
1000
1014
}
1001
1015
1002
- InterleaveAudioChannels (data , channel_buffers , num_samples , & spec );
1016
+ InterleaveAudioChannels (data , channel_buffers , num_channels , num_samples , & spec );
1003
1017
1004
1018
// it's okay if the stream format changed on another thread while we didn't hold the lock; PutAudioStreamBufferInternal will notice
1005
1019
// and set up a new track with the right format, and the next SDL_PutAudioStreamData will notice that stream->src_spec doesn't
0 commit comments