load_sample(3)

πŸ“¦ version 4.4.3.1, in fedora 43, fedora 44

✨ load_sample(3) β€” the Allegro manual, but make it cute ✨

okay bestie, welcome to the Allegro manual πŸ’– this one's about load_sample(3), and it's genuinely one of the most useful little gremlins in the whole audio toolbox, no cap.


🌸 NAME 🌸

load_sample β€” loads a sample from a file. Part of the Allegro game programming library πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <allegro.h>

SAMPLE *load_sample(const char *filename);

πŸ’… DESCRIPTION πŸ’…

So like. This function grabs a sample out of a file and hands it to you, wrapped up all nice. It's giving versatile honestly, because it handles a whole bunch of formats:

  • mono and stereo WAV files 🎧
  • mono VOC files
  • in 8-bit or 16-bit formats ✨
  • plus literally any other format that some function you registered with register_sample_file_type() knows how to deal with πŸ‘‘

Example, because seeing it is believing:

SAMPLE *sample = load_sample(user_input);
if (!sample)
   abort_on_error("Couldn't load sample!");

look at her. iconic. πŸ’–


⭐ RETURN VALUE ⭐

You get back a pointer to the SAMPLE, or NULL if something went wrong 😭 (yes, the classic NULL-on-error situation, we've all been there).

🫢 bestie please, remember to free this sample later to avoid memory leaks. Don't leave her hanging, that's not main character energy.

πŸ‘‘ SEE ALSO πŸ‘‘


Allegro, version 4.4.3, and the page date β€” all of it came from the load_sample(3) page in the Allegro manual, and we're shouting them out at the very end like the icons they are 🌈 mwah, go load some samples, you got this πŸ’œ

πŸ“¦ where this page comes from