play_sample(3alleg4)

πŸ’– play_sample β€” the Allegro manual, but make it cute πŸ’–

okay so bestie, we're in the Allegro manual, play_sample(3alleg4), and this one is a certified banger. it's the function that makes noise happen. no cap.


✨ NAME ✨

play_sample β€” plays a sample. Allegro game programming library. that's it, that's the whole job, and it ate. πŸŽ€


🌸 SYNOPSIS 🌸

#include <allegro.h>

int play_sample(const SAMPLE *spl, int vol, int pan, int freq, int loop);

πŸ¦‹ DESCRIPTION πŸ¦‹

so what it does is it triggers a sample at the volume, pan position, and frequency you tell it. like, you hand it a sample and a whole vibe and it goes. πŸ’…

the parameters:

  • vol and pan β€” these range from 0 (min/left) to 255 (max/right). so 0 on pan is all the way left, 255 is all the way right, and everything between is the lil slider of it all.
  • freq β€” okay this one is relative, not absolute, and that's the part everyone gets wrong fr fr. 1000 represents the frequency that the sample was recorded at. 2000 is twice this. etc. it's giving ratio energy, not hertz energy.
  • loop β€” if loop is not zero, the sample will repeat until you call stop_sample(), and you can still mess with it while it's playing by calling adjust_sample(). main character sample honestly. πŸ‘‘

example, as promised:

/* Scream from the left speaker, twice the freq. */
int sound = play_sample(scream, 255, 0, 2000, 0);
not me allocating a whole voice just to scream out of the left speaker. iconic behaviour, lowkey. 😭

🌈 RETURN VALUE 🌈

it returns the voice number that was allocated for the sample. if no voices were available, you get a negative value back. so check that return value bestie, don't just ignore her. πŸ™ˆ


⭐ SEE ALSO ⭐


this has been the Allegro manual, <b>version 4.4.3</b>, and yeah the footer date slot is just the version hanging out with the page name play_sample(3alleg4) β€” we love a low-maintenance footer. go play a sample, bestie, you deserve it. πŸ«ΆπŸ’–βœ¨