Confused by Allegro 5's sound routines
This is my first post here but I've been using Allegro5 for a while and usually do okay, but today I have I dilemma.
I'm porting an old project I did in allegro 4 which had radial sound effects, for simplicity there was a location (512,384) where a looped sound effect 'was', and there was a sprite who moved around the screen. The volume of the effect was based on his distance to the effect:
spriteX - 512;
spriteY - 384;
distance = sqrt((
dX) + (
volume = 255 -
volume < 0)
volume = 0;
Then if I remember correctly I simply set the volume of the looping sample to this volume.
The problem is I can't workout how to set the volume of an already playing sample in Allegro 5. Please can someone advise me as to how I can make this work, I thought it might be to do with Mixers , but I couldn't work it out from the docs.
Use sample instances instead, you can create them from samples. It allows you to play samples but also modify them in real-time. You don't have to manually set up a mixer and voice to make them work.
To change the volume you'd have to use al_set_sample_instance_gain which as far as I know should be between 0.0 and 1.0 to avoid hard clipping.
Thread #615621. Printed from Allegro.cc
That's good to know.