al_play_sample(3alleg5)

πŸ“¦
version 5.2.11.3 Β· 4 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ al_play_sample ✨

okay bestie, quick vibe check β€” this one lives in the Allegro 5 API manual, and it's literally the "make a sound happen" button. let's get into it πŸ’–


🌸 SYNOPSIS 🌸

#include <allegro5/allegro_audio.h>

bool al_play_sample(ALLEGRO_SAMPLE *spl, float gain, float pan, float speed,
   ALLEGRO_PLAYMODE loop, ALLEGRO_SAMPLE_ID *ret_id)

πŸŽ€ DESCRIPTION πŸŽ€

so what this does is play a sample on one of the sample instances that al_reserve_samples(3alleg5) already set up for you. returns true if it worked, false if it didn't. and ngl, playback can fail because literally all the reserved sample instances are being used rn 😭 like the pool is full, bestie, no room.

Parameters β€” the whole squad:

  • gain β€” the relative volume the sample gets played at; 1.0 is normal. that's your baseline, don't overthink it.
  • pan β€” 0.0 is centred, -1.0 is left, 1.0 is right, or you can use ALLEGRO_AUDIO_PAN_NONE. pick your lane 🎧
  • speed β€” the relative speed the sample gets played at; 1.0 is normal. slow it down or speed it up, your call.
  • loop β€” one of ALLEGRO_PLAYMODE_ONCE, ALLEGRO_PLAYMODE_LOOP, or ALLEGRO_PLAYMODE_BIDIR. once, forever, or back-and-forth like it can't decide πŸ¦‹
  • ret_id β€” if it's non-NULL, the variable it points to gets assigned an id representing the sample being played. BUT β€” if al_play_sample(3alleg5) returns false, then whatever's in ret_id is invalid and you must NOT use it as an argument to other functions. fr fr, don't do it, it's giving undefined chaos πŸ’€
lowkey the biggest glow-up move here is remembering that ret_id is only trustworthy when you got a true back. periodt.

🫢 SEE ALSO 🫢


and that's the whole page, bestie πŸ’… this was pulled straight from the Allegro reference manual β€” al_play_sample(3alleg5), the Allegro 5 API. go make some noise πŸ‘‘βœ¨

πŸ“¦ where this page comes from