SDL School

API reference / Audio

SDL_PutAudioStreamData

Function, SDL3

Adds samples to the end of a stream. The device plays them in order, and the function returns at once.

Declaration

#include <SDL3/SDL.h>

bool SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len);

Parameters

streamThe stream.
bufThe samples.
lenThe size of the samples in bytes.

Return value

True on success. On failure it returns false.

Example

Play a sound
SDL_ClearAudioStream(stream);
SDL_PutAudioStreamData(stream, sound->data, (int)sound->length);

See this code run in Play a sound. Download the full program (.zip)

In Make a tone

Make a tone
make_samples(samples, CHUNK_SAMPLES);
SDL_PutAudioStreamData(stream, samples, sizeof(samples));

See this code run in Make a tone. Download the full program (.zip)

In SDL2

Use SDL_QueueAudio.

See also