al_create_sample(3)

πŸ“¦
version 5.2.11.3 Β· 3 versions
, in arch rolling

πŸŽ€ NAME πŸŽ€

okay so al_create_sample(3) is from the Allegro 5 API and lives in the Library Functions Manual β€” and it's literally the function that creates a sample data structure from the buffer you hand it, bestie πŸ’…βœ¨

🌸 SYNOPSIS 🌸

              #include <allegro5/allegro_audio.h>

              ALLEGRO_SAMPLE *al_create_sample(void *buf, unsigned int samples,
                 unsigned int freq, ALLEGRO_AUDIO_DEPTH depth,
                 ALLEGRO_CHANNEL_CONF chan_conf, bool free_buf)

πŸ¦‹ DESCRIPTION πŸ¦‹

So the whole vibe is: this creates a sample data structure from the supplied buffer. Simple, iconic, main character energy πŸŽ€

Now, the <hotpink>free_buf</hotpink> tea: if free_buf is true, then the buffer will be freed with al_free(3) when the sample data structure is destroyed. If not, you should free the sample data yourself β€” no cap, that's on you 🫢

⚠️ portability check, bestie: especially on Windows, the buffer should have been allocated with al_malloc(3). Otherwise you should free the sample data yourself. Don't skip this, fr fr πŸ’€

A sample that is referred to by the samples parameter refers to a sequence of channel intensities. E.g. if you're making a stereo sample with the samples set to 4, then the layout of the data in buf will be:

LRLRLRLR

Where L and R are the intensities for the left and right channels respectively. A single sample, then, refers to the LR pair in this example. See how that works? Slay 🌈

To allocate a buffer of the correct size, you can use something like this:

              int sample_size = al_get_channel_count(chan_conf)
                                * al_get_audio_depth_size(depth);
              int bytes = samples * sample_size;
              void *buffer = al_malloc(bytes);

πŸ‘‘ SEE ALSO πŸ‘‘


πŸ’– that's the whole al_create_sample(3) page, bestie β€” from the Allegro reference manual for the Allegro 5 API; the footer didn't hand us a date, so this cute sign-off is doing that job instead 🫢✨

πŸ“¦ where this page comes from
  • arch rolling: allegro 5.2.11.3-2 Β· Zlib AND BSD-3-Clause AND OFL-1.1 AND LicenseRef-Custom
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms