SDL_audioqueue.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2023 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 struct SDL_AudioQueue SDL_AudioQueue;
  23. typedef struct SDL_AudioTrack SDL_AudioTrack;
  24. // Create a new audio queue
  25. SDL_AudioQueue *SDL_CreateAudioQueue(size_t chunk_size);
  26. // Destroy an audio queue
  27. void SDL_DestroyAudioQueue(SDL_AudioQueue *queue);
  28. // Completely clear the queue
  29. void SDL_ClearAudioQueue(SDL_AudioQueue *queue);
  30. // Mark the last track as flushed
  31. void SDL_FlushAudioQueue(SDL_AudioQueue *queue);
  32. // Pop the current head track
  33. // REQUIRES: The head track must exist, and must have been flushed
  34. void SDL_PopAudioQueueHead(SDL_AudioQueue *queue);
  35. // Get the chunk size, mostly for use with SDL_CreateChunkedAudioTrack
  36. // This can be called from any thread
  37. size_t SDL_GetAudioQueueChunkSize(SDL_AudioQueue *queue);
  38. // Write data to the end of queue
  39. // REQUIRES: If the spec has changed, the last track must have been flushed
  40. int SDL_WriteToAudioQueue(SDL_AudioQueue *queue, const SDL_AudioSpec *spec, const Uint8 *data, size_t len);
  41. // Create a track without needing to hold any locks
  42. SDL_AudioTrack *SDL_CreateChunkedAudioTrack(const SDL_AudioSpec *spec, const Uint8 *data, size_t len, size_t chunk_size);
  43. // Add a track to the end of the queue
  44. // REQUIRES: `track != NULL`
  45. void SDL_AddTrackToAudioQueue(SDL_AudioQueue *queue, SDL_AudioTrack *track);
  46. // Iterate over the tracks in the queue
  47. void *SDL_BeginAudioQueueIter(SDL_AudioQueue *queue);
  48. // Query and update the track iterator
  49. // REQUIRES: `*inout_iter != NULL` (a valid iterator)
  50. size_t SDL_NextAudioQueueIter(SDL_AudioQueue *queue, void **inout_iter, SDL_AudioSpec *out_spec, SDL_bool *out_flushed);
  51. // Read data from the start of the queue
  52. // REQUIRES: There must be enough data in the queue
  53. int SDL_ReadFromAudioQueue(SDL_AudioQueue *queue, Uint8 *data, size_t len);
  54. // Peek into the start of the queue
  55. // REQUIRES: There must be enough data in the queue, unless it has been flushed, in which case missing data is filled with silence.
  56. int SDL_PeekIntoAudioQueue(SDL_AudioQueue *queue, Uint8 *data, size_t len);
  57. #endif // SDL_audioqueue_h_