play_audio_stream(3)
π play_audio_stream(3) β Allegro manual, but make it make sense π
okay bestie, welcome to play_audio_stream(3) from the Allegro manual, aka the glow-up your game's sound system has been waiting for π
β¨ NAME β¨
play_audio_stream β creates a new audio stream and starts playing it. Part of the Allegro game programming library. π
πΈ SYNOPSIS πΈ
#include <allegro.h>
AUDIOSTREAM *play_audio_stream(int len, int bits, int stereo, int freq,
int vol, int pan);
π¦ DESCRIPTION π¦
So this function does exactly what it says on the tin, no cap: it makes a brand new audio stream and immediately starts playing it. π₯
len is the size of each transfer buffer, measured in sample frames, NOT bytes (this distinction matters, bestie, do not come for me). And what even is a sample frame? It's one single sample value if you're doing mono, or a pair of interleaved sample values β left first β if you're doing stereo. π»
Now, len should normally (but literally doesn't have to) be a power of 2, somewhere around 1k in size. And here's the vibe check on buffer size:
- Bigger buffers = more efficient, need fewer updates β¨
- Bigger buffers = more latency between you handing over the data and it actually getting played π
so it's giving tradeoff, choose wisely.
bitsβ must be8or16. That's it. Those are the options. πfreqβ the sample rate of the data, in Hertz.volandpanβ these use the exact same 0-255 ranges as the regular sample playing functions.stereoβ set it to1for stereo streams, or0otherwise.
ποΈ adjusting it mid-stream (yes you can, icon behavior)
Wanna tweak the pitch, volume, or panning of a stream once it's already playing? You absolutely can β just use the regular voice_*() functions and pass stream->voice as the parameter. π«Ά
The format of the sample data is described in the SAMPLE entry of the "Structures and types defined by Allegro" chapter, iykyk.
The formula to get the size of the buffers in bytes could be:
bytes = length * (bits / 8) * (stereo ? 2 : 1)
π example time
/* Create a 22KHz 8bit mono audio stream. */
stream = play_audio_stream(1024, 8, FALSE, 22050, 255, 128);
if (!stream)
abort_on_error("Error creating audio stream!\n");
β RETURN VALUE β
This function returns a pointer to the audio stream β or NULL if it could not be created. π So like, check it. Always check it.
ngl if you skip the NULL check and it fails, that's on you bestie π
π SEE ALSO π
and that's the whole page, periodt. this was play_audio_stream(3) from the Allegro manual, brought to you by version 4.4.3, same energy as the original dated release. slay, go make some noise ππβ¨
π¦ where this page comes from
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms