play_audio_stream(3alleg4)
πΈ NAME πΈ
play_audio_stream β bestie, this one creates a new audio stream and starts playing it, like, immediately. π
It lives in the Allegro game programming library, and honestly? It's giving main character energy. Periodt.
β¨ SYNOPSIS β¨
#include <allegro.h>
AUDIOSTREAM *play_audio_stream(int len, int bits, int stereo, int freq,
int vol, int pan);
π DESCRIPTION π
okay so. This function creates a brand new audio stream and starts playing it right away. No waiting, no "let me think about it", it just goes. π₯
The len is the size of each transfer buffer β and hear me out, it's measured in sample frames, not bytes. A sample frame is either:
- a single sample value, if you're doing mono data, or
- a pair of interleaved sample values (left one comes first, okay?) if you're doing stereo data.
The length should normally be a power of 2, somewhere around 1k in size β but like, it doesn't have to be. It's not that deep. π
Larger buffers are more efficient and need fewer updates from you, but ngl they also mean more latency between you handing over the data and it actually getting played. So it's a trade-off, bestie. Choose wisely. π
Now the parameters:
bitsβ must be either8or16. That's it, that's the list.freqβ the sample rate of the data, in Hertz.volandpanβ these use the exact same0-255ranges as the regular sample playing functions. Same vibe, same numbers.stereoβ set it to1for stereo streams, or0otherwise.
So if you wanna adjust the pitch, volume, or panning of a stream once it's already playing? You can totes use the regular voice_*() functions with stream->voice as the parameter. Iconic. β¨
The format of the sample data is described in the SAMPLE entry of the "Structures and types defined by Allegro" chapter β go read it, it's right there.
And the formula to get the size of the buffers in bytes could be:
bytes = length * (bits / 8) * (stereo ? 2 : 1)
Example time, because we love a demonstration:
/* 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");
Look at her go. π¦
π RETURN VALUE π
This function returns a pointer to the audio stream β or NULL if it couldn't be created. So like, check it. Fr fr. π
π SEE ALSO π
install_sound(3alleg4)get_audio_stream_buffer(3alleg4)stop_audio_stream(3alleg4)AUDIOSTREAM(3alleg4)exstream(3alleg4)
mwah, that's a wrap bestie π this page came from the Allegro manual, version 4.4.3, and it's all about play_audio_stream(3alleg4) β go make some noise, you've got this. π«Άπ
π¦ where this page comes from
- debian bookworm: allegro4-doc 2:4.4.3.1-3 Β· Allegro-gift-ware
- debian trixie: allegro4-doc 2:4.4.3.1-5 Β· Allegro-gift-ware
- ubuntu jammy: allegro4-doc 2:4.4.3.1-2 Β· Allegro-gift-ware
- ubuntu noble: allegro4-doc 2:4.4.3.1-4.1build3 Β· Allegro-gift-ware
- ubuntu questing: allegro4-doc 2:4.4.3.1-6
- ubuntu resolute: allegro4-doc 2:4.4.3.1-7 Β· Allegro-gift-ware
- ubuntu stonking: allegro4-doc 2:4.4.3.1-9 Β· Allegro-gift-ware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms