@@ -529,6 +529,15 @@ fn C.SDL_GetAudioDeviceName(devid AudioDeviceID) &char
529529
530530// get_audio_device_name gets the human-readable name of a specific audio device.
531531//
532+ // **WARNING**: this function will work with SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK
533+ // and SDL_AUDIO_DEVICE_DEFAULT_RECORDING, returning the current default
534+ // physical devices' names. However, as the default device may change at any
535+ // time, it is likely better to show a generic name to the user, like "System
536+ // default audio device" or perhaps "default [currently %s]". Do not store
537+ // this name to disk to reidentify the device in a later run of the program,
538+ // as the default might change in general, and the string will be the name of
539+ // a specific device and not the abstract system default.
540+ //
532541// `devid` devid the instance ID of the device to query.
533542// returns the name of the audio device, or NULL on failure; call
534543// SDL_GetError() for more information.
@@ -1021,7 +1030,8 @@ fn C.SDL_GetAudioStreamDevice(stream &AudioStream) AudioDeviceID
10211030
10221031// get_audio_stream_device querys an audio stream for its currently-bound device.
10231032//
1024- // This reports the audio device that an audio stream is currently bound to.
1033+ // This reports the logical audio device that an audio stream is currently
1034+ // bound to.
10251035//
10261036// If not bound, or invalid, this returns zero, which is not a valid device
10271037// ID.
@@ -1069,6 +1079,17 @@ fn C.SDL_GetAudioStreamProperties(stream &AudioStream) PropertiesID
10691079
10701080// get_audio_stream_properties gets the properties associated with an audio stream.
10711081//
1082+ // The application can hang any data it wants here, but the following
1083+ // properties are understood by SDL:
1084+ //
1085+ // - `SDL_PROP_AUDIOSTREAM_AUTO_CLEANUP_BOOLEAN`: if true (the default), the
1086+ // stream be automatically cleaned up when the audio subsystem quits. If set
1087+ // to false, the streams will persist beyond that. This property is ignored
1088+ // for streams created through SDL_OpenAudioDeviceStream(), and will always
1089+ // be cleaned up. Streams that are not cleaned up will still be unbound from
1090+ // devices when the audio subsystem quits. This property was added in SDL
1091+ // 3.4.0.
1092+ //
10721093// `stream` stream the SDL_AudioStream to query.
10731094// returns a valid property ID on success or 0 on failure; call
10741095// SDL_GetError() for more information.
@@ -1080,6 +1101,8 @@ pub fn get_audio_stream_properties(stream &AudioStream) PropertiesID {
10801101 return C.SDL_GetAudioStreamProperties (stream)
10811102}
10821103
1104+ pub const prop_audiostream_auto_cleanup_boolean = & char (C.SDL_PROP_AUDIOSTREAM_AUTO_CLEANUP_BOOLEAN) // 'SDL.audiostream.auto_cleanup'
1105+
10831106// C.SDL_GetAudioStreamFormat [official documentation](https://wiki.libsdl.org/SDL3/SDL_GetAudioStreamFormat)
10841107fn C.SDL_GetAudioStreamFormat (stream & AudioStream, src_spec & AudioSpec, dst_spec & AudioSpec) bool
10851108
@@ -1167,14 +1190,14 @@ fn C.SDL_SetAudioStreamFrequencyRatio(stream &AudioStream, ratio f32) bool
11671190//
11681191// The frequency ratio is used to adjust the rate at which input data is
11691192// consumed. Changing this effectively modifies the speed and pitch of the
1170- // audio. A value greater than 1.0 will play the audio faster, and at a higher
1171- // pitch. A value less than 1.0 will play the audio slower, and at a lower
1172- // pitch.
1193+ // audio. A value greater than 1.0f will play the audio faster, and at a
1194+ // higher pitch. A value less than 1.0f will play the audio slower, and at a
1195+ // lower pitch. 1.0f means play at normal speed .
11731196//
11741197// This is applied during SDL_GetAudioStreamData, and can be continuously
11751198// changed to create various effects.
11761199//
1177- // `stream` stream the stream the frequency ratio is being changed.
1200+ // `stream` stream the stream on which the frequency ratio is being changed.
11781201// `ratio` ratio the frequency ratio. 1.0 is normal speed. Must be between 0.01
11791202// and 100.
11801203// returns true on success or false on failure; call SDL_GetError() for more
@@ -1351,7 +1374,7 @@ fn C.SDL_SetAudioStreamInputChannelMap(stream &AudioStream, const_chmap &int, co
13511374// NOTE: (thread safety) It is safe to call this function from any thread, as it holds
13521375// a stream-specific mutex while running. Don't change the
13531376// stream's format to have a different number of channels from a
1354- // a different thread at the same time, though!
1377+ // different thread at the same time, though!
13551378//
13561379// NOTE: This function is available since SDL 3.2.0.
13571380//
@@ -1368,7 +1391,7 @@ fn C.SDL_SetAudioStreamOutputChannelMap(stream &AudioStream, const_chmap &int, c
13681391// Channel maps are optional; most things do not need them, instead passing
13691392// data in the [order that SDL expects](CategoryAudio#channel-layouts).
13701393//
1371- // The output channel map reorders data that leaving a stream via
1394+ // The output channel map reorders data that is leaving a stream via
13721395// SDL_GetAudioStreamData.
13731396//
13741397// Each item in the array represents an input channel, and its value is the
@@ -1454,6 +1477,143 @@ pub fn put_audio_stream_data(stream &AudioStream, const_buf voidptr, len int) bo
14541477 return C.SDL_PutAudioStreamData (stream, const_buf, len)
14551478}
14561479
1480+ // AudioStreamDataCompleteCallback as callback that fires for completed SDL_PutAudioStreamDataNoCopy() data.
1481+ //
1482+ // When using SDL_PutAudioStreamDataNoCopy() to provide data to an
1483+ // SDL_AudioStream, it's not safe to dispose of the data until the stream has
1484+ // completely consumed it. Often times it's difficult to know exactly when
1485+ // this has happened.
1486+ //
1487+ // This callback fires once when the stream no longer needs the buffer,
1488+ // allowing the app to easily free or reuse it.
1489+ //
1490+ // `userdata` userdata an opaque pointer provided by the app for their personal
1491+ // use.
1492+ // `buf` buf the pointer provided to SDL_PutAudioStreamDataNoCopy().
1493+ // `buflen` buflen the size of buffer, in bytes, provided to
1494+ // SDL_PutAudioStreamDataNoCopy().
1495+ //
1496+ // NOTE: (thread safety) This callbacks may run from any thread, so if you need to
1497+ // protect shared data, you should use SDL_LockAudioStream to
1498+ // serialize access; this lock will be held before your callback
1499+ // is called, so your callback does not need to manage the lock
1500+ // explicitly.
1501+ //
1502+ // NOTE: This datatype is available since SDL 3.4.0.
1503+ //
1504+ // See also: set_audio_stream_get_callback (SDL_SetAudioStreamGetCallback)
1505+ // See also: set_audio_stream_put_callback (SDL_SetAudioStreamPutCallback)
1506+ //
1507+ // [Official documentation](https://wiki.libsdl.org/SDL3/SDL_AudioStreamDataCompleteCallback)
1508+ pub type AudioStreamDataCompleteCallback = fn (userdata voidptr , const_buf voidptr , buflen int )
1509+
1510+ // C.SDL_PutAudioStreamDataNoCopy [official documentation](https://wiki.libsdl.org/SDL3/SDL_PutAudioStreamDataNoCopy)
1511+ fn C.SDL_PutAudioStreamDataNoCopy (stream & AudioStream, const_buf voidptr , len int , callback AudioStreamDataCompleteCallback, userdata voidptr ) bool
1512+
1513+ // put_audio_stream_data_no_copy adds external data to an audio stream without copying it.
1514+ //
1515+ // Unlike SDL_PutAudioStreamData(), this function does not make a copy of the
1516+ // provided data, instead storing the provided pointer. This means that the
1517+ // put operation does not need to allocate and copy the data, but the original
1518+ // data must remain available until the stream is done with it, either by
1519+ // being read from the stream in its entirety, or a call to
1520+ // SDL_ClearAudioStream() or SDL_DestroyAudioStream().
1521+ //
1522+ // The data must match the format/channels/samplerate specified in the latest
1523+ // call to SDL_SetAudioStreamFormat, or the format specified when creating the
1524+ // stream if it hasn't been changed.
1525+ //
1526+ // An optional callback may be provided, which is called when the stream no
1527+ // longer needs the data. Once this callback fires, the stream will not access
1528+ // the data again. This callback will fire for any reason the data is no
1529+ // longer needed, including clearing or destroying the stream.
1530+ //
1531+ // Note that there is still an allocation to store tracking information, so
1532+ // this function is more efficient for larger blocks of data. If you're
1533+ // planning to put a few samples at a time, it will be more efficient to use
1534+ // SDL_PutAudioStreamData(), which allocates and buffers in blocks.
1535+ //
1536+ // `stream` stream the stream the audio data is being added to.
1537+ // `buf` buf a pointer to the audio data to add.
1538+ // `len` len the number of bytes to add to the stream.
1539+ // `callback` callback the callback function to call when the data is no longer
1540+ // needed by the stream. May be NULL.
1541+ // `userdata` userdata an opaque pointer provided to the callback for its own
1542+ // personal use.
1543+ // returns true on success or false on failure; call SDL_GetError() for more
1544+ // information.
1545+ //
1546+ // NOTE: (thread safety) It is safe to call this function from any thread, but if the
1547+ // stream has a callback set, the caller might need to manage
1548+ // extra locking.
1549+ //
1550+ // NOTE: This function is available since SDL 3.4.0.
1551+ //
1552+ // See also: clear_audio_stream (SDL_ClearAudioStream)
1553+ // See also: flush_audio_stream (SDL_FlushAudioStream)
1554+ // See also: get_audio_stream_data (SDL_GetAudioStreamData)
1555+ // See also: get_audio_stream_queued (SDL_GetAudioStreamQueued)
1556+ pub fn put_audio_stream_data_no_copy (stream & AudioStream, const_buf voidptr , len int , callback AudioStreamDataCompleteCallback, userdata voidptr ) bool {
1557+ return C.SDL_PutAudioStreamDataNoCopy (stream, const_buf, len, callback, userdata)
1558+ }
1559+
1560+ // C.SDL_PutAudioStreamPlanarData [official documentation](https://wiki.libsdl.org/SDL3/SDL_PutAudioStreamPlanarData)
1561+ fn C.SDL_PutAudioStreamPlanarData (stream & AudioStream, const_channel_buffers voidptr , num_channels int , num_samples int ) bool
1562+
1563+ // put_audio_stream_planar_data adds data to the stream with each channel in a separate array.
1564+ //
1565+ // This data must match the format/channels/samplerate specified in the latest
1566+ // call to SDL_SetAudioStreamFormat, or the format specified when creating the
1567+ // stream if it hasn't been changed.
1568+ //
1569+ // The data will be interleaved and queued. Note that SDL_AudioStream only
1570+ // operates on interleaved data, so this is simply a convenience function for
1571+ // easily queueing data from sources that provide separate arrays. There is no
1572+ // equivalent function to retrieve planar data.
1573+ //
1574+ // The arrays in `channel_buffers` are ordered as they are to be interleaved;
1575+ // the first array will be the first sample in the interleaved data. Any
1576+ // individual array may be NULL; in this case, silence will be interleaved for
1577+ // that channel.
1578+ //
1579+ // `num_channels` specifies how many arrays are in `channel_buffers`. This can
1580+ // be used as a safety to prevent overflow, in case the stream format has
1581+ // changed elsewhere. If more channels are specified than the current input
1582+ // spec, they are ignored. If less channels are specified, the missing arrays
1583+ // are treated as if they are NULL (silence is written to those channels). If
1584+ // the count is -1, SDL will assume the array count matches the current input
1585+ // spec.
1586+ //
1587+ // Note that `num_samples` is the number of _samples per array_. This can also
1588+ // be thought of as the number of _sample frames_ to be queued. A value of 1
1589+ // with stereo arrays will queue two samples to the stream. This is different
1590+ // than SDL_PutAudioStreamData, which wants the size of a single array in
1591+ // bytes.
1592+ //
1593+ // `stream` stream the stream the audio data is being added to.
1594+ // `channel_buffers` channel_buffers a pointer to an array of arrays, one array per
1595+ // channel.
1596+ // `num_channels` num_channels the number of arrays in `channel_buffers` or -1.
1597+ // `num_samples` num_samples the number of _samples_ per array to write to the
1598+ // stream.
1599+ // returns true on success or false on failure; call SDL_GetError() for more
1600+ // information.
1601+ //
1602+ // NOTE: (thread safety) It is safe to call this function from any thread, but if the
1603+ // stream has a callback set, the caller might need to manage
1604+ // extra locking.
1605+ //
1606+ // NOTE: This function is available since SDL 3.4.0.
1607+ //
1608+ // See also: clear_audio_stream (SDL_ClearAudioStream)
1609+ // See also: flush_audio_stream (SDL_FlushAudioStream)
1610+ // See also: get_audio_stream_data (SDL_GetAudioStreamData)
1611+ // See also: get_audio_stream_queued (SDL_GetAudioStreamQueued)
1612+ pub fn put_audio_stream_planar_data (stream & AudioStream, const_channel_buffers voidptr , num_channels int , num_samples int ) bool {
1613+ return C.SDL_PutAudioStreamPlanarData (stream, const_channel_buffers, num_channels,
1614+ num_samples)
1615+ }
1616+
14571617// C.SDL_GetAudioStreamData [official documentation](https://wiki.libsdl.org/SDL3/SDL_GetAudioStreamData)
14581618fn C.SDL_GetAudioStreamData (stream & AudioStream, buf voidptr , len int ) int
14591619
@@ -1641,6 +1801,9 @@ fn C.SDL_ResumeAudioStreamDevice(stream &AudioStream) bool
16411801// previously been paused. Once unpaused, any bound audio streams will begin
16421802// to progress again, and audio can be generated.
16431803//
1804+ // SDL_OpenAudioDeviceStream opens audio devices in a paused state, so this
1805+ // function call is required for audio playback to begin on such devices.
1806+ //
16441807// `stream` stream the audio stream associated with the audio device to resume.
16451808// returns true on success or false on failure; call SDL_GetError() for more
16461809// information.
@@ -1913,7 +2076,7 @@ fn C.SDL_OpenAudioDeviceStream(devid AudioDeviceID, const_spec &AudioSpec, callb
19132076// Also unlike other functions, the audio device begins paused. This is to map
19142077// more closely to SDL2-style behavior, since there is no extra step here to
19152078// bind a stream to begin audio flowing. The audio device should be resumed
1916- // with ` SDL_ResumeAudioStreamDevice(stream);`
2079+ // with SDL_ResumeAudioStreamDevice().
19172080//
19182081// This function works with both playback and recording devices.
19192082//
0 commit comments