1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
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#include "SDL_internal.h"
22
23#ifndef SDL_audioqueue_h_
24#define SDL_audioqueue_h_
25
26// Internal functions used by SDL_AudioStream for queueing audio.
27
28typedef void (SDLCALL *SDL_ReleaseAudioBufferCallback)(void *userdata, const void *buffer, int buflen);
29
30typedef struct SDL_AudioQueue SDL_AudioQueue;
31typedef struct SDL_AudioTrack SDL_AudioTrack;
32
33// Create a new audio queue
34extern SDL_AudioQueue *SDL_CreateAudioQueue(size_t chunk_size);
35
36// Destroy an audio queue
37extern void SDL_DestroyAudioQueue(SDL_AudioQueue *queue);
38
39// Completely clear the queue
40extern void SDL_ClearAudioQueue(SDL_AudioQueue *queue);
41
42// Mark the last track as flushed
43extern void SDL_FlushAudioQueue(SDL_AudioQueue *queue);
44
45// Pop the current head track
46// REQUIRES: The head track must exist, and must have been flushed
47extern void SDL_PopAudioQueueHead(SDL_AudioQueue *queue);
48
49// Write data to the end of queue
50// REQUIRES: If the spec has changed, the last track must have been flushed
51extern bool SDL_WriteToAudioQueue(SDL_AudioQueue *queue, const SDL_AudioSpec *spec, const int *chmap, const Uint8 *data, size_t len);
52
53// Create a track where the input data is owned by the caller
54extern SDL_AudioTrack *SDL_CreateAudioTrack(SDL_AudioQueue *queue,
55 const SDL_AudioSpec *spec, const int *chmap, Uint8 *data, size_t len, size_t capacity,
56 SDL_ReleaseAudioBufferCallback callback, void *userdata);
57
58// Add a track to the end of the queue
59// REQUIRES: `track != NULL`
60extern void SDL_AddTrackToAudioQueue(SDL_AudioQueue *queue, SDL_AudioTrack *track);
61
62// Iterate over the tracks in the queue
63extern void *SDL_BeginAudioQueueIter(SDL_AudioQueue *queue);
64
65// Query and update the track iterator
66// REQUIRES: `*inout_iter != NULL` (a valid iterator)
67extern size_t SDL_NextAudioQueueIter(SDL_AudioQueue *queue, void **inout_iter, SDL_AudioSpec *out_spec, int **out_chmap, bool *out_flushed);
68
69extern const Uint8 *SDL_ReadFromAudioQueue(SDL_AudioQueue *queue,
70 Uint8 *dst, SDL_AudioFormat dst_format, int dst_channels, const int *dst_map,
71 int past_frames, int present_frames, int future_frames,
72 Uint8 *scratch, float gain);
73
74// Get the total number of bytes currently queued
75extern size_t SDL_GetAudioQueueQueued(SDL_AudioQueue *queue);
76
77extern bool SDL_ResetAudioQueueHistory(SDL_AudioQueue *queue, int num_frames);
78
79#endif // SDL_audioqueue_h_
80