|
Confused by Allegro 5's sound routines |
StanEd
Member #16,038
August 2015
|
Hi Everyone, 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: 1dX = spriteX - 512;
2dY = spriteY - 384;
3distance = sqrt((dX * dX) + (dY * dY));
4volume = 255 - distance;
5if(volume < 0)
6{
7volume = 0;
8}
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. Thank you, Stan |
l j
Member #10,584
January 2009
|
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.
|
StanEd
Member #16,038
August 2015
|
Thanks Taron That's good to know.
|
|