@@ -942,7 +942,10 @@ extern SDL_DECLSPEC void SDLCALL SDL_CloseAudioDevice(SDL_AudioDeviceID devid);
942
942
* Binding a stream to a device will set its output format for playback
943
943
* devices, and its input format for recording devices, so they match the
944
944
* device's settings. The caller is welcome to change the other end of the
945
- * stream's format at any time with SDL_SetAudioStreamFormat().
945
+ * stream's format at any time with SDL_SetAudioStreamFormat(). If the other
946
+ * end of the stream's format has never been set (the audio stream was created
947
+ * with a NULL audio spec), this function will set it to match the device
948
+ * end's format.
946
949
*
947
950
* \param devid an audio device to bind a stream to.
948
951
* \param streams an array of audio streams to bind.
@@ -1021,7 +1024,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_UnbindAudioStream(SDL_AudioStream *stream);
1021
1024
/**
1022
1025
* Query an audio stream for its currently-bound device.
1023
1026
*
1024
- * This reports the audio device that an audio stream is currently bound to.
1027
+ * This reports the logical audio device that an audio stream is currently
1028
+ * bound to.
1025
1029
*
1026
1030
* If not bound, or invalid, this returns zero, which is not a valid device
1027
1031
* ID.
@@ -1063,6 +1067,17 @@ extern SDL_DECLSPEC SDL_AudioStream * SDLCALL SDL_CreateAudioStream(const SDL_Au
1063
1067
/**
1064
1068
* Get the properties associated with an audio stream.
1065
1069
*
1070
+ * The application can hang any data it wants here, but the following
1071
+ * properties are understood by SDL:
1072
+ *
1073
+ * - `SDL_PROP_AUDIOSTREAM_AUTO_CLEANUP_BOOLEAN`: if true (the default), the
1074
+ * stream be automatically cleaned up when the audio subsystem quits. If set
1075
+ * to false, the streams will persist beyond that. This property is ignored
1076
+ * for streams created through SDL_OpenAudioDeviceStream(), and will always
1077
+ * be cleaned up. Streams that are not cleaned up will still be unbound from
1078
+ * devices when the audio subsystem quits. This property was added in SDL
1079
+ * 3.4.0.
1080
+ *
1066
1081
* \param stream the SDL_AudioStream to query.
1067
1082
* \returns a valid property ID on success or 0 on failure; call
1068
1083
* SDL_GetError() for more information.
@@ -1073,6 +1088,9 @@ extern SDL_DECLSPEC SDL_AudioStream * SDLCALL SDL_CreateAudioStream(const SDL_Au
1073
1088
*/
1074
1089
extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetAudioStreamProperties (SDL_AudioStream * stream );
1075
1090
1091
+ #define SDL_PROP_AUDIOSTREAM_AUTO_CLEANUP_BOOLEAN "SDL.audiostream.auto_cleanup"
1092
+
1093
+
1076
1094
/**
1077
1095
* Query the current format of an audio stream.
1078
1096
*
@@ -1149,14 +1167,14 @@ extern SDL_DECLSPEC float SDLCALL SDL_GetAudioStreamFrequencyRatio(SDL_AudioStre
1149
1167
*
1150
1168
* The frequency ratio is used to adjust the rate at which input data is
1151
1169
* consumed. Changing this effectively modifies the speed and pitch of the
1152
- * audio. A value greater than 1.0 will play the audio faster, and at a higher
1153
- * pitch. A value less than 1.0 will play the audio slower, and at a lower
1154
- * pitch.
1170
+ * audio. A value greater than 1.0f will play the audio faster, and at a
1171
+ * higher pitch. A value less than 1.0f will play the audio slower, and at a
1172
+ * lower pitch. 1.0f means play at normal speed .
1155
1173
*
1156
1174
* This is applied during SDL_GetAudioStreamData, and can be continuously
1157
1175
* changed to create various effects.
1158
1176
*
1159
- * \param stream the stream the frequency ratio is being changed.
1177
+ * \param stream the stream on which the frequency ratio is being changed.
1160
1178
* \param ratio the frequency ratio. 1.0 is normal speed. Must be between 0.01
1161
1179
* and 100.
1162
1180
* \returns true on success or false on failure; call SDL_GetError() for more
@@ -1332,7 +1350,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamInputChannelMap(SDL_AudioStre
1332
1350
* Channel maps are optional; most things do not need them, instead passing
1333
1351
* data in the [order that SDL expects](CategoryAudio#channel-layouts).
1334
1352
*
1335
- * The output channel map reorders data that leaving a stream via
1353
+ * The output channel map reorders data that is leaving a stream via
1336
1354
* SDL_GetAudioStreamData.
1337
1355
*
1338
1356
* Each item in the array represents an input channel, and its value is the
@@ -1414,6 +1432,136 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamOutputChannelMap(SDL_AudioStr
1414
1432
*/
1415
1433
extern SDL_DECLSPEC bool SDLCALL SDL_PutAudioStreamData (SDL_AudioStream * stream , const void * buf , int len );
1416
1434
1435
+ /**
1436
+ * A callback that fires for completed SDL_PutAudioStreamDataNoCopy() data.
1437
+ *
1438
+ * When using SDL_PutAudioStreamDataNoCopy() to provide data to an
1439
+ * SDL_AudioStream, it's not safe to dispose of the data until the stream has
1440
+ * completely consumed it. Often times it's difficult to know exactly when
1441
+ * this has happened.
1442
+ *
1443
+ * This callback fires once when the stream no longer needs the buffer,
1444
+ * allowing the app to easily free or reuse it.
1445
+ *
1446
+ * \param userdata an opaque pointer provided by the app for their personal
1447
+ * use.
1448
+ * \param buf the pointer provided to SDL_PutAudioStreamDataNoCopy().
1449
+ * \param buflen the size of buffer, in bytes, provided to
1450
+ * SDL_PutAudioStreamDataNoCopy().
1451
+ *
1452
+ * \threadsafety This callbacks may run from any thread, so if you need to
1453
+ * protect shared data, you should use SDL_LockAudioStream to
1454
+ * serialize access; this lock will be held before your callback
1455
+ * is called, so your callback does not need to manage the lock
1456
+ * explicitly.
1457
+ *
1458
+ * \since This datatype is available since SDL 3.4.0.
1459
+ *
1460
+ * \sa SDL_SetAudioStreamGetCallback
1461
+ * \sa SDL_SetAudioStreamPutCallback
1462
+ */
1463
+ typedef void (SDLCALL * SDL_AudioStreamDataCompleteCallback )(void * userdata , const void * buf , int buflen );
1464
+
1465
+ /**
1466
+ * Add external data to an audio stream without copying it.
1467
+ *
1468
+ * Unlike SDL_PutAudioStreamData(), this function does not make a copy of the
1469
+ * provided data, instead storing the provided pointer. This means that the
1470
+ * put operation does not need to allocate and copy the data, but the original
1471
+ * data must remain available until the stream is done with it, either by
1472
+ * being read from the stream in its entirety, or a call to
1473
+ * SDL_ClearAudioStream() or SDL_DestroyAudioStream().
1474
+ *
1475
+ * The data must match the format/channels/samplerate specified in the latest
1476
+ * call to SDL_SetAudioStreamFormat, or the format specified when creating the
1477
+ * stream if it hasn't been changed.
1478
+ *
1479
+ * An optional callback may be provided, which is called when the stream no
1480
+ * longer needs the data. Once this callback fires, the stream will not access
1481
+ * the data again. This callback will fire for any reason the data is no
1482
+ * longer needed, including clearing or destroying the stream.
1483
+ *
1484
+ * Note that there is still an allocation to store tracking information, so
1485
+ * this function is more efficient for larger blocks of data. If you're
1486
+ * planning to put a few samples at a time, it will be more efficient to use
1487
+ * SDL_PutAudioStreamData(), which allocates and buffers in blocks.
1488
+ *
1489
+ * \param stream the stream the audio data is being added to.
1490
+ * \param buf a pointer to the audio data to add.
1491
+ * \param len the number of bytes to add to the stream.
1492
+ * \param callback the callback function to call when the data is no longer
1493
+ * needed by the stream. May be NULL.
1494
+ * \param userdata an opaque pointer provided to the callback for its own
1495
+ * personal use.
1496
+ * \returns true on success or false on failure; call SDL_GetError() for more
1497
+ * information.
1498
+ *
1499
+ * \threadsafety It is safe to call this function from any thread, but if the
1500
+ * stream has a callback set, the caller might need to manage
1501
+ * extra locking.
1502
+ *
1503
+ * \since This function is available since SDL 3.4.0.
1504
+ *
1505
+ * \sa SDL_ClearAudioStream
1506
+ * \sa SDL_FlushAudioStream
1507
+ * \sa SDL_GetAudioStreamData
1508
+ * \sa SDL_GetAudioStreamQueued
1509
+ */
1510
+ extern SDL_DECLSPEC bool SDLCALL SDL_PutAudioStreamDataNoCopy (SDL_AudioStream * stream , const void * buf , int len , SDL_AudioStreamDataCompleteCallback callback , void * userdata );
1511
+
1512
+ /**
1513
+ * Add data to the stream with each channel in a separate array.
1514
+ *
1515
+ * This data must match the format/channels/samplerate specified in the latest
1516
+ * call to SDL_SetAudioStreamFormat, or the format specified when creating the
1517
+ * stream if it hasn't been changed.
1518
+ *
1519
+ * The data will be interleaved and queued. Note that SDL_AudioStream only
1520
+ * operates on interleaved data, so this is simply a convenience function for
1521
+ * easily queueing data from sources that provide separate arrays. There is no
1522
+ * equivalent function to retrieve planar data.
1523
+ *
1524
+ * The arrays in `channel_buffers` are ordered as they are to be interleaved;
1525
+ * the first array will be the first sample in the interleaved data. Any
1526
+ * individual array may be NULL; in this case, silence will be interleaved for
1527
+ * that channel.
1528
+ *
1529
+ * `num_channels` specifies how many arrays are in `channel_buffers`. This can
1530
+ * be used as a safety to prevent overflow, in case the stream format has
1531
+ * changed elsewhere. If more channels are specified than the current input
1532
+ * spec, they are ignored. If less channels are specified, the missing arrays
1533
+ * are treated as if they are NULL (silence is written to those channels). If
1534
+ * the count is -1, SDL will assume the array count matches the current input
1535
+ * spec.
1536
+ *
1537
+ * Note that `num_samples` is the number of _samples per array_. This can also
1538
+ * be thought of as the number of _sample frames_ to be queued. A value of 1
1539
+ * with stereo arrays will queue two samples to the stream. This is different
1540
+ * than SDL_PutAudioStreamData, which wants the size of a single array in
1541
+ * bytes.
1542
+ *
1543
+ * \param stream the stream the audio data is being added to.
1544
+ * \param channel_buffers a pointer to an array of arrays, one array per
1545
+ * channel.
1546
+ * \param num_channels the number of arrays in `channel_buffers` or -1.
1547
+ * \param num_samples the number of _samples_ per array to write to the
1548
+ * stream.
1549
+ * \returns true on success or false on failure; call SDL_GetError() for more
1550
+ * information.
1551
+ *
1552
+ * \threadsafety It is safe to call this function from any thread, but if the
1553
+ * stream has a callback set, the caller might need to manage
1554
+ * extra locking.
1555
+ *
1556
+ * \since This function is available since SDL 3.4.0.
1557
+ *
1558
+ * \sa SDL_ClearAudioStream
1559
+ * \sa SDL_FlushAudioStream
1560
+ * \sa SDL_GetAudioStreamData
1561
+ * \sa SDL_GetAudioStreamQueued
1562
+ */
1563
+ extern SDL_DECLSPEC bool SDLCALL SDL_PutAudioStreamPlanarData (SDL_AudioStream * stream , const void * const * channel_buffers , int num_channels , int num_samples );
1564
+
1417
1565
/**
1418
1566
* Get converted/resampled data from the stream.
1419
1567
*
@@ -1583,8 +1731,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_PauseAudioStreamDevice(SDL_AudioStream *str
1583
1731
* previously been paused. Once unpaused, any bound audio streams will begin
1584
1732
* to progress again, and audio can be generated.
1585
1733
*
1586
- * Remember, SDL_OpenAudioDeviceStream opens device in a paused state, so this
1587
- * function call is required for audio playback to begin on such device .
1734
+ * SDL_OpenAudioDeviceStream opens audio devices in a paused state, so this
1735
+ * function call is required for audio playback to begin on such devices .
1588
1736
*
1589
1737
* \param stream the audio stream associated with the audio device to resume.
1590
1738
* \returns true on success or false on failure; call SDL_GetError() for more
@@ -1717,7 +1865,7 @@ typedef void (SDLCALL *SDL_AudioStreamCallback)(void *userdata, SDL_AudioStream
1717
1865
* audio to the stream during this call; if needed, the request that triggered
1718
1866
* this callback will obtain the new data immediately.
1719
1867
*
1720
- * The callback's `approx_request ` argument is roughly how many bytes of
1868
+ * The callback's `additional_amount ` argument is roughly how many bytes of
1721
1869
* _unconverted_ data (in the stream's input format) is needed by the caller,
1722
1870
* although this may overestimate a little for safety. This takes into account
1723
1871
* how much is already in the stream and only asks for any extra necessary to
@@ -1762,13 +1910,13 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamGetCallback(SDL_AudioStream *
1762
1910
* The callback can (optionally) call SDL_GetAudioStreamData() to obtain audio
1763
1911
* from the stream during this call.
1764
1912
*
1765
- * The callback's `approx_request ` argument is how many bytes of _converted_
1766
- * data (in the stream's output format) was provided by the caller, although
1767
- * this may underestimate a little for safety. This value might be less than
1768
- * what is currently available in the stream, if data was already there, and
1769
- * might be less than the caller provided if the stream needs to keep a buffer
1770
- * to aid in resampling. Which means the callback may be provided with zero
1771
- * bytes, and a different amount on each call.
1913
+ * The callback's `additional_amount ` argument is how many bytes of
1914
+ * _converted_ data (in the stream's output format) was provided by the
1915
+ * caller, although this may underestimate a little for safety. This value
1916
+ * might be less than what is currently available in the stream, if data was
1917
+ * already there, and might be less than the caller provided if the stream
1918
+ * needs to keep a buffer to aid in resampling. Which means the callback may
1919
+ * be provided with zero bytes, and a different amount on each call.
1772
1920
*
1773
1921
* The callback may call SDL_GetAudioStreamAvailable to see the total amount
1774
1922
* currently available to read from the stream, instead of the total provided
@@ -1841,7 +1989,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyAudioStream(SDL_AudioStream *stream)
1841
1989
* Also unlike other functions, the audio device begins paused. This is to map
1842
1990
* more closely to SDL2-style behavior, since there is no extra step here to
1843
1991
* bind a stream to begin audio flowing. The audio device should be resumed
1844
- * with ` SDL_ResumeAudioStreamDevice(stream);`
1992
+ * with SDL_ResumeAudioStreamDevice().
1845
1993
*
1846
1994
* This function works with both playback and recording devices.
1847
1995
*
0 commit comments