Skip to content

Commit

Permalink
SDL API renaming: SDL_audio.h
Browse files Browse the repository at this point in the history
Fixes #6879
  • Loading branch information
slouken committed Dec 27, 2022
1 parent 9625fb2 commit 713ba2e
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 129 deletions.
7 changes: 7 additions & 0 deletions WhatsNew.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ General:
* RW_SEEK_SET -> SDL_RW_SEEK_SET
* SDL_FreeWAV has been removed and calls can be replaced with SDL_free
* The following functions have been renamed:
* SDL_AudioStreamAvailable => SDL_GetAudioStreamAvailable
* SDL_AudioStreamClear => SDL_ClearAudioStream
* SDL_AudioStreamFlush => SDL_FlushAudioStream
* SDL_AudioStreamGet => SDL_GetAudioStreamData
* SDL_AudioStreamPut => SDL_PutAudioStreamData
* SDL_FreeAudioStream => SDL_DestroyAudioStream
* SDL_NewAudioStream => SDL_CreateAudioStream
* Removed the following functions from the API, see docs/README-migration.md for details:
* SDL_AudioInit()
* SDL_AudioQuit()
Expand Down
9 changes: 9 additions & 0 deletions docs/README-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ SDL_AudioInit() and SDL_AudioQuit() have been removed. Instead you can call SDL_

SDL_FreeWAV has been removed and calls can be replaced with SDL_free.

The following functions have been renamed:
* SDL_AudioStreamAvailable => SDL_GetAudioStreamAvailable
* SDL_AudioStreamClear => SDL_ClearAudioStream
* SDL_AudioStreamFlush => SDL_FlushAudioStream
* SDL_AudioStreamGet => SDL_GetAudioStreamData
* SDL_AudioStreamPut => SDL_PutAudioStreamData
* SDL_FreeAudioStream => SDL_DestroyAudioStream
* SDL_NewAudioStream => SDL_CreateAudioStream

## SDL_cpuinfo.h

