1 /* 2 DSDL 3 Copyright (C) 2025 Inochi2D Project <luna@foxgirls.gay> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20 21 ========================================================================== 22 23 Simple DirectMedia Layer 24 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> 25 26 This software is provided 'as-is', without any express or implied 27 warranty. In no event will the authors be held liable for any damages 28 arising from the use of this software. 29 30 Permission is granted to anyone to use this software for any purpose, 31 including commercial applications, and to alter it and redistribute it 32 freely, subject to the following restrictions: 33 34 1. The origin of this software must not be misrepresented; you must not 35 claim that you wrote the original software. If you use this software 36 in a product, an acknowledgment in the product documentation would be 37 appreciated but is not required. 38 2. Altered source versions must be plainly marked as such, and must not be 39 misrepresented as being the original software. 40 3. This notice may not be removed or altered from any source distribution. 41 */ 42 43 /** 44 SDL Audio 45 46 See_Also: 47 $(LINK2 https://wiki.libsdl.org/SDL3/CategoryAudio, SDL3 Audio Documentation) 48 49 Copyright: © 2025 Inochi2D Project, © 1997-2025 Sam Lantinga 50 License: Subject to the terms of the Zlib License, as written in the LICENSE file. 51 Authors: 52 Luna Nielsen 53 */ 54 module sdl.audio; 55 import sdl.stdc; 56 import sdl.properties; 57 import sdl.iostream; 58 59 extern (C) nothrow @nogc: 60 61 /** 62 Mask of bits in an SDL_AudioFormat that contains the format bit size. 63 64 Generally one should use SDL_AUDIO_BITSIZE instead of this macro directly. 65 */ 66 enum SDL_AUDIO_MASK_BITSIZE = (0xFFu); 67 68 /** 69 Mask of bits in an SDL_AudioFormat that contain the floating point flag. 70 71 Generally one should use SDL_AUDIO_ISFLOAT instead of this macro directly. 72 */ 73 enum SDL_AUDIO_MASK_FLOAT = (1u << 8); 74 75 /** 76 Mask of bits in an SDL_AudioFormat that contain the bigendian flag. 77 78 Generally one should use SDL_AUDIO_ISBIGENDIAN or SDL_AUDIO_ISLITTLEENDIAN 79 instead of this macro directly. 80 */ 81 enum SDL_AUDIO_MASK_BIG_ENDIAN = (1u << 12); 82 83 /** 84 Mask of bits in an SDL_AudioFormat that contain the signed data flag. 85 86 Generally one should use SDL_AUDIO_ISSIGNED instead of this macro directly. 87 */ 88 enum SDL_AUDIO_MASK_SIGNED = (1u << 15); 89 90 /** 91 Audio format. 92 93 See_Also: 94 $(D SDL_AUDIO_BITSIZE) 95 $(D SDL_AUDIO_BYTESIZE) 96 $(D SDL_AUDIO_ISINT) 97 $(D SDL_AUDIO_ISFLOAT) 98 $(D SDL_AUDIO_ISBIGENDIAN) 99 $(D SDL_AUDIO_ISLITTLEENDIAN) 100 $(D SDL_AUDIO_ISSIGNED) 101 $(D SDL_AUDIO_ISUNSIGNED) 102 */ 103 enum SDL_AudioFormat { 104 SDL_AUDIO_UNKNOWN = 0x0000u, /**< Unspecified audio format*/ 105 SDL_AUDIO_U8 = 0x0008u, /**< Unsigned 8-bit samples*/ 106 SDL_AUDIO_S8 = 0x8008u, /**< Signed 8-bit samples*/ 107 SDL_AUDIO_S16LE = 0x8010u, /**< Signed 16-bit samples*/ 108 SDL_AUDIO_S16BE = 0x9010u, /**< As above, but big-endian byte order*/ 109 SDL_AUDIO_S32LE = 0x8020u, /**< 32-bit integer samples*/ 110 SDL_AUDIO_S32BE = 0x9020u, /**< As above, but big-endian byte order*/ 111 SDL_AUDIO_F32LE = 0x8120u, /**< 32-bit floating point samples*/ 112 SDL_AUDIO_F32BE = 0x9120u, /**< As above, but big-endian byte order*/ 113 } 114 115 /* These represent the current system's byteorder.*/ 116 version (BigEndian) { 117 enum SDL_AudioFormat SDL_AUDIO_S16 = SDL_AudioFormat.SDL_AUDIO_S16BE; 118 enum SDL_AudioFormat SDL_AUDIO_S32 = SDL_AudioFormat.SDL_AUDIO_S32BE; 119 enum SDL_AudioFormat SDL_AUDIO_F32 = SDL_AudioFormat.SDL_AUDIO_F32BE; 120 } else { 121 enum SDL_AudioFormat SDL_AUDIO_S16 = SDL_AudioFormat.SDL_AUDIO_S16LE; 122 enum SDL_AudioFormat SDL_AUDIO_S32 = SDL_AudioFormat.SDL_AUDIO_S32LE; 123 enum SDL_AudioFormat SDL_AUDIO_F32 = SDL_AudioFormat.SDL_AUDIO_F32LE; 124 } 125 126 /** 127 Retrieve the size, in bits, from an SDL_AudioFormat. 128 129 For example, `SDL_AUDIO_BITSIZE(SDL_AUDIO_S16)` returns 16. 130 131 Params: 132 x = an SDL_AudioFormat value. 133 134 Returns: 135 data size in bits. 136 137 Threadsafety: 138 It is safe to call this macro from any thread. 139 */ 140 enum SDL_AUDIO_BITSIZE(x) = ((x) & SDL_AUDIO_MASK_BITSIZE); 141 142 /** 143 Retrieve the size, in bytes, from an SDL_AudioFormat. 144 145 For example, `SDL_AUDIO_BYTESIZE(SDL_AUDIO_S16)` returns 2. 146 147 Params: 148 x = an SDL_AudioFormat value. 149 150 Returns: 151 data size in bytes. 152 153 Threadsafety: 154 It is safe to call this macro from any thread. 155 */ 156 enum SDL_AUDIO_BYTESIZE(x) = (SDL_AUDIO_BITSIZE(x) / 8); 157 158 /** 159 Determine if an SDL_AudioFormat represents floating point data. 160 161 For example, `SDL_AUDIO_ISFLOAT(SDL_AUDIO_S16)` returns 0. 162 163 Params: 164 x = an SDL_AudioFormat value. 165 166 Returns: 167 non-zero if format is floating point, zero otherwise. 168 169 Threadsafety: 170 It is safe to call this macro from any thread. 171 */ 172 enum SDL_AUDIO_ISFLOAT(x) = ((x) & SDL_AUDIO_MASK_FLOAT); 173 174 /** 175 Determine if an SDL_AudioFormat represents bigendian data. 176 177 For example, `SDL_AUDIO_ISBIGENDIAN(SDL_AUDIO_S16LE)` returns 0. 178 179 Params: 180 x = an SDL_AudioFormat value. 181 182 Returns: 183 non-zero if format is bigendian, zero otherwise. 184 185 Threadsafety: 186 It is safe to call this macro from any thread. 187 */ 188 enum SDL_AUDIO_ISBIGENDIAN(x) = ((x) & SDL_AUDIO_MASK_BIG_ENDIAN); 189 190 /** 191 Determine if an SDL_AudioFormat represents littleendian data. 192 193 For example, `SDL_AUDIO_ISLITTLEENDIAN(SDL_AUDIO_S16BE)` returns 0. 194 195 Params: 196 x = an SDL_AudioFormat value. 197 198 Returns: 199 non-zero if format is littleendian, zero otherwise. 200 201 Threadsafety: 202 It is safe to call this macro from any thread. 203 */ 204 enum SDL_AUDIO_ISLITTLEENDIAN(x) = (!SDL_AUDIO_ISBIGENDIAN(x)); 205 206 /** 207 Determine if an SDL_AudioFormat represents signed data. 208 209 For example, `SDL_AUDIO_ISSIGNED(SDL_AUDIO_U8)` returns 0. 210 211 Params: 212 x = an SDL_AudioFormat value. 213 214 Returns: 215 non-zero if format is signed, zero otherwise. 216 217 Threadsafety: 218 It is safe to call this macro from any thread. 219 */ 220 enum SDL_AUDIO_ISSIGNED(x) = ((x) & SDL_AUDIO_MASK_SIGNED); 221 222 /** 223 Determine if an SDL_AudioFormat represents integer data. 224 225 For example, `SDL_AUDIO_ISINT(SDL_AUDIO_F32)` returns 0. 226 227 Params: 228 x = an SDL_AudioFormat value. 229 230 Returns: 231 non-zero if format is integer, zero otherwise. 232 233 Threadsafety: 234 It is safe to call this macro from any thread. 235 */ 236 enum SDL_AUDIO_ISINT(x) = (!SDL_AUDIO_ISFLOAT(x)); 237 238 /** 239 Determine if an SDL_AudioFormat represents unsigned data. 240 241 For example, `SDL_AUDIO_ISUNSIGNED(SDL_AUDIO_S16)` returns 0. 242 243 Params: 244 x = an SDL_AudioFormat value. 245 246 Returns: 247 non-zero if format is unsigned, zero otherwise. 248 249 Threadsafety: 250 It is safe to call this macro from any thread. 251 */ 252 enum SDL_AUDIO_ISUNSIGNED(x) = (!SDL_AUDIO_ISSIGNED(x)); 253 254 /** 255 SDL Audio Device instance IDs. 256 257 Zero is used to signify an invalid/null device. 258 */ 259 alias SDL_AudioDeviceID = Uint32; 260 261 /** 262 A value used to request a default playback audio device. 263 264 Several functions that require an SDL_AudioDeviceID will accept this value 265 to signify the app just wants the system to choose a default device instead 266 of the app providing a specific one. 267 */ 268 enum SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK = (cast(SDL_AudioDeviceID) 0xFFFFFFFFu); 269 270 /** 271 A value used to request a default recording audio device. 272 273 Several functions that require an SDL_AudioDeviceID will accept this value 274 to signify the app just wants the system to choose a default device instead 275 of the app providing a specific one. 276 */ 277 enum SDL_AUDIO_DEVICE_DEFAULT_RECORDING = (cast(SDL_AudioDeviceID) 0xFFFFFFFEu); 278 279 /** 280 Format specifier for audio data. 281 282 See_Also: 283 $(D SDL_AudioFormat) 284 */ 285 struct SDL_AudioSpec { 286 SDL_AudioFormat format; /**< Audio data format*/ 287 int channels; /**< Number of channels: 1 mono, 2 stereo, etc*/ 288 int freq; /**< sample rate: sample frames per second*/ 289 } 290 291 /** 292 Calculate the size of each audio frame (in bytes) from an SDL_AudioSpec. 293 294 This reports on the size of an audio sample frame: stereo Sint16 data (2 295 channels of 2 bytes each) would be 4 bytes per frame, for example. 296 297 Params: 298 x = an SDL_AudioSpec to query. 299 300 Returns: 301 the number of bytes used per sample frame. 302 303 Threadsafety: 304 It is safe to call this macro from any thread. 305 */ 306 enum SDL_AUDIO_FRAMESIZE(x) = (SDL_AUDIO_BYTESIZE((x).format) * (x).channels); 307 308 /** 309 The opaque handle that represents an audio stream. 310 311 SDL_AudioStream is an audio conversion interface. 312 313 - It can handle resampling data in chunks without generating artifacts, 314 when it doesn't have the complete buffer available. 315 - It can handle incoming data in any variable size. 316 - It can handle input/output format changes on the fly. 317 - It can remap audio channels between inputs and outputs. 318 - You push data as you have it, and pull it when you need it 319 - It can also function as a basic audio data queue even if you just have 320 sound that needs to pass from one place to another. 321 - You can hook callbacks up to them when more data is added or requested, 322 to manage data on-the-fly. 323 324 Audio streams are the core of the SDL3 audio interface. You create one or 325 more of them, bind them to an opened audio device, and feed data to them 326 (or for recording, consume data from them). 327 328 See_Also: 329 $(D SDL_CreateAudioStream) 330 */ 331 struct SDL_AudioStream; 332 333 /* Function prototypes*/ 334 335 /** 336 Use this function to get the number of built-in audio drivers. 337 338 This function returns a hardcoded number. This never returns a negative 339 value; if there are no drivers compiled into this build of SDL, this 340 function returns zero. The presence of a driver in this list does not mean 341 it will function, it just means SDL is capable of interacting with that 342 interface. For example, a build of SDL might have esound support, but if 343 there's no esound server available, SDL's esound driver would fail if used. 344 345 By default, SDL tries all drivers, in its preferred order, until one is 346 found to be usable. 347 348 Returns: 349 the number of built-in audio drivers. 350 351 Threadsafety: 352 It is safe to call this function from any thread. 353 354 See_Also: 355 $(D SDL_GetAudioDriver) 356 */ 357 extern int SDL_GetNumAudioDrivers(); 358 359 /** 360 Use this function to get the name of a built in audio driver. 361 362 The list of audio drivers is given in the order that they are normally 363 initialized by default; the drivers that seem more reasonable to choose 364 first (as far as the SDL developers believe) are earlier in the list. 365 366 The names of drivers are all simple, low-ASCII identifiers, like "alsa", 367 "coreaudio" or "wasapi". These never have Unicode characters, and are not 368 meant to be proper names. 369 370 Params: 371 index = the index of the audio driver; the value ranges from 0 to 372 SDL_GetNumAudioDrivers() - 1. 373 374 Returns: 375 the name of the audio driver at the requested index, or NULL if an 376 invalid index was specified. 377 378 Threadsafety: 379 It is safe to call this function from any thread. 380 381 See_Also: 382 $(D SDL_GetNumAudioDrivers) 383 */ 384 extern const(char)* SDL_GetAudioDriver(int index); 385 386 /** 387 Get the name of the current audio driver. 388 389 The names of drivers are all simple, low-ASCII identifiers, like "alsa", 390 "coreaudio" or "wasapi". These never have Unicode characters, and are not 391 meant to be proper names. 392 393 Returns: 394 the name of the current audio driver or NULL if no driver has been 395 initialized. 396 397 398 Threadsafety: 399 It is safe to call this function from any thread. 400 */ 401 extern const(char)* SDL_GetCurrentAudioDriver(); 402 403 /** 404 Get a list of currently-connected audio playback devices. 405 406 This returns of list of available devices that play sound, perhaps to 407 speakers or headphones ("playback" devices). If you want devices that 408 record audio, like a microphone ("recording" devices), use 409 SDL_GetAudioRecordingDevices() instead. 410 411 This only returns a list of physical devices; it will not have any device 412 IDs returned by SDL_OpenAudioDevice(). 413 414 If this function returns NULL, to signify an error, `*count` will be set to 415 zero. 416 417 Params: 418 count = a pointer filled in with the number of devices returned, may 419 be NULL. 420 421 Returns: 422 a 0 terminated array of device instance IDs or NULL on error; call 423 SDL_GetError() for more information. This should be freed with 424 SDL_free() when it is no longer needed. 425 426 Threadsafety: 427 It is safe to call this function from any thread. 428 429 See_Also: 430 $(D SDL_OpenAudioDevice) 431 $(D SDL_GetAudioRecordingDevices) 432 */ 433 extern SDL_AudioDeviceID* SDL_GetAudioPlaybackDevices(int* count); 434 435 /** 436 Get a list of currently-connected audio recording devices. 437 438 This returns of list of available devices that record audio, like a 439 microphone ("recording" devices). If you want devices that play sound, 440 perhaps to speakers or headphones ("playback" devices), use 441 SDL_GetAudioPlaybackDevices() instead. 442 443 This only returns a list of physical devices; it will not have any device 444 IDs returned by SDL_OpenAudioDevice(). 445 446 If this function returns NULL, to signify an error, `*count` will be set to 447 zero. 448 449 Params: 450 count = a pointer filled in with the number of devices returned, may 451 be NULL. 452 453 Returns: 454 a 0 terminated array of device instance IDs, or NULL on failure; 455 call SDL_GetError() for more information. This should be freed 456 with SDL_free() when it is no longer needed. 457 458 Threadsafety: 459 It is safe to call this function from any thread. 460 461 See_Also: 462 $(D SDL_OpenAudioDevice) 463 $(D SDL_GetAudioPlaybackDevices) 464 */ 465 extern SDL_AudioDeviceID* SDL_GetAudioRecordingDevices(int* count); 466 467 /** 468 Get the human-readable name of a specific audio device. 469 470 Params: 471 devid = the instance ID of the device to query. 472 473 Returns: 474 the name of the audio device, or NULL on failure; call 475 SDL_GetError() for more information. 476 477 Threadsafety: 478 It is safe to call this function from any thread. 479 480 See_Also: 481 $(D SDL_GetAudioPlaybackDevices) 482 $(D SDL_GetAudioRecordingDevices) 483 */ 484 extern const(char)* SDL_GetAudioDeviceName(SDL_AudioDeviceID devid); 485 486 /** 487 Get the current audio format of a specific audio device. 488 489 For an opened device, this will report the format the device is currently 490 using. If the device isn't yet opened, this will report the device's 491 preferred format (or a reasonable default if this can't be determined). 492 493 You may also specify SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK or 494 SDL_AUDIO_DEVICE_DEFAULT_RECORDING here, which is useful for getting a 495 reasonable recommendation before opening the system-recommended default 496 device. 497 498 You can also use this to request the current device buffer size. This is 499 specified in sample frames and represents the amount of data SDL will feed 500 to the physical hardware in each chunk. This can be converted to 501 milliseconds of audio with the following equation: 502 503 `ms = (int) ((((Sint64) frames) * 1000) / spec.freq);` 504 505 Buffer size is only important if you need low-level control over the audio 506 playback timing. Most apps do not need this. 507 508 Params: 509 devid = the instance ID of the device to query. 510 spec = on return, will be filled with device details. 511 sample_frames = pointer to store device buffer size, in sample frames. 512 Can be NULL. 513 514 Returns: 515 true on success or false on failure; call SDL_GetError() for more 516 information. 517 518 Threadsafety: 519 It is safe to call this function from any thread. 520 */ 521 extern bool SDL_GetAudioDeviceFormat(SDL_AudioDeviceID devid, SDL_AudioSpec* spec, int* sample_frames); 522 523 /** 524 Get the current channel map of an audio device. 525 526 Channel maps are optional; most things do not need them, instead passing 527 data in the [order that SDL expects](CategoryAudio#channel-layouts). 528 529 Audio devices usually have no remapping applied. This is represented by 530 returning NULL, and does not signify an error. 531 532 Params: 533 devid = the instance ID of the device to query. 534 count = On output, set to number of channels in the map. Can be NULL. 535 536 Returns: 537 an array of the current channel mapping, with as many elements as 538 the current output spec's channels, or NULL if default. This 539 should be freed with SDL_free() when it is no longer needed. 540 541 Threadsafety: 542 It is safe to call this function from any thread. 543 544 See_Also: 545 $(D SDL_SetAudioStreamInputChannelMap) 546 */ 547 extern int* SDL_GetAudioDeviceChannelMap(SDL_AudioDeviceID devid, int* count); 548 549 /** 550 Open a specific audio device. 551 552 You can open both playback and recording devices through this function. 553 Playback devices will take data from bound audio streams, mix it, and send 554 it to the hardware. Recording devices will feed any bound audio streams 555 with a copy of any incoming data. 556 557 An opened audio device starts out with no audio streams bound. To start 558 audio playing, bind a stream and supply audio data to it. Unlike SDL2, 559 there is no audio callback; you only bind audio streams and make sure they 560 have data flowing into them (however, you can simulate SDL2's semantics 561 fairly closely by using SDL_OpenAudioDeviceStream instead of this 562 function). 563 564 If you don't care about opening a specific device, pass a `devid` of either 565 `SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK` or 566 `SDL_AUDIO_DEVICE_DEFAULT_RECORDING`. In this case, SDL will try to pick 567 the most reasonable default, and may also switch between physical devices 568 seamlessly later, if the most reasonable default changes during the 569 lifetime of this opened device (user changed the default in the OS's system 570 preferences, the default got unplugged so the system jumped to a new 571 default, the user plugged in headphones on a mobile device, etc). Unless 572 you have a good reason to choose a specific device, this is probably what 573 you want. 574 575 You may request a specific format for the audio device, but there is no 576 promise the device will honor that request for several reasons. As such, 577 it's only meant to be a hint as to what data your app will provide. Audio 578 streams will accept data in whatever format you specify and manage 579 conversion for you as appropriate. SDL_GetAudioDeviceFormat can tell you 580 the preferred format for the device before opening and the actual format 581 the device is using after opening. 582 583 It's legal to open the same device ID more than once; each successful open 584 will generate a new logical SDL_AudioDeviceID that is managed separately 585 from others on the same physical device. This allows libraries to open a 586 device separately from the main app and bind its own streams without 587 conflicting. 588 589 It is also legal to open a device ID returned by a previous call to this 590 function; doing so just creates another logical device on the same physical 591 device. This may be useful for making logical groupings of audio streams. 592 593 This function returns the opened device ID on success. This is a new, 594 unique SDL_AudioDeviceID that represents a logical device. 595 596 Some backends might offer arbitrary devices (for example, a networked audio 597 protocol that can connect to an arbitrary server). For these, as a change 598 from SDL2, you should open a default device ID and use an SDL hint to 599 specify the target if you care, or otherwise let the backend figure out a 600 reasonable default. Most backends don't offer anything like this, and often 601 this would be an end user setting an environment variable for their custom 602 need, and not something an application should specifically manage. 603 604 When done with an audio device, possibly at the end of the app's life, one 605 should call SDL_CloseAudioDevice() on the returned device id. 606 607 Params: 608 devid = the device instance id to open, or 609 SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK or 610 SDL_AUDIO_DEVICE_DEFAULT_RECORDING for the most reasonable 611 default device. 612 spec = the requested device configuration. Can be NULL to use 613 reasonable defaults. 614 615 Returns: 616 the device ID on success or 0 on failure; call SDL_GetError() for 617 more information. 618 619 Threadsafety: 620 It is safe to call this function from any thread. 621 622 See_Also: 623 $(D SDL_CloseAudioDevice) 624 $(D SDL_GetAudioDeviceFormat) 625 */ 626 extern SDL_AudioDeviceID SDL_OpenAudioDevice(SDL_AudioDeviceID devid, const(SDL_AudioSpec)* spec); 627 628 /** 629 Determine if an audio device is physical (instead of logical). 630 631 An SDL_AudioDeviceID that represents physical hardware is a physical 632 device; there is one for each piece of hardware that SDL can see. Logical 633 devices are created by calling SDL_OpenAudioDevice or 634 SDL_OpenAudioDeviceStream, and while each is associated with a physical 635 device, there can be any number of logical devices on one physical device. 636 637 For the most part, logical and physical IDs are interchangeable--if you try 638 to open a logical device, SDL understands to assign that effort to the 639 underlying physical device, etc. However, it might be useful to know if an 640 arbitrary device ID is physical or logical. This function reports which. 641 642 This function may return either true or false for invalid device IDs. 643 644 Params: 645 devid = the device ID to query. 646 647 Returns: 648 true if devid is a physical device, false if it is logical. 649 650 Threadsafety: 651 It is safe to call this function from any thread. 652 */ 653 extern bool SDL_IsAudioDevicePhysical(SDL_AudioDeviceID devid); 654 655 /** 656 Determine if an audio device is a playback device (instead of recording). 657 658 This function may return either true or false for invalid device IDs. 659 660 Params: 661 devid = the device ID to query. 662 663 Returns: 664 true if devid is a playback device, false if it is recording. 665 666 Threadsafety: 667 It is safe to call this function from any thread. 668 */ 669 extern bool SDL_IsAudioDevicePlayback(SDL_AudioDeviceID devid); 670 671 /** 672 Use this function to pause audio playback on a specified device. 673 674 This function pauses audio processing for a given device. Any bound audio 675 streams will not progress, and no audio will be generated. Pausing one 676 device does not prevent other unpaused devices from running. 677 678 Unlike in SDL2, audio devices start in an _unpaused_ state, since an app 679 has to bind a stream before any audio will flow. Pausing a paused device is 680 a legal no-op. 681 682 Pausing a device can be useful to halt all audio without unbinding all the 683 audio streams. This might be useful while a game is paused, or a level is 684 loading, etc. 685 686 Physical devices can not be paused or unpaused, only logical devices 687 created through SDL_OpenAudioDevice() can be. 688 689 Params: 690 devid = a device opened by SDL_OpenAudioDevice(). 691 692 Returns: 693 true on success or false on failure; call SDL_GetError() for more 694 information. 695 696 Threadsafety: 697 It is safe to call this function from any thread. 698 699 See_Also: 700 $(D SDL_ResumeAudioDevice) 701 $(D SDL_AudioDevicePaused) 702 */ 703 extern bool SDL_PauseAudioDevice(SDL_AudioDeviceID devid); 704 705 /** 706 Use this function to unpause audio playback on a specified device. 707 708 This function unpauses audio processing for a given device that has 709 previously been paused with SDL_PauseAudioDevice(). Once unpaused, any 710 bound audio streams will begin to progress again, and audio can be 711 generated. 712 713 Unlike in SDL2, audio devices start in an _unpaused_ state, since an app 714 has to bind a stream before any audio will flow. Unpausing an unpaused 715 device is a legal no-op. 716 717 Physical devices can not be paused or unpaused, only logical devices 718 created through SDL_OpenAudioDevice() can be. 719 720 Params: 721 devid = a device opened by SDL_OpenAudioDevice(). 722 723 Returns: 724 true on success or false on failure; call SDL_GetError() for more 725 information. 726 727 Threadsafety: 728 It is safe to call this function from any thread. 729 730 See_Also: 731 $(D SDL_AudioDevicePaused) 732 $(D SDL_PauseAudioDevice) 733 */ 734 extern bool SDL_ResumeAudioDevice(SDL_AudioDeviceID devid); 735 736 /** 737 Use this function to query if an audio device is paused. 738 739 Unlike in SDL2, audio devices start in an _unpaused_ state, since an app 740 has to bind a stream before any audio will flow. 741 742 Physical devices can not be paused or unpaused, only logical devices 743 created through SDL_OpenAudioDevice() can be. Physical and invalid device 744 IDs will report themselves as unpaused here. 745 746 Params: 747 devid = a device opened by SDL_OpenAudioDevice(). 748 749 Returns: 750 true if device is valid and paused, false otherwise. 751 752 Threadsafety: 753 It is safe to call this function from any thread. 754 755 See_Also: 756 $(D SDL_PauseAudioDevice) 757 $(D SDL_ResumeAudioDevice) 758 */ 759 extern bool SDL_AudioDevicePaused(SDL_AudioDeviceID devid); 760 761 /** 762 Get the gain of an audio device. 763 764 The gain of a device is its volume; a larger gain means a louder output, 765 with a gain of zero being silence. 766 767 Audio devices default to a gain of 1.0f (no change in output). 768 769 Physical devices may not have their gain changed, only logical devices, and 770 this function will always return -1.0f when used on physical devices. 771 772 Params: 773 devid = the audio device to query. 774 775 Returns: 776 the gain of the device or -1.0f on failure; call SDL_GetError() 777 for more information. 778 779 Threadsafety: 780 It is safe to call this function from any thread. 781 782 See_Also: 783 $(D SDL_SetAudioDeviceGain) 784 */ 785 extern float SDL_GetAudioDeviceGain(SDL_AudioDeviceID devid); 786 787 /** 788 Change the gain of an audio device. 789 790 The gain of a device is its volume; a larger gain means a louder output, 791 with a gain of zero being silence. 792 793 Audio devices default to a gain of 1.0f (no change in output). 794 795 Physical devices may not have their gain changed, only logical devices, and 796 this function will always return false when used on physical devices. While 797 it might seem attractive to adjust several logical devices at once in this 798 way, it would allow an app or library to interfere with another portion of 799 the program's otherwise-isolated devices. 800 801 This is applied, along with any per-audiostream gain, during playback to 802 the hardware, and can be continuously changed to create various effects. On 803 recording devices, this will adjust the gain before passing the data into 804 an audiostream; that recording audiostream can then adjust its gain further 805 when outputting the data elsewhere, if it likes, but that second gain is 806 not applied until the data leaves the audiostream again. 807 808 Params: 809 devid = the audio device on which to change gain. 810 gain = the gain. 1.0f is no change, 0.0f is silence. 811 812 Returns: 813 true on success or false on failure; call SDL_GetError() for more 814 information. 815 816 Threadsafety: 817 It is safe to call this function from any thread, as it holds 818 a stream-specific mutex while running. 819 820 See_Also: 821 $(D SDL_GetAudioDeviceGain) 822 */ 823 extern bool SDL_SetAudioDeviceGain(SDL_AudioDeviceID devid, float gain); 824 825 /** 826 Close a previously-opened audio device. 827 828 The application should close open audio devices once they are no longer 829 needed. 830 831 This function may block briefly while pending audio data is played by the 832 hardware, so that applications don't drop the last buffer of data they 833 supplied if terminating immediately afterwards. 834 835 Params: 836 devid = an audio device id previously returned by 837 SDL_OpenAudioDevice(). 838 839 Threadsafety: 840 It is safe to call this function from any thread. 841 842 See_Also: 843 $(D SDL_OpenAudioDevice) 844 */ 845 extern void SDL_CloseAudioDevice(SDL_AudioDeviceID devid); 846 847 /** 848 Bind a list of audio streams to an audio device. 849 850 Audio data will flow through any bound streams. For a playback device, data 851 for all bound streams will be mixed together and fed to the device. For a 852 recording device, a copy of recorded data will be provided to each bound 853 stream. 854 855 Audio streams can only be bound to an open device. This operation is 856 atomic--all streams bound in the same call will start processing at the 857 same time, so they can stay in sync. Also: either all streams will be bound 858 or none of them will be. 859 860 It is an error to bind an already-bound stream; it must be explicitly 861 unbound first. 862 863 Binding a stream to a device will set its output format for playback 864 devices, and its input format for recording devices, so they match the 865 device's settings. The caller is welcome to change the other end of the 866 stream's format at any time with SDL_SetAudioStreamFormat(). 867 868 Params: 869 devid = an audio device to bind a stream to. 870 streams = an array of audio streams to bind. 871 num_streams = number streams listed in the `streams` array. 872 873 Returns: 874 true on success or false on failure; call SDL_GetError() for more 875 information. 876 877 Threadsafety: 878 It is safe to call this function from any thread. 879 880 See_Also: 881 $(D SDL_BindAudioStreams) 882 $(D SDL_UnbindAudioStream) 883 $(D SDL_GetAudioStreamDevice) 884 */ 885 extern bool SDL_BindAudioStreams(SDL_AudioDeviceID devid, const(SDL_AudioStream*)* streams, int num_streams); 886 887 /** 888 Bind a single audio stream to an audio device. 889 890 This is a convenience function, equivalent to calling 891 `SDL_BindAudioStreams(devid, &stream, 1)`. 892 893 Params: 894 devid = an audio device to bind a stream to. 895 stream = an audio stream to bind to a device. 896 897 Returns: 898 true on success or false on failure; call SDL_GetError() for more 899 information. 900 901 Threadsafety: 902 It is safe to call this function from any thread. 903 904 See_Also: 905 $(D SDL_BindAudioStreams) 906 $(D SDL_UnbindAudioStream) 907 $(D SDL_GetAudioStreamDevice) 908 */ 909 extern bool SDL_BindAudioStream(SDL_AudioDeviceID devid, SDL_AudioStream* stream); 910 911 /** 912 Unbind a list of audio streams from their audio devices. 913 914 The streams being unbound do not all have to be on the same device. All 915 streams on the same device will be unbound atomically (data will stop 916 flowing through all unbound streams on the same device at the same time). 917 918 Unbinding a stream that isn't bound to a device is a legal no-op. 919 920 Params: 921 streams = an array of audio streams to unbind. Can be NULL or contain 922 NULL. 923 num_streams = number streams listed in the `streams` array. 924 925 Threadsafety: 926 It is safe to call this function from any thread. 927 928 See_Also: 929 $(D SDL_BindAudioStreams) 930 */ 931 extern void SDL_UnbindAudioStreams(const(SDL_AudioStream*)* streams, int num_streams); 932 933 /** 934 Unbind a single audio stream from its audio device. 935 936 This is a convenience function, equivalent to calling 937 `SDL_UnbindAudioStreams(&stream, 1)`. 938 939 Params: 940 stream = an audio stream to unbind from a device. Can be NULL. 941 942 Threadsafety: 943 It is safe to call this function from any thread. 944 945 See_Also: 946 $(D SDL_BindAudioStream) 947 */ 948 extern void SDL_UnbindAudioStream(SDL_AudioStream* stream); 949 950 /** 951 Query an audio stream for its currently-bound device. 952 953 This reports the audio device that an audio stream is currently bound to. 954 955 If not bound, or invalid, this returns zero, which is not a valid device 956 ID. 957 958 Params: 959 stream = the audio stream to query. 960 961 Returns: 962 the bound audio device, or 0 if not bound or invalid. 963 964 Threadsafety: 965 It is safe to call this function from any thread. 966 967 See_Also: 968 $(D SDL_BindAudioStream) 969 $(D SDL_BindAudioStreams) 970 */ 971 extern SDL_AudioDeviceID SDL_GetAudioStreamDevice(SDL_AudioStream* stream); 972 973 /** 974 Create a new audio stream. 975 976 Params: 977 src_spec = the format details of the input audio. 978 dst_spec = the format details of the output audio. 979 980 Returns: 981 a new audio stream on success or NULL on failure; call 982 SDL_GetError() for more information. 983 984 Threadsafety: 985 It is safe to call this function from any thread. 986 987 See_Also: 988 $(D SDL_PutAudioStreamData) 989 $(D SDL_GetAudioStreamData) 990 $(D SDL_GetAudioStreamAvailable) 991 $(D SDL_FlushAudioStream) 992 $(D SDL_ClearAudioStream) 993 $(D SDL_SetAudioStreamFormat) 994 $(D SDL_DestroyAudioStream) 995 */ 996 extern SDL_AudioStream* SDL_CreateAudioStream(const(SDL_AudioSpec)* src_spec, const(SDL_AudioSpec)* dst_spec); 997 998 /** 999 Get the properties associated with an audio stream. 1000 1001 Params: 1002 stream = the SDL_AudioStream to query. 1003 1004 Returns: 1005 a valid property ID on success or 0 on failure; call 1006 SDL_GetError() for more information. 1007 1008 Threadsafety: 1009 It is safe to call this function from any thread. 1010 */ 1011 extern SDL_PropertiesID SDL_GetAudioStreamProperties(SDL_AudioStream* stream); 1012 1013 /** 1014 Query the current format of an audio stream. 1015 1016 Params: 1017 stream = the SDL_AudioStream to query. 1018 src_spec = where to store the input audio format; ignored if NULL. 1019 dst_spec = where to store the output audio format; ignored if NULL. 1020 1021 Returns: 1022 true on success or false on failure; call SDL_GetError() for more 1023 information. 1024 1025 Threadsafety: 1026 It is safe to call this function from any thread, as it holds 1027 a stream-specific mutex while running. 1028 1029 See_Also: 1030 $(D SDL_SetAudioStreamFormat) 1031 */ 1032 extern bool SDL_GetAudioStreamFormat(SDL_AudioStream* stream, SDL_AudioSpec* src_spec, SDL_AudioSpec* dst_spec); 1033 1034 /** 1035 Change the input and output formats of an audio stream. 1036 1037 Future calls to and SDL_GetAudioStreamAvailable and SDL_GetAudioStreamData 1038 will reflect the new format, and future calls to SDL_PutAudioStreamData 1039 must provide data in the new input formats. 1040 1041 Data that was previously queued in the stream will still be operated on in 1042 the format that was current when it was added, which is to say you can put 1043 the end of a sound file in one format to a stream, change formats for the 1044 next sound file, and start putting that new data while the previous sound 1045 file is still queued, and everything will still play back correctly. 1046 1047 If a stream is bound to a device, then the format of the side of the stream 1048 bound to a device cannot be changed (src_spec for recording devices, 1049 dst_spec for playback devices). Attempts to make a change to this side will 1050 be ignored, but this will not report an error. The other side's format can 1051 be changed. 1052 1053 Params: 1054 stream = the stream the format is being changed. 1055 src_spec = the new format of the audio input; if NULL, it is not 1056 changed. 1057 dst_spec = the new format of the audio output; if NULL, it is not 1058 changed. 1059 1060 Returns: 1061 true on success or false on failure; call SDL_GetError() for more 1062 information. 1063 1064 Threadsafety: 1065 It is safe to call this function from any thread, as it holds 1066 a stream-specific mutex while running. 1067 1068 See_Also: 1069 $(D SDL_GetAudioStreamFormat) 1070 $(D SDL_SetAudioStreamFrequencyRatio) 1071 */ 1072 extern bool SDL_SetAudioStreamFormat(SDL_AudioStream* stream, const(SDL_AudioSpec)* src_spec, const( 1073 SDL_AudioSpec)* dst_spec); 1074 1075 /** 1076 Get the frequency ratio of an audio stream. 1077 1078 Params: 1079 stream = the SDL_AudioStream to query. 1080 1081 Returns: 1082 the frequency ratio of the stream or 0.0 on failure; call 1083 SDL_GetError() for more information. 1084 1085 Threadsafety: 1086 It is safe to call this function from any thread, as it holds 1087 a stream-specific mutex while running. 1088 1089 See_Also: 1090 $(D SDL_SetAudioStreamFrequencyRatio) 1091 */ 1092 extern float SDL_GetAudioStreamFrequencyRatio(SDL_AudioStream* stream); 1093 1094 /** 1095 Change the frequency ratio of an audio stream. 1096 1097 The frequency ratio is used to adjust the rate at which input data is 1098 consumed. Changing this effectively modifies the speed and pitch of the 1099 audio. A value greater than 1.0 will play the audio faster, and at a higher 1100 pitch. A value less than 1.0 will play the audio slower, and at a lower 1101 pitch. 1102 1103 This is applied during SDL_GetAudioStreamData, and can be continuously 1104 changed to create various effects. 1105 1106 Params: 1107 stream = the stream the frequency ratio is being changed. 1108 ratio = the frequency ratio. 1.0 is normal speed. Must be between 0.01 1109 and 100. 1110 1111 Returns: 1112 true on success or false on failure; call SDL_GetError() for more 1113 information. 1114 1115 Threadsafety: 1116 It is safe to call this function from any thread, as it holds 1117 a stream-specific mutex while running. 1118 1119 See_Also: 1120 $(D SDL_GetAudioStreamFrequencyRatio) 1121 $(D SDL_SetAudioStreamFormat) 1122 */ 1123 extern bool SDL_SetAudioStreamFrequencyRatio(SDL_AudioStream* stream, float ratio); 1124 1125 /** 1126 Get the gain of an audio stream. 1127 1128 The gain of a stream is its volume; a larger gain means a louder output, 1129 with a gain of zero being silence. 1130 1131 Audio streams default to a gain of 1.0f (no change in output). 1132 1133 Params: 1134 stream = the SDL_AudioStream to query. 1135 1136 Returns: 1137 the gain of the stream or -1.0f on failure; call SDL_GetError() 1138 for more information. 1139 1140 Threadsafety: 1141 It is safe to call this function from any thread, as it holds 1142 a stream-specific mutex while running. 1143 1144 See_Also: 1145 $(D SDL_SetAudioStreamGain) 1146 */ 1147 extern float SDL_GetAudioStreamGain(SDL_AudioStream* stream); 1148 1149 /** 1150 Change the gain of an audio stream. 1151 1152 The gain of a stream is its volume; a larger gain means a louder output, 1153 with a gain of zero being silence. 1154 1155 Audio streams default to a gain of 1.0f (no change in output). 1156 1157 This is applied during SDL_GetAudioStreamData, and can be continuously 1158 changed to create various effects. 1159 1160 Params: 1161 stream = the stream on which the gain is being changed. 1162 gain = the gain. 1.0f is no change, 0.0f is silence. 1163 1164 Returns: 1165 true on success or false on failure; call SDL_GetError() for more 1166 information. 1167 1168 Threadsafety: 1169 It is safe to call this function from any thread, as it holds 1170 a stream-specific mutex while running. 1171 1172 See_Also: 1173 $(D SDL_GetAudioStreamGain) 1174 */ 1175 extern bool SDL_SetAudioStreamGain(SDL_AudioStream* stream, float gain); 1176 1177 /** 1178 Get the current input channel map of an audio stream. 1179 1180 Channel maps are optional; most things do not need them, instead passing 1181 data in the [order that SDL expects](CategoryAudio#channel-layouts). 1182 1183 Audio streams default to no remapping applied. This is represented by 1184 returning NULL, and does not signify an error. 1185 1186 Params: 1187 stream = the SDL_AudioStream to query. 1188 count = On output, set to number of channels in the map. Can be NULL. 1189 1190 Returns: 1191 an array of the current channel mapping, with as many elements as 1192 the current output spec's channels, or NULL if default. This 1193 should be freed with SDL_free() when it is no longer needed. 1194 1195 Threadsafety: 1196 It is safe to call this function from any thread, as it holds 1197 a stream-specific mutex while running. 1198 1199 See_Also: 1200 $(D SDL_SetAudioStreamInputChannelMap) 1201 */ 1202 extern int* SDL_GetAudioStreamInputChannelMap(SDL_AudioStream* stream, int* count); 1203 1204 /** 1205 Get the current output channel map of an audio stream. 1206 1207 Channel maps are optional; most things do not need them, instead passing 1208 data in the [order that SDL expects](CategoryAudio#channel-layouts). 1209 1210 Audio streams default to no remapping applied. This is represented by 1211 returning NULL, and does not signify an error. 1212 1213 Params: 1214 stream = the SDL_AudioStream to query. 1215 count = On output, set to number of channels in the map. Can be NULL. 1216 1217 Returns: 1218 an array of the current channel mapping, with as many elements as 1219 the current output spec's channels, or NULL if default. This 1220 should be freed with SDL_free() when it is no longer needed. 1221 1222 Threadsafety: 1223 It is safe to call this function from any thread, as it holds 1224 a stream-specific mutex while running. 1225 1226 See_Also: 1227 $(D SDL_SetAudioStreamInputChannelMap) 1228 */ 1229 extern int* SDL_GetAudioStreamOutputChannelMap(SDL_AudioStream* stream, int* count); 1230 1231 /** 1232 Set the current input channel map of an audio stream. 1233 1234 Channel maps are optional; most things do not need them, instead passing 1235 data in the [order that SDL expects](CategoryAudio#channel-layouts). 1236 1237 The input channel map reorders data that is added to a stream via 1238 SDL_PutAudioStreamData. Future calls to SDL_PutAudioStreamData must provide 1239 data in the new channel order. 1240 1241 Each item in the array represents an input channel, and its value is the 1242 channel that it should be remapped to. To reverse a stereo signal's left 1243 and right values, you'd have an array of `{ 1, 0 }`. It is legal to remap 1244 multiple channels to the same thing, so `{ 1, 1 }` would duplicate the 1245 right channel to both channels of a stereo signal. An element in the 1246 channel map set to -1 instead of a valid channel will mute that channel, 1247 setting it to a silence value. 1248 1249 You cannot change the number of channels through a channel map, just 1250 reorder/mute them. 1251 1252 Data that was previously queued in the stream will still be operated on in 1253 the order that was current when it was added, which is to say you can put 1254 the end of a sound file in one order to a stream, change orders for the 1255 next sound file, and start putting that new data while the previous sound 1256 file is still queued, and everything will still play back correctly. 1257 1258 Audio streams default to no remapping applied. Passing a NULL channel map 1259 is legal, and turns off remapping. 1260 1261 SDL will copy the channel map; the caller does not have to save this array 1262 after this call. 1263 1264 If `count` is not equal to the current number of channels in the audio 1265 stream's format, this will fail. This is a safety measure to make sure a 1266 race condition hasn't changed the format while this call is setting the 1267 channel map. 1268 1269 Unlike attempting to change the stream's format, the input channel map on a 1270 stream bound to a recording device is permitted to change at any time; any 1271 data added to the stream from the device after this call will have the new 1272 mapping, but previously-added data will still have the prior mapping. 1273 1274 Params: 1275 stream = the SDL_AudioStream to change. 1276 chmap = the new channel map, NULL to reset to default. 1277 count = The number of channels in the map. 1278 1279 Returns: 1280 true on success or false on failure; call SDL_GetError() for more 1281 information. 1282 1283 Threadsafety: 1284 It is safe to call this function from any thread, as it holds 1285 a stream-specific mutex while running. Don't change the 1286 stream's format to have a different number of channels from a 1287 a different thread at the same time, though! 1288 1289 See_Also: 1290 $(D SDL_SetAudioStreamInputChannelMap) 1291 */ 1292 extern bool SDL_SetAudioStreamInputChannelMap(SDL_AudioStream* stream, const(int)* chmap, int count); 1293 1294 /** 1295 Set the current output channel map of an audio stream. 1296 1297 Channel maps are optional; most things do not need them, instead passing 1298 data in the [order that SDL expects](CategoryAudio#channel-layouts). 1299 1300 The output channel map reorders data that leaving a stream via 1301 SDL_GetAudioStreamData. 1302 1303 Each item in the array represents an input channel, and its value is the 1304 channel that it should be remapped to. To reverse a stereo signal's left 1305 and right values, you'd have an array of `{ 1, 0 }`. It is legal to remap 1306 multiple channels to the same thing, so `{ 1, 1 }` would duplicate the 1307 right channel to both channels of a stereo signal. An element in the 1308 channel map set to -1 instead of a valid channel will mute that channel, 1309 setting it to a silence value. 1310 1311 You cannot change the number of channels through a channel map, just 1312 reorder/mute them. 1313 1314 The output channel map can be changed at any time, as output remapping is 1315 applied during SDL_GetAudioStreamData. 1316 1317 Audio streams default to no remapping applied. Passing a NULL channel map 1318 is legal, and turns off remapping. 1319 1320 SDL will copy the channel map; the caller does not have to save this array 1321 after this call. 1322 1323 If `count` is not equal to the current number of channels in the audio 1324 stream's format, this will fail. This is a safety measure to make sure a 1325 race condition hasn't changed the format while this call is setting the 1326 channel map. 1327 1328 Unlike attempting to change the stream's format, the output channel map on 1329 a stream bound to a recording device is permitted to change at any time; 1330 any data added to the stream after this call will have the new mapping, but 1331 previously-added data will still have the prior mapping. When the channel 1332 map doesn't match the hardware's channel layout, SDL will convert the data 1333 before feeding it to the device for playback. 1334 1335 Params: 1336 stream = the SDL_AudioStream to change. 1337 chmap = the new channel map, NULL to reset to default. 1338 count = The number of channels in the map. 1339 1340 Returns: 1341 true on success or false on failure; call SDL_GetError() for more 1342 information. 1343 1344 Threadsafety: 1345 It is safe to call this function from any thread, as it holds 1346 a stream-specific mutex while running. Don't change the 1347 stream's format to have a different number of channels from a 1348 a different thread at the same time, though! 1349 1350 See_Also: 1351 $(D SDL_SetAudioStreamInputChannelMap) 1352 */ 1353 extern bool SDL_SetAudioStreamOutputChannelMap(SDL_AudioStream* stream, const(int)* chmap, int count); 1354 1355 /** 1356 Add data to the stream. 1357 1358 This data must match the format/channels/samplerate specified in the latest 1359 call to SDL_SetAudioStreamFormat, or the format specified when creating the 1360 stream if it hasn't been changed. 1361 1362 Note that this call simply copies the unconverted data for later. This is 1363 different than SDL2, where data was converted during the Put call and the 1364 Get call would just dequeue the previously-converted data. 1365 1366 Params: 1367 stream = the stream the audio data is being added to. 1368 buf = a pointer to the audio data to add. 1369 len = the number of bytes to write to the stream. 1370 1371 Returns: 1372 true on success or false on failure; call SDL_GetError() for more 1373 information. 1374 1375 Threadsafety: 1376 It is safe to call this function from any thread, but if the 1377 stream has a callback set, the caller might need to manage 1378 extra locking. 1379 1380 See_Also: 1381 $(D SDL_ClearAudioStream) 1382 $(D SDL_FlushAudioStream) 1383 $(D SDL_GetAudioStreamData) 1384 $(D SDL_GetAudioStreamQueued) 1385 */ 1386 extern bool SDL_PutAudioStreamData(SDL_AudioStream* stream, const(void)* buf, int len); 1387 1388 /** 1389 Get converted/resampled data from the stream. 1390 1391 The input/output data format/channels/samplerate is specified when creating 1392 the stream, and can be changed after creation by calling 1393 SDL_SetAudioStreamFormat. 1394 1395 Note that any conversion and resampling necessary is done during this call, 1396 and SDL_PutAudioStreamData simply queues unconverted data for later. This 1397 is different than SDL2, where that work was done while inputting new data 1398 to the stream and requesting the output just copied the converted data. 1399 1400 Params: 1401 stream = the stream the audio is being requested from. 1402 buf = a buffer to fill with audio data. 1403 len = the maximum number of bytes to fill. 1404 1405 Returns: 1406 the number of bytes read from the stream or -1 on failure; call 1407 SDL_GetError() for more information. 1408 1409 Threadsafety: 1410 It is safe to call this function from any thread, but if the 1411 stream has a callback set, the caller might need to manage 1412 extra locking. 1413 1414 See_Also: 1415 $(D SDL_ClearAudioStream) 1416 $(D SDL_GetAudioStreamAvailable) 1417 $(D SDL_PutAudioStreamData) 1418 */ 1419 extern int SDL_GetAudioStreamData(SDL_AudioStream* stream, void* buf, int len); 1420 1421 /** 1422 Get the number of converted/resampled bytes available. 1423 1424 The stream may be buffering data behind the scenes until it has enough to 1425 resample correctly, so this number might be lower than what you expect, or 1426 even be zero. Add more data or flush the stream if you need the data now. 1427 1428 If the stream has so much data that it would overflow an int, the return 1429 value is clamped to a maximum value, but no queued data is lost; if there 1430 are gigabytes of data queued, the app might need to read some of it with 1431 SDL_GetAudioStreamData before this function's return value is no longer 1432 clamped. 1433 1434 Params: 1435 stream = the audio stream to query. 1436 1437 Returns: 1438 the number of converted/resampled bytes available or -1 on 1439 failure; call SDL_GetError() for more information. 1440 1441 Threadsafety: 1442 It is safe to call this function from any thread. 1443 1444 See_Also: 1445 $(D SDL_GetAudioStreamData) 1446 $(D SDL_PutAudioStreamData) 1447 */ 1448 extern int SDL_GetAudioStreamAvailable(SDL_AudioStream* stream); 1449 1450 /** 1451 Get the number of bytes currently queued. 1452 1453 This is the number of bytes put into a stream as input, not the number that 1454 can be retrieved as output. Because of several details, it's not possible 1455 to calculate one number directly from the other. If you need to know how 1456 much usable data can be retrieved right now, you should use 1457 SDL_GetAudioStreamAvailable() and not this function. 1458 1459 Note that audio streams can change their input format at any time, even if 1460 there is still data queued in a different format, so the returned byte 1461 count will not necessarily match the number of _sample frames_ available. 1462 Users of this API should be aware of format changes they make when feeding 1463 a stream and plan accordingly. 1464 1465 Queued data is not converted until it is consumed by 1466 SDL_GetAudioStreamData, so this value should be representative of the exact 1467 data that was put into the stream. 1468 1469 If the stream has so much data that it would overflow an int, the return 1470 value is clamped to a maximum value, but no queued data is lost; if there 1471 are gigabytes of data queued, the app might need to read some of it with 1472 SDL_GetAudioStreamData before this function's return value is no longer 1473 clamped. 1474 1475 Params: 1476 stream = the audio stream to query. 1477 1478 Returns: 1479 the number of bytes queued or -1 on failure; call SDL_GetError() 1480 for more information. 1481 1482 Threadsafety: 1483 It is safe to call this function from any thread. 1484 1485 See_Also: 1486 $(D SDL_PutAudioStreamData) 1487 $(D SDL_ClearAudioStream) 1488 */ 1489 extern int SDL_GetAudioStreamQueued(SDL_AudioStream* stream); 1490 1491 /** 1492 Tell the stream that you're done sending data, and anything being buffered 1493 should be converted/resampled and made available immediately. 1494 1495 It is legal to add more data to a stream after flushing, but there may be 1496 audio gaps in the output. Generally this is intended to signal the end of 1497 input, so the complete output becomes available. 1498 1499 Params: 1500 stream = the audio stream to flush. 1501 1502 Returns: 1503 true on success or false on failure; call SDL_GetError() for more 1504 information. 1505 1506 Threadsafety: 1507 It is safe to call this function from any thread. 1508 1509 See_Also: 1510 $(D SDL_PutAudioStreamData) 1511 */ 1512 extern bool SDL_FlushAudioStream(SDL_AudioStream* stream); 1513 1514 /** 1515 Clear any pending data in the stream. 1516 1517 This drops any queued data, so there will be nothing to read from the 1518 stream until more is added. 1519 1520 Params: 1521 stream = the audio stream to clear. 1522 1523 Returns: 1524 true on success or false on failure; call SDL_GetError() for more 1525 information. 1526 1527 Threadsafety: 1528 It is safe to call this function from any thread. 1529 1530 See_Also: 1531 $(D SDL_GetAudioStreamAvailable) 1532 $(D SDL_GetAudioStreamData) 1533 $(D SDL_GetAudioStreamQueued) 1534 $(D SDL_PutAudioStreamData) 1535 */ 1536 extern bool SDL_ClearAudioStream(SDL_AudioStream* stream); 1537 1538 /** 1539 Use this function to pause audio playback on the audio device associated 1540 with an audio stream. 1541 1542 This function pauses audio processing for a given device. Any bound audio 1543 streams will not progress, and no audio will be generated. Pausing one 1544 device does not prevent other unpaused devices from running. 1545 1546 Pausing a device can be useful to halt all audio without unbinding all the 1547 audio streams. This might be useful while a game is paused, or a level is 1548 loading, etc. 1549 1550 Params: 1551 stream = the audio stream associated with the audio device to pause. 1552 1553 Returns: 1554 true on success or false on failure; call SDL_GetError() for more 1555 information. 1556 1557 Threadsafety: 1558 It is safe to call this function from any thread. 1559 1560 See_Also: 1561 $(D SDL_ResumeAudioStreamDevice) 1562 */ 1563 extern bool SDL_PauseAudioStreamDevice(SDL_AudioStream* stream); 1564 1565 /** 1566 Use this function to unpause audio playback on the audio device associated 1567 with an audio stream. 1568 1569 This function unpauses audio processing for a given device that has 1570 previously been paused. Once unpaused, any bound audio streams will begin 1571 to progress again, and audio can be generated. 1572 1573 Remember, SDL_OpenAudioDeviceStream opens device in a paused state, so this 1574 function call is required for audio playback to begin on such device. 1575 1576 Params: 1577 stream = the audio stream associated with the audio device to resume. 1578 1579 Returns: 1580 true on success or false on failure; call SDL_GetError() for more 1581 information. 1582 1583 Threadsafety: 1584 It is safe to call this function from any thread. 1585 1586 See_Also: 1587 $(D SDL_PauseAudioStreamDevice) 1588 */ 1589 extern bool SDL_ResumeAudioStreamDevice(SDL_AudioStream* stream); 1590 1591 /** 1592 Use this function to query if an audio device associated with a stream is 1593 paused. 1594 1595 Unlike in SDL2, audio devices start in an _unpaused_ state, since an app 1596 has to bind a stream before any audio will flow. 1597 1598 Params: 1599 stream = the audio stream associated with the audio device to query. 1600 1601 Returns: 1602 true if device is valid and paused, false otherwise. 1603 1604 Threadsafety: 1605 It is safe to call this function from any thread. 1606 1607 See_Also: 1608 $(D SDL_PauseAudioStreamDevice) 1609 $(D SDL_ResumeAudioStreamDevice) 1610 */ 1611 extern bool SDL_AudioStreamDevicePaused(SDL_AudioStream* stream); 1612 1613 /** 1614 Lock an audio stream for serialized access. 1615 1616 Each SDL_AudioStream has an internal mutex it uses to protect its data 1617 structures from threading conflicts. This function allows an app to lock 1618 that mutex, which could be useful if registering callbacks on this stream. 1619 1620 One does not need to lock a stream to use in it most cases, as the stream 1621 manages this lock internally. However, this lock is held during callbacks, 1622 which may run from arbitrary threads at any time, so if an app needs to 1623 protect shared data during those callbacks, locking the stream guarantees 1624 that the callback is not running while the lock is held. 1625 1626 As this is just a wrapper over SDL_LockMutex for an internal lock; it has 1627 all the same attributes (recursive locks are allowed, etc). 1628 1629 Params: 1630 stream = the audio stream to lock. 1631 1632 Returns: 1633 true on success or false on failure; call SDL_GetError() for more 1634 information. 1635 1636 Threadsafety: 1637 It is safe to call this function from any thread. 1638 1639 See_Also: 1640 $(D SDL_UnlockAudioStream) 1641 */ 1642 extern bool SDL_LockAudioStream(SDL_AudioStream* stream); 1643 1644 /** 1645 Unlock an audio stream for serialized access. 1646 1647 This unlocks an audio stream after a call to SDL_LockAudioStream. 1648 1649 Params: 1650 stream = the audio stream to unlock. 1651 1652 Returns: 1653 true on success or false on failure; call SDL_GetError() for more 1654 information. 1655 1656 Threadsafety: 1657 You should only call this from the same thread that 1658 previously called SDL_LockAudioStream. 1659 1660 See_Also: 1661 $(D SDL_LockAudioStream) 1662 */ 1663 extern bool SDL_UnlockAudioStream(SDL_AudioStream* stream); 1664 1665 /** 1666 A callback that fires when data passes through an SDL_AudioStream. 1667 1668 Apps can (optionally) register a callback with an audio stream that is 1669 called when data is added with SDL_PutAudioStreamData, or requested with 1670 SDL_GetAudioStreamData. 1671 1672 Two values are offered here: one is the amount of additional data needed to 1673 satisfy the immediate request (which might be zero if the stream already 1674 has enough data queued) and the other is the total amount being requested. 1675 In a Get call triggering a Put callback, these values can be different. In 1676 a Put call triggering a Get callback, these values are always the same. 1677 1678 Byte counts might be slightly overestimated due to buffering or resampling, 1679 and may change from call to call. 1680 1681 This callback is not required to do anything. Generally this is useful for 1682 adding/reading data on demand, and the app will often put/get data as 1683 appropriate, but the system goes on with the data currently available to it 1684 if this callback does nothing. 1685 1686 Params: 1687 stream = the SDL audio stream associated with this callback. 1688 additional_amount = the amount of data, in bytes, that is needed right 1689 now. 1690 total_amount = the total amount of data requested, in bytes, that is 1691 requested or available. 1692 userdata = an opaque pointer provided by the app for their personal 1693 use. 1694 1695 Threadsafety: 1696 This callbacks may run from any thread, so if you need to 1697 protect shared data, you should use SDL_LockAudioStream to 1698 serialize access; this lock will be held before your callback 1699 is called, so your callback does not need to manage the lock 1700 explicitly. 1701 1702 See_Also: 1703 $(D SDL_SetAudioStreamGetCallback) 1704 $(D SDL_SetAudioStreamPutCallback) 1705 */ 1706 alias SDL_AudioStreamCallback = void function(void* userdata, SDL_AudioStream* stream, int additional_amount, int total_amount); 1707 1708 /** 1709 Set a callback that runs when data is requested from an audio stream. 1710 1711 This callback is called _before_ data is obtained from the stream, giving 1712 the callback the chance to add more on-demand. 1713 1714 The callback can (optionally) call SDL_PutAudioStreamData() to add more 1715 audio to the stream during this call; if needed, the request that triggered 1716 this callback will obtain the new data immediately. 1717 1718 The callback's `approx_request` argument is roughly how many bytes of 1719 _unconverted_ data (in the stream's input format) is needed by the caller, 1720 although this may overestimate a little for safety. This takes into account 1721 how much is already in the stream and only asks for any extra necessary to 1722 resolve the request, which means the callback may be asked for zero bytes, 1723 and a different amount on each call. 1724 1725 The callback is not required to supply exact amounts; it is allowed to 1726 supply too much or too little or none at all. The caller will get what's 1727 available, up to the amount they requested, regardless of this callback's 1728 outcome. 1729 1730 Clearing or flushing an audio stream does not call this callback. 1731 1732 This function obtains the stream's lock, which means any existing callback 1733 (get or put) in progress will finish running before setting the new 1734 callback. 1735 1736 Setting a NULL function turns off the callback. 1737 1738 Params: 1739 stream = the audio stream to set the new callback on. 1740 callback = the new callback function to call when data is requested 1741 from the stream. 1742 userdata = an opaque pointer provided to the callback for its own 1743 personal use. 1744 1745 Returns: 1746 true on success or false on failure; call SDL_GetError() for more 1747 information. This only fails if `stream` is NULL. 1748 1749 Threadsafety: 1750 It is safe to call this function from any thread. 1751 1752 See_Also: 1753 $(D SDL_SetAudioStreamPutCallback) 1754 */ 1755 extern bool SDL_SetAudioStreamGetCallback(SDL_AudioStream* stream, SDL_AudioStreamCallback callback, void* userdata); 1756 1757 /** 1758 Set a callback that runs when data is added to an audio stream. 1759 1760 This callback is called _after_ the data is added to the stream, giving the 1761 callback the chance to obtain it immediately. 1762 1763 The callback can (optionally) call SDL_GetAudioStreamData() to obtain audio 1764 from the stream during this call. 1765 1766 The callback's `approx_request` argument is how many bytes of _converted_ 1767 data (in the stream's output format) was provided by the caller, although 1768 this may underestimate a little for safety. This value might be less than 1769 what is currently available in the stream, if data was already there, and 1770 might be less than the caller provided if the stream needs to keep a buffer 1771 to aid in resampling. Which means the callback may be provided with zero 1772 bytes, and a different amount on each call. 1773 1774 The callback may call SDL_GetAudioStreamAvailable to see the total amount 1775 currently available to read from the stream, instead of the total provided 1776 by the current call. 1777 1778 The callback is not required to obtain all data. It is allowed to read less 1779 or none at all. Anything not read now simply remains in the stream for 1780 later access. 1781 1782 Clearing or flushing an audio stream does not call this callback. 1783 1784 This function obtains the stream's lock, which means any existing callback 1785 (get or put) in progress will finish running before setting the new 1786 callback. 1787 1788 Setting a NULL function turns off the callback. 1789 1790 Params: 1791 stream = the audio stream to set the new callback on. 1792 callback = the new callback function to call when data is added to the 1793 stream. 1794 userdata = an opaque pointer provided to the callback for its own 1795 personal use. 1796 1797 Returns: 1798 true on success or false on failure; call SDL_GetError() for more 1799 information. This only fails if `stream` is NULL. 1800 1801 Threadsafety: 1802 It is safe to call this function from any thread. 1803 1804 See_Also: 1805 $(D SDL_SetAudioStreamGetCallback) 1806 */ 1807 extern bool SDL_SetAudioStreamPutCallback(SDL_AudioStream* stream, SDL_AudioStreamCallback callback, void* userdata); 1808 1809 /** 1810 Free an audio stream. 1811 1812 This will release all allocated data, including any audio that is still 1813 queued. You do not need to manually clear the stream first. 1814 1815 If this stream was bound to an audio device, it is unbound during this 1816 call. If this stream was created with SDL_OpenAudioDeviceStream, the audio 1817 device that was opened alongside this stream's creation will be closed, 1818 too. 1819 1820 Params: 1821 stream = the audio stream to destroy. 1822 1823 Threadsafety: 1824 It is safe to call this function from any thread. 1825 1826 See_Also: 1827 $(D SDL_CreateAudioStream) 1828 */ 1829 extern void SDL_DestroyAudioStream(SDL_AudioStream* stream); 1830 1831 /** 1832 Convenience function for straightforward audio init for the common case. 1833 1834 If all your app intends to do is provide a single source of PCM audio, this 1835 function allows you to do all your audio setup in a single call. 1836 1837 This is also intended to be a clean means to migrate apps from SDL2. 1838 1839 This function will open an audio device, create a stream and bind it. 1840 Unlike other methods of setup, the audio device will be closed when this 1841 stream is destroyed, so the app can treat the returned SDL_AudioStream as 1842 the only object needed to manage audio playback. 1843 1844 Also unlike other functions, the audio device begins paused. This is to map 1845 more closely to SDL2-style behavior, since there is no extra step here to 1846 bind a stream to begin audio flowing. The audio device should be resumed 1847 with `SDL_ResumeAudioStreamDevice(stream);` 1848 1849 This function works with both playback and recording devices. 1850 1851 The `spec` parameter represents the app's side of the audio stream. That 1852 is, for recording audio, this will be the output format, and for playing 1853 audio, this will be the input format. If spec is NULL, the system will 1854 choose the format, and the app can use SDL_GetAudioStreamFormat() to obtain 1855 this information later. 1856 1857 If you don't care about opening a specific audio device, you can (and 1858 probably _should_), use SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK for playback and 1859 SDL_AUDIO_DEVICE_DEFAULT_RECORDING for recording. 1860 1861 One can optionally provide a callback function; if NULL, the app is 1862 expected to queue audio data for playback (or unqueue audio data if 1863 capturing). Otherwise, the callback will begin to fire once the device is 1864 unpaused. 1865 1866 Destroying the returned stream with SDL_DestroyAudioStream will also close 1867 the audio device associated with this stream. 1868 1869 Params: 1870 devid = an audio device to open, or SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK 1871 or SDL_AUDIO_DEVICE_DEFAULT_RECORDING. 1872 spec = the audio stream's data format. Can be NULL. 1873 callback = a callback where the app will provide new data for 1874 playback, or receive new data for recording. Can be NULL, 1875 in which case the app will need to call 1876 SDL_PutAudioStreamData or SDL_GetAudioStreamData as 1877 necessary. 1878 userdata = app-controlled pointer passed to callback. Can be NULL. 1879 Ignored if callback is NULL. 1880 1881 Returns: 1882 an audio stream on success, ready to use, or NULL on failure; call 1883 SDL_GetError() for more information. When done with this stream, 1884 call SDL_DestroyAudioStream to free resources and close the 1885 device. 1886 1887 Threadsafety: 1888 It is safe to call this function from any thread. 1889 1890 See_Also: 1891 $(D SDL_GetAudioStreamDevice) 1892 $(D SDL_ResumeAudioStreamDevice) 1893 */ 1894 extern SDL_AudioStream* SDL_OpenAudioDeviceStream(SDL_AudioDeviceID devid, const(SDL_AudioSpec)* spec, SDL_AudioStreamCallback callback, void* userdata); 1895 1896 /** 1897 A callback that fires when data is about to be fed to an audio device. 1898 1899 This is useful for accessing the final mix, perhaps for writing a 1900 visualizer or applying a final effect to the audio data before playback. 1901 1902 This callback should run as quickly as possible and not block for any 1903 significant time, as this callback delays submission of data to the audio 1904 device, which can cause audio playback problems. 1905 1906 The postmix callback _must_ be able to handle any audio data format 1907 specified in `spec`, which can change between callbacks if the audio device 1908 changed. However, this only covers frequency and channel count; data is 1909 always provided here in SDL_AUDIO_F32 format. 1910 1911 The postmix callback runs _after_ logical device gain and audiostream gain 1912 have been applied, which is to say you can make the output data louder at 1913 this point than the gain settings would suggest. 1914 1915 Params: 1916 userdata = a pointer provided by the app through 1917 SDL_SetAudioPostmixCallback, for its own use. 1918 spec = the current format of audio that is to be submitted to the 1919 audio device. 1920 buffer = the buffer of audio samples to be submitted. The callback can 1921 inspect and/or modify this data. 1922 buflen = the size of `buffer` in bytes. 1923 1924 Threadsafety: 1925 This will run from a background thread owned by SDL. The 1926 application is responsible for locking resources the callback 1927 touches that need to be protected. 1928 1929 See_Also: 1930 $(D SDL_SetAudioPostmixCallback) 1931 */ 1932 alias SDL_AudioPostmixCallback = void function(void* userdata, const(SDL_AudioSpec)* spec, float* buffer, int buflen); 1933 1934 /** 1935 Set a callback that fires when data is about to be fed to an audio device. 1936 1937 This is useful for accessing the final mix, perhaps for writing a 1938 visualizer or applying a final effect to the audio data before playback. 1939 1940 The buffer is the final mix of all bound audio streams on an opened device; 1941 this callback will fire regularly for any device that is both opened and 1942 unpaused. If there is no new data to mix, either because no streams are 1943 bound to the device or all the streams are empty, this callback will still 1944 fire with the entire buffer set to silence. 1945 1946 This callback is allowed to make changes to the data; the contents of the 1947 buffer after this call is what is ultimately passed along to the hardware. 1948 1949 The callback is always provided the data in float format (values from -1.0f 1950 to 1.0f), but the number of channels or sample rate may be different than 1951 the format the app requested when opening the device; SDL might have had to 1952 manage a conversion behind the scenes, or the playback might have jumped to 1953 new physical hardware when a system default changed, etc. These details may 1954 change between calls. Accordingly, the size of the buffer might change 1955 between calls as well. 1956 1957 This callback can run at any time, and from any thread; if you need to 1958 serialize access to your app's data, you should provide and use a mutex or 1959 other synchronization device. 1960 1961 All of this to say: there are specific needs this callback can fulfill, but 1962 it is not the simplest interface. Apps should generally provide audio in 1963 their preferred format through an SDL_AudioStream and let SDL handle the 1964 difference. 1965 1966 This function is extremely time-sensitive; the callback should do the least 1967 amount of work possible and return as quickly as it can. The longer the 1968 callback runs, the higher the risk of audio dropouts or other problems. 1969 1970 This function will block until the audio device is in between iterations, 1971 so any existing callback that might be running will finish before this 1972 function sets the new callback and returns. 1973 1974 Setting a NULL callback function disables any previously-set callback. 1975 1976 Params: 1977 devid = the ID of an opened audio device. 1978 callback = a callback function to be called. Can be NULL. 1979 userdata = app-controlled pointer passed to callback. Can be NULL. 1980 1981 Returns: 1982 true on success or false on failure; call SDL_GetError() for more 1983 information. 1984 1985 Threadsafety: 1986 It is safe to call this function from any thread. 1987 */ 1988 extern bool SDL_SetAudioPostmixCallback(SDL_AudioDeviceID devid, SDL_AudioPostmixCallback callback, void* userdata); 1989 1990 /** 1991 Load the audio data of a WAVE file into memory. 1992 1993 Loading a WAVE file requires `src`, `spec`, `audio_buf` and `audio_len` to 1994 be valid pointers. The entire data portion of the file is then loaded into 1995 memory and decoded if necessary. 1996 1997 Supported formats are RIFF WAVE files with the formats PCM (8, 16, 24, and 1998 32 bits), IEEE Float (32 bits), Microsoft ADPCM and IMA ADPCM (4 bits), and 1999 A-law and mu-law (8 bits). Other formats are currently unsupported and 2000 cause an error. 2001 2002 If this function succeeds, the return value is zero and the pointer to the 2003 audio data allocated by the function is written to `audio_buf` and its 2004 length in bytes to `audio_len`. The SDL_AudioSpec members `freq`, 2005 `channels`, and `format` are set to the values of the audio data in the 2006 buffer. 2007 2008 It's necessary to use SDL_free() to free the audio data returned in 2009 `audio_buf` when it is no longer used. 2010 2011 Because of the underspecification of the .WAV format, there are many 2012 problematic files in the wild that cause issues with strict decoders. To 2013 provide compatibility with these files, this decoder is lenient in regards 2014 to the truncation of the file, the fact chunk, and the size of the RIFF 2015 chunk. The hints `SDL_HINT_WAVE_RIFF_CHUNK_SIZE`, 2016 `SDL_HINT_WAVE_TRUNCATION`, and `SDL_HINT_WAVE_FACT_CHUNK` can be used to 2017 tune the behavior of the loading process. 2018 2019 Any file that is invalid (due to truncation, corruption, or wrong values in 2020 the headers), too big, or unsupported causes an error. Additionally, any 2021 critical I/O error from the data source will terminate the loading process 2022 with an error. The function returns NULL on error and in all cases (with 2023 the exception of `src` being NULL), an appropriate error message will be 2024 set. 2025 2026 It is required that the data source supports seeking. 2027 2028 Example: 2029 2030 --- 2031 SDL_LoadWAV_IO(SDL_IOFromFile("sample.wav", "rb"), true, &spec, &buf, &len); 2032 --- 2033 2034 Note that the SDL_LoadWAV function does this same thing for you, but in a 2035 less messy way: 2036 2037 --- 2038 SDL_LoadWAV("sample.wav", &spec, &buf, &len); 2039 --- 2040 2041 Params: 2042 src = the data source for the WAVE data. 2043 closeio = if true, calls SDL_CloseIO() on `src` before returning, even 2044 in the case of an error. 2045 spec = a pointer to an SDL_AudioSpec that will be set to the WAVE 2046 data's format details on successful return. 2047 audio_buf = a pointer filled with the audio data, allocated by the 2048 function. 2049 audio_len = a pointer filled with the length of the audio data buffer 2050 in bytes. 2051 2052 Returns: 2053 true on success. `audio_buf` will be filled with a pointer to an 2054 allocated buffer containing the audio data, and `audio_len` is 2055 filled with the length of that audio buffer in bytes. 2056 2057 This function returns false if the .WAV file cannot be opened, 2058 uses an unknown data format, or is corrupt; call SDL_GetError() 2059 for more information. 2060 2061 When the application is done with the data returned in 2062 `audio_buf`, it should call SDL_free() to dispose of it. 2063 2064 Threadsafety: 2065 It is safe to call this function from any thread. 2066 2067 See_Also: 2068 $(D SDL_free) 2069 $(D SDL_LoadWAV) 2070 */ 2071 extern bool SDL_LoadWAV_IO(SDL_IOStream* src, bool closeio, SDL_AudioSpec* spec, Uint8** audio_buf, Uint32* audio_len); 2072 2073 /** 2074 Loads a WAV from a file path. 2075 2076 This is a convenience function that is effectively the same as: 2077 2078 --- 2079 SDL_LoadWAV_IO(SDL_IOFromFile(path, "rb"), true, spec, audio_buf, audio_len); 2080 --- 2081 2082 Params: 2083 path = the file path of the WAV file to open. 2084 spec = a pointer to an SDL_AudioSpec that will be set to the WAVE 2085 data's format details on successful return. 2086 audio_buf = a pointer filled with the audio data, allocated by the 2087 function. 2088 audio_len = a pointer filled with the length of the audio data buffer 2089 in bytes. 2090 2091 Returns: 2092 true on success. `audio_buf` will be filled with a pointer to an 2093 allocated buffer containing the audio data, and `audio_len` is 2094 filled with the length of that audio buffer in bytes. 2095 2096 This function returns false if the .WAV file cannot be opened, 2097 uses an unknown data format, or is corrupt; call SDL_GetError() 2098 for more information. 2099 2100 When the application is done with the data returned in 2101 `audio_buf`, it should call SDL_free() to dispose of it. 2102 2103 Threadsafety: 2104 It is safe to call this function from any thread. 2105 2106 See_Also: 2107 $(D SDL_free) 2108 $(D SDL_LoadWAV_IO) 2109 */ 2110 extern bool SDL_LoadWAV(const(char)* path, SDL_AudioSpec* spec, Uint8** audio_buf, Uint32* audio_len); 2111 2112 /** 2113 Mix audio data in a specified format. 2114 2115 This takes an audio buffer `src` of `len` bytes of `format` data and mixes 2116 it into `dst`, performing addition, volume adjustment, and overflow 2117 clipping. The buffer pointed to by `dst` must also be `len` bytes of 2118 `format` data. 2119 2120 This is provided for convenience -- you can mix your own audio data. 2121 2122 Do not use this function for mixing together more than two streams of 2123 sample data. The output from repeated application of this function may be 2124 distorted by clipping, because there is no accumulator with greater range 2125 than the input (not to mention this being an inefficient way of doing it). 2126 2127 It is a common misconception that this function is required to write audio 2128 data to an output stream in an audio callback. While you can do that, 2129 SDL_MixAudio() is really only needed when you're mixing a single audio 2130 stream with a volume adjustment. 2131 2132 Params: 2133 dst = the destination for the mixed audio. 2134 src = the source audio buffer to be mixed. 2135 format = the SDL_AudioFormat structure representing the desired audio 2136 format. 2137 len = the length of the audio buffer in bytes. 2138 volume = ranges from 0.0 - 1.0, and should be set to 1.0 for full 2139 audio volume. 2140 2141 Returns: 2142 true on success or false on failure; call SDL_GetError() for more 2143 information. 2144 2145 Threadsafety: 2146 It is safe to call this function from any thread. 2147 */ 2148 extern bool SDL_MixAudio(Uint8* dst, const(Uint8)* src, SDL_AudioFormat format, Uint32 len, float volume); 2149 2150 /** 2151 Convert some audio data of one format to another format. 2152 2153 Please note that this function is for convenience, but should not be used 2154 to resample audio in blocks, as it will introduce audio artifacts on the 2155 boundaries. You should only use this function if you are converting audio 2156 data in its entirety in one call. If you want to convert audio in smaller 2157 chunks, use an SDL_AudioStream, which is designed for this situation. 2158 2159 Internally, this function creates and destroys an SDL_AudioStream on each 2160 use, so it's also less efficient than using one directly, if you need to 2161 convert multiple times. 2162 2163 Params: 2164 src_spec = the format details of the input audio. 2165 src_data = the audio data to be converted. 2166 src_len = the len of src_data. 2167 dst_spec = the format details of the output audio. 2168 dst_data = will be filled with a pointer to converted audio data, 2169 which should be freed with SDL_free(). On error, it will be 2170 NULL. 2171 dst_len = will be filled with the len of dst_data. 2172 2173 Returns: 2174 true on success or false on failure; call SDL_GetError() for more 2175 information. 2176 2177 Threadsafety: 2178 It is safe to call this function from any thread. 2179 */ 2180 extern bool SDL_ConvertAudioSamples(const(SDL_AudioSpec)* src_spec, const(Uint8)* src_data, int src_len, const( 2181 SDL_AudioSpec)* dst_spec, Uint8** dst_data, int* dst_len); 2182 2183 /** 2184 Get the human readable name of an audio format. 2185 2186 Params: 2187 format = the audio format to query. 2188 2189 Returns: 2190 the human readable name of the specified audio format or 2191 "SDL_AUDIO_UNKNOWN" if the format isn't recognized. 2192 2193 Threadsafety: 2194 It is safe to call this function from any thread. 2195 */ 2196 extern const(char)* SDL_GetAudioFormatName(SDL_AudioFormat format); 2197 2198 /** 2199 Get the appropriate memset value for silencing an audio format. 2200 2201 The value returned by this function can be used as the second argument to 2202 memset (or SDL_memset) to set an audio buffer in a specific format to 2203 silence. 2204 2205 Params: 2206 format = the audio data format to query. 2207 2208 Returns: 2209 a byte value that can be passed to memset. 2210 2211 Threadsafety: 2212 It is safe to call this function from any thread. 2213 */ 2214 extern int SDL_GetSilenceValueForFormat(SDL_AudioFormat format);