Skip to content

Commit c80d695

Browse files
committed
Revert "audio: Added SDL_SetAudioIterationCallbacks()."
This reverts commit 608f706. Didn't end up using this in SDL3_mixer, and it's a super-awkward API if we don't need it. I _might_ bite the bullet and let people lock a physical audio device, though, as I could see that being useful but less awkward for the same reasons I originally wanted it.
1 parent e5d57d8 commit c80d695

File tree

6 files changed

+1
-127
lines changed

6 files changed

+1
-127
lines changed

include/SDL3/SDL_audio.h

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,85 +2035,6 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyAudioStream(SDL_AudioStream *stream)
20352035
*/
20362036
extern SDL_DECLSPEC SDL_AudioStream * SDLCALL SDL_OpenAudioDeviceStream(SDL_AudioDeviceID devid, const SDL_AudioSpec *spec, SDL_AudioStreamCallback callback, void *userdata);
20372037

2038-
/**
2039-
* A callback that fires around an audio device's processing work.
2040-
*
2041-
* This callback fires when a logical audio device is about to start accessing
2042-
* its bound audio streams, and fires again when it has finished accessing
2043-
* them. It covers the range of one "iteration" of the audio device.
2044-
*
2045-
* It can be useful to use this callback to update state that must apply to
2046-
* all bound audio streams atomically: to make sure state changes don't happen
2047-
* while half of the streams are already processed for the latest audio
2048-
* buffer.
2049-
*
2050-
* This callback should run as quickly as possible and not block for any
2051-
* significant time, as this callback delays submission of data to the audio
2052-
* device, which can cause audio playback problems. This callback delays all
2053-
* audio processing across a single physical audio device: all its logical
2054-
* devices and all bound audio streams. Use it carefully.
2055-
*
2056-
* \param userdata a pointer provided by the app through
2057-
* SDL_SetAudioPostmixCallback, for its own use.
2058-
* \param devid the audio device this callback is running for.
2059-
* \param start true if this is the start of the iteration, false if the end.
2060-
*
2061-
* \threadsafety This will run from a background thread owned by SDL. The
2062-
* application is responsible for locking resources the callback
2063-
* touches that need to be protected.
2064-
*
2065-
* \since This datatype is available since SDL 3.4.0.
2066-
*
2067-
* \sa SDL_SetAudioIterationCallbacks
2068-
*/
2069-
typedef void (SDLCALL *SDL_AudioIterationCallback)(void *userdata, SDL_AudioDeviceID devid, bool start);
2070-
2071-
/**
2072-
* Set callbacks that fire around a new iteration of audio device processing.
2073-
*
2074-
* Two callbacks are provided here: one that runs when a device is about to
2075-
* process its bound audio streams, and another that runs when the device has
2076-
* finished processing them.
2077-
*
2078-
* These callbacks can run at any time, and from any thread; if you need to
2079-
* serialize access to your app's data, you should provide and use a mutex or
2080-
* other synchronization device.
2081-
*
2082-
* Generally these callbacks are used to apply state that applies to multiple
2083-
* bound audio streams, with a guarantee that the audio device's thread isn't
2084-
* halfway through processing them. Generally a finer-grained lock through
2085-
* SDL_LockAudioStream() is more appropriate.
2086-
*
2087-
* The callbacks are extremely time-sensitive; the callback should do the
2088-
* least amount of work possible and return as quickly as it can. The longer
2089-
* the callback runs, the higher the risk of audio dropouts or other problems.
2090-
*
2091-
* This function will block until the audio device is in between iterations,
2092-
* so any existing callback that might be running will finish before this
2093-
* function sets the new callback and returns.
2094-
*
2095-
* Physical devices do not accept these callbacks, only logical devices
2096-
* created through SDL_OpenAudioDevice() can be.
2097-
*
2098-
* Setting a NULL callback function disables any previously-set callback.
2099-
* Either callback may be NULL, and the same callback is permitted to be used
2100-
* for both.
2101-
*
2102-
* \param devid the ID of an opened audio device.
2103-
* \param start a callback function to be called at the start of an iteration.
2104-
* Can be NULL.
2105-
* \param end a callback function to be called at the end of an iteration. Can
2106-
* be NULL.
2107-
* \param userdata app-controlled pointer passed to callback. Can be NULL.
2108-
* \returns true on success or false on failure; call SDL_GetError() for more
2109-
* information.
2110-
*
2111-
* \threadsafety It is safe to call this function from any thread.
2112-
*
2113-
* \since This function is available since SDL 3.4.0.
2114-
*/
2115-
extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioIterationCallbacks(SDL_AudioDeviceID devid, SDL_AudioIterationCallback start, SDL_AudioIterationCallback end, void *userdata);
2116-
21172038
/**
21182039
* A callback that fires when data is about to be fed to an audio device.
21192040
*

src/audio/SDL_audio.c

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,23 +1164,9 @@ bool SDL_PlaybackAudioThreadIterate(SDL_AudioDevice *device)
11641164

11651165
// We should have updated this elsewhere if the format changed!
11661166
SDL_assert(SDL_AudioSpecsEqual(&stream->dst_spec, &device->spec, NULL, NULL));
1167-
11681167
SDL_assert(stream->src_spec.format != SDL_AUDIO_UNKNOWN);
11691168

1170-
int br = 0;
1171-
1172-
if (!SDL_GetAtomicInt(&logdev->paused)) {
1173-
if (logdev->iteration_start) {
1174-
logdev->iteration_start(logdev->iteration_userdata, logdev->instance_id, true);
1175-
}
1176-
1177-
br = SDL_GetAudioStreamDataAdjustGain(stream, device_buffer, buffer_size, logdev->gain);
1178-
1179-
if (logdev->iteration_end) {
1180-
logdev->iteration_end(logdev->iteration_userdata, logdev->instance_id, false);
1181-
}
1182-
}
1183-
1169+
const int br = SDL_GetAtomicInt(&logdev->paused) ? 0 : SDL_GetAudioStreamDataAdjustGain(stream, device_buffer, buffer_size, logdev->gain);
11841170
if (br < 0) { // Probably OOM. Kill the audio device; the whole thing is likely dying soon anyhow.
11851171
failed = true;
11861172
SDL_memset(device_buffer, device->silence_value, buffer_size); // just supply silence to the device before we die.
@@ -1218,10 +1204,6 @@ bool SDL_PlaybackAudioThreadIterate(SDL_AudioDevice *device)
12181204
SDL_memset(mix_buffer, '\0', work_buffer_size); // start with silence.
12191205
}
12201206

1221-
if (logdev->iteration_start) {
1222-
logdev->iteration_start(logdev->iteration_userdata, logdev->instance_id, true);
1223-
}
1224-
12251207
for (SDL_AudioStream *stream = logdev->bound_streams; stream; stream = stream->next_binding) {
12261208
// We should have updated this elsewhere if the format changed!
12271209
SDL_assert(SDL_AudioSpecsEqual(&stream->dst_spec, &outspec, NULL, NULL));
@@ -1246,10 +1228,6 @@ bool SDL_PlaybackAudioThreadIterate(SDL_AudioDevice *device)
12461228
}
12471229
}
12481230

1249-
if (logdev->iteration_end) {
1250-
logdev->iteration_end(logdev->iteration_userdata, logdev->instance_id, false);
1251-
}
1252-
12531231
if (postmix) {
12541232
SDL_assert(mix_buffer == device->postmix_buffer);
12551233
postmix(logdev->postmix_userdata, &outspec, mix_buffer, work_buffer_size);
@@ -1991,21 +1969,6 @@ bool SDL_SetAudioPostmixCallback(SDL_AudioDeviceID devid, SDL_AudioPostmixCallba
19911969
return result;
19921970
}
19931971

1994-
bool SDL_SetAudioIterationCallbacks(SDL_AudioDeviceID devid, SDL_AudioIterationCallback iter_start, SDL_AudioIterationCallback iter_end, void *userdata)
1995-
{
1996-
SDL_AudioDevice *device = NULL;
1997-
SDL_LogicalAudioDevice *logdev = ObtainLogicalAudioDevice(devid, &device);
1998-
bool result = false;
1999-
if (logdev) {
2000-
logdev->iteration_start = iter_start;
2001-
logdev->iteration_end = iter_end;
2002-
logdev->iteration_userdata = userdata;
2003-
result = true;
2004-
}
2005-
ReleaseAudioDevice(device);
2006-
return result;
2007-
}
2008-
20091972
bool SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream * const *streams, int num_streams)
20101973
{
20111974
const bool islogical = !(devid & (1<<1));

src/audio/SDL_sysaudio.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,6 @@ struct SDL_LogicalAudioDevice
264264
// true if device was opened with SDL_OpenAudioDeviceStream (so it forbids binding changes, etc).
265265
bool simplified;
266266

267-
// If non-NULL, callback into the app that alerts it to start/end of device iteration.
268-
SDL_AudioIterationCallback iteration_start;
269-
SDL_AudioIterationCallback iteration_end;
270-
271-
// App-supplied pointer for iteration callbacks.
272-
void *iteration_userdata;
273-
274267
// If non-NULL, callback into the app that lets them access the final postmix buffer.
275268
SDL_AudioPostmixCallback postmix;
276269

src/dynapi/SDL_dynapi.sym

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,6 @@ SDL3_0.0.0 {
12511251
SDL_GetGPUDeviceProperties;
12521252
SDL_CreateGPURenderer;
12531253
SDL_PutAudioStreamPlanarData;
1254-
SDL_SetAudioIterationCallbacks;
12551254
SDL_GetEventDescription;
12561255
SDL_PutAudioStreamDataNoCopy;
12571256
SDL_IsTraySupported;

src/dynapi/SDL_dynapi_overrides.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,6 @@
12761276
#define SDL_GetGPUDeviceProperties SDL_GetGPUDeviceProperties_REAL
12771277
#define SDL_CreateGPURenderer SDL_CreateGPURenderer_REAL
12781278
#define SDL_PutAudioStreamPlanarData SDL_PutAudioStreamPlanarData_REAL
1279-
#define SDL_SetAudioIterationCallbacks SDL_SetAudioIterationCallbacks_REAL
12801279
#define SDL_GetEventDescription SDL_GetEventDescription_REAL
12811280
#define SDL_PutAudioStreamDataNoCopy SDL_PutAudioStreamDataNoCopy_REAL
12821281
#define SDL_IsTraySupported SDL_IsTraySupported_REAL

src/dynapi/SDL_dynapi_procs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,6 @@ SDL_DYNAPI_PROC(bool,SDL_GetRenderTextureAddressMode,(SDL_Renderer *a,SDL_Textur
12841284
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetGPUDeviceProperties,(SDL_GPUDevice *a),(a),return)
12851285
SDL_DYNAPI_PROC(SDL_Renderer*,SDL_CreateGPURenderer,(SDL_Window *a,SDL_GPUShaderFormat b,SDL_GPUDevice **c),(a,b,c),return)
12861286
SDL_DYNAPI_PROC(bool,SDL_PutAudioStreamPlanarData,(SDL_AudioStream *a,const void * const*b,int c,int d),(a,b,c,d),return)
1287-
SDL_DYNAPI_PROC(bool,SDL_SetAudioIterationCallbacks,(SDL_AudioDeviceID a,SDL_AudioIterationCallback b,SDL_AudioIterationCallback c,void *d),(a,b,c,d),return)
12881287
SDL_DYNAPI_PROC(int,SDL_GetEventDescription,(const SDL_Event *a,char *b,int c),(a,b,c),return)
12891288
SDL_DYNAPI_PROC(bool,SDL_PutAudioStreamDataNoCopy,(SDL_AudioStream *a,const void *b,int c,SDL_AudioStreamDataCompleteCallback d,void *e),(a,b,c,d,e),return)
12901289
SDL_DYNAPI_PROC(bool,SDL_IsTraySupported,(void),(),return)

0 commit comments

Comments
 (0)