@@ -1887,6 +1887,84 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyAudioStream(SDL_AudioStream *stream)
1887
1887
*/
1888
1888
extern SDL_DECLSPEC SDL_AudioStream * SDLCALL SDL_OpenAudioDeviceStream (SDL_AudioDeviceID devid , const SDL_AudioSpec * spec , SDL_AudioStreamCallback callback , void * userdata );
1889
1889
1890
+ /**
1891
+ * A callback that fires around an audio device's processing work.
1892
+ *
1893
+ * This callback fires when a logical audio device is about to start
1894
+ * accessing its bound audio streams, and fires again when it has
1895
+ * finished accessing them. It covers the range of one "iteration" of
1896
+ * the audio device.
1897
+ *
1898
+ * It can be useful to use this callback to update state that must
1899
+ * apply to all bound audio streams atomically: to make sure state
1900
+ * changes don't happen while half of the streams are already processed
1901
+ * for the latest audio buffer.
1902
+ *
1903
+ * This callback should run as quickly as possible and not block for any
1904
+ * significant time, as this callback delays submission of data to the audio
1905
+ * device, which can cause audio playback problems. This callback delays all
1906
+ * audio processing across a single physical audio device: all its logical
1907
+ * devices and all bound audio streams. Use it carefully.
1908
+ *
1909
+ * \param userdata a pointer provided by the app through
1910
+ * SDL_SetAudioPostmixCallback, for its own use.
1911
+ * \param devid the audio device this callback is running for.
1912
+ * \param start true if this is the start of the iteration, false if the end.
1913
+ *
1914
+ * \threadsafety This will run from a background thread owned by SDL. The
1915
+ * application is responsible for locking resources the callback
1916
+ * touches that need to be protected.
1917
+ *
1918
+ * \since This datatype is available since SDL 3.4.0.
1919
+ *
1920
+ * \sa SDL_SetAudioIterationCallbacks
1921
+ */
1922
+ typedef void (SDLCALL * SDL_AudioIterationCallback )(void * userdata , SDL_AudioDeviceID devid , bool start );
1923
+
1924
+ /**
1925
+ * Set callbacks that fire around a new iteration of audio device processing.
1926
+ *
1927
+ * Two callbacks are provided here: one that runs when a device is about to
1928
+ * process its bound audio streams, and another that runs when the device has
1929
+ * finished processing them.
1930
+ *
1931
+ * These callbacks can run at any time, and from any thread; if you need to
1932
+ * serialize access to your app's data, you should provide and use a mutex or
1933
+ * other synchronization device.
1934
+ *
1935
+ * Generally these callbacks are used to apply state that applies to multiple
1936
+ * bound audio streams, with a guarantee that the audio device's thread isn't
1937
+ * halfway through processing them. Generally a finer-grained lock through
1938
+ * SDL_LockAudioStream() is more appropriate.
1939
+ *
1940
+ * The callbacks are extremely time-sensitive; the callback should do the
1941
+ * least amount of work possible and return as quickly as it can. The longer
1942
+ * the callback runs, the higher the risk of audio dropouts or other problems.
1943
+ *
1944
+ * This function will block until the audio device is in between iterations,
1945
+ * so any existing callback that might be running will finish before this
1946
+ * function sets the new callback and returns.
1947
+ *
1948
+ * Physical devices do not accept these callbacks, only logical devices
1949
+ * created through SDL_OpenAudioDevice() can be.
1950
+ *
1951
+ * Setting a NULL callback function disables any previously-set callback.
1952
+ * Either callback may be NULL, and the same callback is permitted to be used
1953
+ * for both.
1954
+ *
1955
+ * \param devid the ID of an opened audio device.
1956
+ * \param start a callback function to be called at the start of an iteration. Can be NULL.
1957
+ * \param end a callback function to be called at the end of an iteration. Can be NULL.
1958
+ * \param userdata app-controlled pointer passed to callback. Can be NULL.
1959
+ * \returns true on success or false on failure; call SDL_GetError() for more
1960
+ * information.
1961
+ *
1962
+ * \threadsafety It is safe to call this function from any thread.
1963
+ *
1964
+ * \since This function is available since SDL 3.4.0.
1965
+ */
1966
+ extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioIterationCallbacks (SDL_AudioDeviceID devid , SDL_AudioIterationCallback start , SDL_AudioIterationCallback end , void * userdata );
1967
+
1890
1968
/**
1891
1969
* A callback that fires when data is about to be fed to an audio device.
1892
1970
*
0 commit comments