@@ -1931,6 +1931,84 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyAudioStream(SDL_AudioStream *stream)
1931
1931
*/
1932
1932
extern SDL_DECLSPEC SDL_AudioStream * SDLCALL SDL_OpenAudioDeviceStream (SDL_AudioDeviceID devid , const SDL_AudioSpec * spec , SDL_AudioStreamCallback callback , void * userdata );
1933
1933
1934
+ /**
1935
+ * A callback that fires around an audio device's processing work.
1936
+ *
1937
+ * This callback fires when a logical audio device is about to start
1938
+ * accessing its bound audio streams, and fires again when it has
1939
+ * finished accessing them. It covers the range of one "iteration" of
1940
+ * the audio device.
1941
+ *
1942
+ * It can be useful to use this callback to update state that must
1943
+ * apply to all bound audio streams atomically: to make sure state
1944
+ * changes don't happen while half of the streams are already processed
1945
+ * for the latest audio buffer.
1946
+ *
1947
+ * This callback should run as quickly as possible and not block for any
1948
+ * significant time, as this callback delays submission of data to the audio
1949
+ * device, which can cause audio playback problems. This callback delays all
1950
+ * audio processing across a single physical audio device: all its logical
1951
+ * devices and all bound audio streams. Use it carefully.
1952
+ *
1953
+ * \param userdata a pointer provided by the app through
1954
+ * SDL_SetAudioPostmixCallback, for its own use.
1955
+ * \param devid the audio device this callback is running for.
1956
+ * \param start true if this is the start of the iteration, false if the end.
1957
+ *
1958
+ * \threadsafety This will run from a background thread owned by SDL. The
1959
+ * application is responsible for locking resources the callback
1960
+ * touches that need to be protected.
1961
+ *
1962
+ * \since This datatype is available since SDL 3.4.0.
1963
+ *
1964
+ * \sa SDL_SetAudioIterationCallbacks
1965
+ */
1966
+ typedef void (SDLCALL * SDL_AudioIterationCallback )(void * userdata , SDL_AudioDeviceID devid , bool start );
1967
+
1968
+ /**
1969
+ * Set callbacks that fire around a new iteration of audio device processing.
1970
+ *
1971
+ * Two callbacks are provided here: one that runs when a device is about to
1972
+ * process its bound audio streams, and another that runs when the device has
1973
+ * finished processing them.
1974
+ *
1975
+ * These callbacks can run at any time, and from any thread; if you need to
1976
+ * serialize access to your app's data, you should provide and use a mutex or
1977
+ * other synchronization device.
1978
+ *
1979
+ * Generally these callbacks are used to apply state that applies to multiple
1980
+ * bound audio streams, with a guarantee that the audio device's thread isn't
1981
+ * halfway through processing them. Generally a finer-grained lock through
1982
+ * SDL_LockAudioStream() is more appropriate.
1983
+ *
1984
+ * The callbacks are extremely time-sensitive; the callback should do the
1985
+ * least amount of work possible and return as quickly as it can. The longer
1986
+ * the callback runs, the higher the risk of audio dropouts or other problems.
1987
+ *
1988
+ * This function will block until the audio device is in between iterations,
1989
+ * so any existing callback that might be running will finish before this
1990
+ * function sets the new callback and returns.
1991
+ *
1992
+ * Physical devices do not accept these callbacks, only logical devices
1993
+ * created through SDL_OpenAudioDevice() can be.
1994
+ *
1995
+ * Setting a NULL callback function disables any previously-set callback.
1996
+ * Either callback may be NULL, and the same callback is permitted to be used
1997
+ * for both.
1998
+ *
1999
+ * \param devid the ID of an opened audio device.
2000
+ * \param start a callback function to be called at the start of an iteration. Can be NULL.
2001
+ * \param end a callback function to be called at the end of an iteration. Can be NULL.
2002
+ * \param userdata app-controlled pointer passed to callback. Can be NULL.
2003
+ * \returns true on success or false on failure; call SDL_GetError() for more
2004
+ * information.
2005
+ *
2006
+ * \threadsafety It is safe to call this function from any thread.
2007
+ *
2008
+ * \since This function is available since SDL 3.4.0.
2009
+ */
2010
+ extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioIterationCallbacks (SDL_AudioDeviceID devid , SDL_AudioIterationCallback start , SDL_AudioIterationCallback end , void * userdata );
2011
+
1934
2012
/**
1935
2013
* A callback that fires when data is about to be fed to an audio device.
1936
2014
*
0 commit comments