SDL_Has3DNow() has been removed; there is no replacement.
Expand Down
98 changes: 49 additions & 49 deletions include/SDL3/SDL_audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -941,14 +941,14 @@ typedef struct _SDL_AudioStream SDL_AudioStream;
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_AudioStreamPut
* \sa SDL_AudioStreamGet
* \sa SDL_AudioStreamAvailable
* \sa SDL_AudioStreamFlush
* \sa SDL_AudioStreamClear
* \sa SDL_FreeAudioStream
* \sa SDL_PutAudioStreamData
* \sa SDL_GetAudioStreamData
* \sa SDL_GetAudioStreamAvailable
* \sa SDL_FlushAudioStream
* \sa SDL_ClearAudioStream
* \sa SDL_DestroyAudioStream
*/
extern DECLSPEC SDL_AudioStream *SDLCALL SDL_NewAudioStream(SDL_AudioFormat src_format,
extern DECLSPEC SDL_AudioStream *SDLCALL SDL_CreateAudioStream(SDL_AudioFormat src_format,
Uint8 src_channels,
int src_rate,
SDL_AudioFormat dst_format,
Expand All @@ -965,14 +965,14 @@ extern DECLSPEC SDL_AudioStream *SDLCALL SDL_NewAudioStream(SDL_AudioFormat src_
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_NewAudioStream
* \sa SDL_AudioStreamGet
* \sa SDL_AudioStreamAvailable
* \sa SDL_AudioStreamFlush
* \sa SDL_AudioStreamClear
* \sa SDL_FreeAudioStream
* \sa SDL_CreateAudioStream
* \sa SDL_GetAudioStreamData
* \sa SDL_GetAudioStreamAvailable
* \sa SDL_FlushAudioStream
* \sa SDL_ClearAudioStream
* \sa SDL_DestroyAudioStream
*/
extern DECLSPEC int SDLCALL SDL_AudioStreamPut(SDL_AudioStream *stream, const void *buf, int len);
extern DECLSPEC int SDLCALL SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len);

/**
* Get converted/resampled data from the stream
Expand All @@ -984,14 +984,14 @@ extern DECLSPEC int SDLCALL SDL_AudioStreamPut(SDL_AudioStream *stream, const vo
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_NewAudioStream
* \sa SDL_AudioStreamPut
* \sa SDL_AudioStreamAvailable
* \sa SDL_AudioStreamFlush
* \sa SDL_AudioStreamClear
* \sa SDL_FreeAudioStream
* \sa SDL_CreateAudioStream
* \sa SDL_PutAudioStreamData
* \sa SDL_GetAudioStreamAvailable
* \sa SDL_FlushAudioStream
* \sa SDL_ClearAudioStream
* \sa SDL_DestroyAudioStream
*/
extern DECLSPEC int SDLCALL SDL_AudioStreamGet(SDL_AudioStream *stream, void *buf, int len);
extern DECLSPEC int SDLCALL SDL_GetAudioStreamData(SDL_AudioStream *stream, void *buf, int len);

/**
* Get the number of converted/resampled bytes available.
Expand All @@ -1002,14 +1002,14 @@ extern DECLSPEC int SDLCALL SDL_AudioStreamGet(SDL_AudioStream *stream, void *bu
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_NewAudioStream
* \sa SDL_AudioStreamPut
* \sa SDL_AudioStreamGet
* \sa SDL_AudioStreamFlush
* \sa SDL_AudioStreamClear
* \sa SDL_FreeAudioStream
* \sa SDL_CreateAudioStream
* \sa SDL_PutAudioStreamData
* \sa SDL_GetAudioStreamData
* \sa SDL_FlushAudioStream
* \sa SDL_ClearAudioStream
* \sa SDL_DestroyAudioStream
*/
extern DECLSPEC int SDLCALL SDL_AudioStreamAvailable(SDL_AudioStream *stream);
extern DECLSPEC int SDLCALL SDL_GetAudioStreamAvailable(SDL_AudioStream *stream);

/**
* Tell the stream that you're done sending data, and anything being buffered
Expand All @@ -1021,42 +1021,42 @@ extern DECLSPEC int SDLCALL SDL_AudioStreamAvailable(SDL_AudioStream *stream);
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_NewAudioStream
* \sa SDL_AudioStreamPut
* \sa SDL_AudioStreamGet
* \sa SDL_AudioStreamAvailable
* \sa SDL_AudioStreamClear
* \sa SDL_FreeAudioStream
* \sa SDL_CreateAudioStream
* \sa SDL_PutAudioStreamData
* \sa SDL_GetAudioStreamData
* \sa SDL_GetAudioStreamAvailable
* \sa SDL_ClearAudioStream
* \sa SDL_DestroyAudioStream
*/
extern DECLSPEC int SDLCALL SDL_AudioStreamFlush(SDL_AudioStream *stream);
extern DECLSPEC int SDLCALL SDL_FlushAudioStream(SDL_AudioStream *stream);

/**
* Clear any pending data in the stream without converting it
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_NewAudioStream
* \sa SDL_AudioStreamPut
* \sa SDL_AudioStreamGet
* \sa SDL_AudioStreamAvailable
* \sa SDL_AudioStreamFlush
* \sa SDL_FreeAudioStream
* \sa SDL_CreateAudioStream
* \sa SDL_PutAudioStreamData
* \sa SDL_GetAudioStreamData
* \sa SDL_GetAudioStreamAvailable
* \sa SDL_FlushAudioStream
* \sa SDL_DestroyAudioStream
*/
extern DECLSPEC void SDLCALL SDL_AudioStreamClear(SDL_AudioStream *stream);
extern DECLSPEC void SDLCALL SDL_ClearAudioStream(SDL_AudioStream *stream);

/**
* Free an audio stream
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_NewAudioStream
* \sa SDL_AudioStreamPut
* \sa SDL_AudioStreamGet
* \sa SDL_AudioStreamAvailable
* \sa SDL_AudioStreamFlush
* \sa SDL_AudioStreamClear
* \sa SDL_CreateAudioStream
* \sa SDL_PutAudioStreamData
* \sa SDL_GetAudioStreamData
* \sa SDL_GetAudioStreamAvailable
* \sa SDL_FlushAudioStream
* \sa SDL_ClearAudioStream
*/
extern DECLSPEC void SDLCALL SDL_FreeAudioStream(SDL_AudioStream *stream);
extern DECLSPEC void SDLCALL SDL_DestroyAudioStream(SDL_AudioStream *stream);

#define SDL_MIX_MAXVOLUME 128

Expand Down
14 changes: 14 additions & 0 deletions include/SDL3/SDL_oldnames.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@
#ifdef SDL_ENABLE_OLD_NAMES

/* ##SDL_audio.h */
#define SDL_AudioStreamAvailable SDL_GetAudioStreamAvailable
#define SDL_AudioStreamClear SDL_ClearAudioStream
#define SDL_AudioStreamFlush SDL_FlushAudioStream
#define SDL_AudioStreamGet SDL_GetAudioStreamData
#define SDL_AudioStreamPut SDL_PutAudioStreamData
#define SDL_FreeAudioStream SDL_DestroyAudioStream
#define SDL_FreeWAV SDL_free
#define SDL_NewAudioStream SDL_CreateAudioStream

/* ##SDL_keycode.h */
#define KMOD_ALT SDL_KMOD_ALT
Expand Down Expand Up @@ -78,7 +85,14 @@
#else /* !SDL_ENABLE_OLD_NAMES */

/* ##SDL_audio.h */
#define SDL_AudioStreamAvailable SDL_AudioStreamAvailable_renamed_SDL_GetAudioStreamAvailable
#define SDL_AudioStreamClear SDL_AudioStreamClear_renamed_SDL_ClearAudioStream
#define SDL_AudioStreamFlush SDL_AudioStreamFlush_renamed_SDL_FlushAudioStream
#define SDL_AudioStreamGet SDL_AudioStreamGet_renamed_SDL_GetAudioStreamData
#define SDL_AudioStreamPut SDL_AudioStreamPut_renamed_SDL_PutAudioStreamData
#define SDL_FreeAudioStream SDL_FreeAudioStream_renamed_SDL_DestroyAudioStream
#define SDL_FreeWAV SDL_FreeWAV_renamed_SDL_free
#define SDL_NewAudioStream SDL_NewAudioStream_renamed_SDL_CreateAudioStream

/* ##SDL_keycode.h */
#define KMOD_ALT KMOD_ALT_renamed_SDL_KMOD_ALT
Expand Down
20 changes: 10 additions & 10 deletions src/audio/SDL_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,12 +689,12 @@ static int SDLCALL SDL_RunAudio(void *devicep)
if (device->stream) {
/* Stream available audio to device, converting/resampling. */
/* if this fails...oh well. We'll play silence here. */
SDL_AudioStreamPut(device->stream, data, data_len);
SDL_PutAudioStreamData(device->stream, data, data_len);

while (SDL_AudioStreamAvailable(device->stream) >= ((int)device->spec.size)) {
while (SDL_GetAudioStreamAvailable(device->stream) >= ((int)device->spec.size)) {
int got;
data = SDL_AtomicGet(&device->enabled) ? current_audio.impl.GetDeviceBuf(device) : NULL;
got = SDL_AudioStreamGet(device->stream, data ? data : device->work_buffer, device->spec.size);
got = SDL_GetAudioStreamData(device->stream, data ? data : device->work_buffer, device->spec.size);
SDL_assert((got <= 0) || (got == device->spec.size));

if (data == NULL) { /* device is having issues... */
Expand Down Expand Up @@ -763,7 +763,7 @@ static int SDLCALL SDL_CaptureAudio(void *devicep)
if (SDL_AtomicGet(&device->paused)) {
SDL_Delay(delay); /* just so we don't cook the CPU. */
if (device->stream) {
SDL_AudioStreamClear(device->stream);
SDL_ClearAudioStream(device->stream);
}
current_audio.impl.FlushCapture(device); /* dump anything pending. */
continue;
Expand Down Expand Up @@ -805,10 +805,10 @@ static int SDLCALL SDL_CaptureAudio(void *devicep)

if (device->stream) {
/* if this fails...oh well. */
SDL_AudioStreamPut(device->stream, data, data_len);
SDL_PutAudioStreamData(device->stream, data, data_len);

while (SDL_AudioStreamAvailable(device->stream) >= ((int)device->callbackspec.size)) {
const int got = SDL_AudioStreamGet(device->stream, device->work_buffer, device->callbackspec.size);
while (SDL_GetAudioStreamAvailable(device->stream) >= ((int)device->callbackspec.size)) {
const int got = SDL_GetAudioStreamData(device->stream, device->work_buffer, device->callbackspec.size);
SDL_assert((got < 0) || (got == device->callbackspec.size));
if (got != device->callbackspec.size) {
SDL_memset(device->work_buffer, device->spec.silence, device->callbackspec.size);
Expand Down Expand Up @@ -1138,7 +1138,7 @@ static void close_audio_device(SDL_AudioDevice *device)
}

SDL_free(device->work_buffer);
SDL_FreeAudioStream(device->stream);
SDL_DestroyAudioStream(device->stream);

if (device->id > 0) {
SDL_AudioDevice *opendev = open_devices[device->id - 1];
Expand Down Expand Up @@ -1423,11 +1423,11 @@ static SDL_AudioDeviceID open_audio_device(const char *devname, int iscapture,

if (build_stream) {
if (iscapture) {
device->stream = SDL_NewAudioStream(device->spec.format,
device->stream = SDL_CreateAudioStream(device->spec.format,
device->spec.channels, device->spec.freq,
obtained->format, obtained->channels, obtained->freq);
} else {
device->stream = SDL_NewAudioStream(obtained->format, obtained->channels,
device->stream = SDL_CreateAudioStream(obtained->format, obtained->channels,
obtained->freq, device->spec.format,
device->spec.channels, device->spec.freq);
}
Expand Down
Loading

0 comments on commit 713ba2e

Please sign in to comment.