diff --git a/docs/README-migration.md b/docs/README-migration.md index 6eecb10d4..989d245aa 100644 --- a/docs/README-migration.md +++ b/docs/README-migration.md @@ -70,8 +70,8 @@ should be changed to: ```c Uint8 *dst_data = NULL; int dst_len = 0; - if (SDL_ConvertAudioSamples(src_format, src_channels, src_rate, src_len, src_data - dst_format, dst_channels, dst_rate, &dst_len, &dst_data) < 0) { + if (SDL_ConvertAudioSamples(src_format, src_channels, src_rate, src_data, src_len + dst_format, dst_channels, dst_rate, &dst_data, &dst_len) < 0) { /* error */ } do_something(dst_data, dst_len); diff --git a/include/SDL3/SDL_audio.h b/include/SDL3/SDL_audio.h index 09223a62f..0d445798b 100644 --- a/include/SDL3/SDL_audio.h +++ b/include/SDL3/SDL_audio.h @@ -555,7 +555,7 @@ extern DECLSPEC SDL_AudioStatus SDLCALL SDL_GetAudioDeviceStatus(SDL_AudioDevice * * \param dev a device opened by SDL_OpenAudioDevice() * \returns 0 on success or a negative error code on failure; call - * SDL_GetError() for more information. + * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * @@ -580,7 +580,7 @@ extern DECLSPEC int SDLCALL SDL_PlayAudioDevice(SDL_AudioDeviceID dev); * * \param dev a device opened by SDL_OpenAudioDevice() * \returns 0 on success or a negative error code on failure; call - * SDL_GetError() for more information. + * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * @@ -1025,7 +1025,7 @@ extern DECLSPEC Uint32 SDLCALL SDL_GetQueuedAudioSize(SDL_AudioDeviceID dev); * * \param dev the device ID of which to clear the audio queue * \returns 0 on success or a negative error code on failure; call - * SDL_GetError() for more information. + * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * @@ -1079,7 +1079,7 @@ extern DECLSPEC int SDLCALL SDL_ClearQueuedAudio(SDL_AudioDeviceID dev); * * \param dev the ID of the device to be locked * \returns 0 on success or a negative error code on failure; call - * SDL_GetError() for more information. + * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * @@ -1132,14 +1132,14 @@ extern DECLSPEC void SDLCALL SDL_CloseAudioDevice(SDL_AudioDeviceID dev); * \param src_format The format of the source audio * \param src_channels The number of channels of the source audio * \param src_rate The sampling rate of the source audio - * \param src_len The len of src_data * \param src_data The audio data to be converted + * \param src_len The len of src_data * \param dst_format The format of the desired audio output * \param dst_channels The number of channels of the desired audio output * \param dst_rate The sampling rate of the desired audio output - * \param dst_len Will be filled with the len of dst_data * \param dst_data Will be filled with a pointer to converted audio data, * which should be freed with SDL_free(). + * \param dst_len Will be filled with the len of dst_data * \returns 0 on success or a negative error code on failure. On error, * *dst_data will be NULL and so not allocated. * @@ -1150,13 +1150,13 @@ extern DECLSPEC void SDLCALL SDL_CloseAudioDevice(SDL_AudioDeviceID dev); extern DECLSPEC int SDLCALL SDL_ConvertAudioSamples(SDL_AudioFormat src_format, Uint8 src_channels, int src_rate, + const Uint8 *src_data, int src_len, - Uint8 *src_data, SDL_AudioFormat dst_format, Uint8 dst_channels, int dst_rate, - int *dst_len, - Uint8 **dst_data); + Uint8 **dst_data, + int *dst_len); /* Ends C function definitions when using C++ */ #ifdef __cplusplus diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index 6abba6b67..23ee40053 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -1674,8 +1674,8 @@ void SDL_CalculateAudioSpec(SDL_AudioSpec *spec) } int SDL_ConvertAudioSamples( - SDL_AudioFormat src_format, Uint8 src_channels, int src_rate, int src_len, Uint8 *src_data, - SDL_AudioFormat dst_format, Uint8 dst_channels, int dst_rate, int *dst_len, Uint8 **dst_data) + SDL_AudioFormat src_format, Uint8 src_channels, int src_rate, const Uint8 *src_data, int src_len, + SDL_AudioFormat dst_format, Uint8 dst_channels, int dst_rate, Uint8 **dst_data, int *dst_len) { int ret = -1; SDL_AudioStream *stream = NULL; @@ -1684,21 +1684,21 @@ int SDL_ConvertAudioSamples( int real_dst_len; - if (src_len < 0) { - return SDL_InvalidParamError("src_len"); - } if (src_data == NULL) { return SDL_InvalidParamError("src_data"); } - if (dst_len == NULL) { - return SDL_InvalidParamError("dst_len"); + if (src_len < 0) { + return SDL_InvalidParamError("src_len"); } if (dst_data == NULL) { return SDL_InvalidParamError("dst_data"); } + if (dst_len == NULL) { + return SDL_InvalidParamError("dst_len"); + } - *dst_len = 0; *dst_data = NULL; + *dst_len = 0; stream = SDL_CreateAudioStream(src_format, src_channels, src_rate, dst_format, dst_channels, dst_rate); if (stream == NULL) { @@ -1737,8 +1737,8 @@ int SDL_ConvertAudioSamples( end: if (ret != 0) { SDL_free(*dst_data); - *dst_len = 0; *dst_data = NULL; + *dst_len = 0; } SDL_DestroyAudioStream(stream); return ret; diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 4b66477b6..6b68bec35 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -900,7 +900,7 @@ SDL_DYNAPI_PROC(int,SDL_GetRenderVSync,(SDL_Renderer *a, int *b),(a,b),return) SDL_DYNAPI_PROC(int,SDL_PlayAudioDevice,(SDL_AudioDeviceID a),(a),return) SDL_DYNAPI_PROC(void*,SDL_aligned_alloc,(size_t a, size_t b),(a,b),return) SDL_DYNAPI_PROC(void,SDL_aligned_free,(void *a),(a),) -SDL_DYNAPI_PROC(int,SDL_ConvertAudioSamples,(SDL_AudioFormat a, Uint8 b, int c, int d, Uint8 *e, SDL_AudioFormat f, Uint8 g, int h, int *i, Uint8 **j),(a,b,c,d,e,f,g,h,i,j),return) +SDL_DYNAPI_PROC(int,SDL_ConvertAudioSamples,(SDL_AudioFormat a, Uint8 b, int c, const Uint8 *d, int e, SDL_AudioFormat f, Uint8 g, int h, Uint8 **i, int *j),(a,b,c,d,e,f,g,h,i,j),return) SDL_DYNAPI_PROC(SDL_DisplayID*,SDL_GetDisplays,(int *a),(a),return) SDL_DYNAPI_PROC(SDL_DisplayID,SDL_GetPrimaryDisplay,(void),(),return) SDL_DYNAPI_PROC(const SDL_DisplayMode**,SDL_GetFullscreenDisplayModes,(SDL_DisplayID a, int *b),(a,b),return) diff --git a/test/testresample.c b/test/testresample.c index 15eb76c49..281c6b71d 100644 --- a/test/testresample.c +++ b/test/testresample.c @@ -53,8 +53,8 @@ int main(int argc, char **argv) goto end; } - if (SDL_ConvertAudioSamples(spec.format, spec.channels, spec.freq, len, data, - spec.format, cvtchans, cvtfreq, &dst_len, &dst_buf) < 0) { + if (SDL_ConvertAudioSamples(spec.format, spec.channels, spec.freq, data, len, + spec.format, cvtchans, cvtfreq, &dst_buf, &dst_len) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "failed to convert samples: %s\n", SDL_GetError()); ret = 4; goto end;