SAMPLE(3alleg4)

πŸ’– SAMPLE πŸ’–

okay bestie, welcome to SAMPLE, straight outta the Allegro manual (that's SAMPLE(3alleg4) if you're being formal, which we are not) β€” it's the Allegro game programming library's lil container for sound data and honestly? iconic. πŸŽ€


✨ NAME ✨

SAMPLE β€” stores sound data. Allegro game programming library. that's it, that's the vibe. πŸ¦‹


🌸 SYNOPSIS 🌸

#include <allegro.h>

typedef struct SAMPLE

πŸ’… DESCRIPTION πŸ’…

okay so here's the whole struct laid out, no cap:

   int bits;                   - 8 or 16
   int stereo;                 - sample type flag
   int freq;                   - sample frequency
   int priority;               - 0-255
   unsigned long len;          - length (in samples)
   unsigned long loop_start;   - loop start position
   unsigned long loop_end;     - loop finish position
   void *data;                 - raw sample data

it's a sample structure that holds sound data, used by the digital sample routines. 🎧

here's the tea on what you're allowed to touch: you can consider all of these fields as read only β€” except priority, loop_start and loop_end, which you can totally change, for example after loading a sample from disk. πŸ‘‘

now the priority: it's a value from 0 to 255 (by default set to 128) and it controls how hardware voices on the sound card get allocated if you try to play more than the driver can handle. lowkey a whole vibe-check system β€” you use it to make sure the less important sounds get cut off while the important ones are preserved. main character sounds stay, background NPC sounds get yeeted. πŸ’€

the variables loop_start and loop_end specify the loop position in sample units, and they're set by default to the start and end of the sample. periodt. πŸŒ€

if you're creating your own samples on the fly, you might also wanna modify the raw data of the sample pointed by the data field. and listen β€” the sample data are always in unsigned format. so if you're loading a PCM encoded sound file with signed 16-bit samples, you'd have to XOR every two bytes (i.e. every sample value) with 0x8000 to change the signedness. not me making you do byte math, but here we are bestie 😭

ngl that signedness flip is a real one β€” forget it and your audio is gonna sound cursed. πŸ™ˆ

🫢 SEE ALSO 🫢


that's the whole page, you ate it fr fr πŸ’œ this was Allegro version 4.4.3, slay, go make some beautiful noise 🌈⭐