SDL_audioqueue.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "SDL_internal.h"
  19. #ifndef SDL_audioqueue_h_
  20. #define SDL_audioqueue_h_
  21. // Internal functions used by SDL_AudioStream for queueing audio.
  22. typedef void (SDLCALL *SDL_ReleaseAudioBufferCallback)(void *userdata, const void *buffer, int buflen);
  23. typedef struct SDL_AudioQueue SDL_AudioQueue;
  24. typedef struct SDL_AudioTrack SDL_AudioTrack;
  25. // Create a new audio queue
  26. extern SDL_AudioQueue *SDL_CreateAudioQueue(size_t chunk_size);
  27. // Destroy an audio queue
  28. extern void SDL_DestroyAudioQueue(SDL_AudioQueue *queue);
  29. // Completely clear the queue
  30. extern void SDL_ClearAudioQueue(SDL_AudioQueue *queue);
  31. // Mark the last track as flushed
  32. extern void SDL_FlushAudioQueue(SDL_AudioQueue *queue);
  33. // Pop the current head track
  34. // REQUIRES: The head track must exist, and must have been flushed
  35. extern void SDL_PopAudioQueueHead(SDL_AudioQueue *queue);
  36. // Write data to the end of queue
  37. // REQUIRES: If the spec has changed, the last track must have been flushed
  38. extern bool SDL_WriteToAudioQueue(SDL_AudioQueue *queue, const SDL_AudioSpec *spec, const int *chmap, const Uint8 *data, size_t len);
  39. // Create a track where the input data is owned by the caller
  40. extern SDL_AudioTrack *SDL_CreateAudioTrack(SDL_AudioQueue *queue,
  41. const SDL_AudioSpec *spec, const int *chmap, Uint8 *data, size_t len, size_t capacity,
  42. SDL_ReleaseAudioBufferCallback callback, void *userdata);
  43. // Add a track to the end of the queue
  44. // REQUIRES: `track != NULL`
  45. extern void SDL_AddTrackToAudioQueue(SDL_AudioQueue *queue, SDL_AudioTrack *track);
  46. // Iterate over the tracks in the queue
  47. extern void *SDL_BeginAudioQueueIter(SDL_AudioQueue *queue);
  48. // Query and update the track iterator
  49. // REQUIRES: `*inout_iter != NULL` (a valid iterator)
  50. extern size_t SDL_NextAudioQueueIter(SDL_AudioQueue *queue, void **inout_iter, SDL_AudioSpec *out_spec, int **out_chmap, bool *out_flushed);
  51. extern const Uint8 *SDL_ReadFromAudioQueue(SDL_AudioQueue *queue,
  52. Uint8 *dst, SDL_AudioFormat dst_format, int dst_channels, const int *dst_map,
  53. int past_frames, int present_frames, int future_frames,
  54. Uint8 *scratch, float gain);
  55. // Get the total number of bytes currently queued
  56. extern size_t SDL_GetAudioQueueQueued(SDL_AudioQueue *queue);
  57. extern bool SDL_ResetAudioQueueHistory(SDL_AudioQueue *queue, int num_frames);
  58. #endif // SDL_audioqueue_h_