![]() |
|
How would you fade audio |
User9000
Member #15,315
September 2013
|
How could one fade out all the currently playing audio? Additionally is it possible to fade only specific samples? So this can be useful to other readers, please assume the code is the Allegro5 Audio tutorial code from the Allegro wiki. 1#include <stdio.h>
2#include <allegro5/allegro.h>
3#include <allegro5/allegro_audio.h>
4#include <allegro5/allegro_acodec.h>
5
6int main(int argc, char **argv){
7
8 ALLEGRO_DISPLAY *display = NULL;
9 ALLEGRO_SAMPLE *sample=NULL;
10
11 if(!al_init()){
12 fprintf(stderr, "failed to initialize allegro!\n");
13 return -1;
14 }
15
16 if(!al_install_audio()){
17 fprintf(stderr, "failed to initialize audio!\n");
18 return -1;
19 }
20
21 if(!al_init_acodec_addon()){
22 fprintf(stderr, "failed to initialize audio codecs!\n");
23 return -1;
24 }
25
26 if (!al_reserve_samples(1)){
27 fprintf(stderr, "failed to reserve samples!\n");
28 return -1;
29 }
30
31 sample = al_load_sample( "footstep.wav" );
32
33 if (!sample){
34 printf( "Audio clip sample not loaded!\n" );
35 return -1;
36 }
37
38 display = al_create_display(640, 480);
39
40 if(!display){
41 fprintf(stderr, "failed to create display!\n");
42 return -1;
43 }
44
45 /* Loop the sample until the display closes. */
46 al_play_sample(sample, 1.0, 0.0,1.0,ALLEGRO_PLAYMODE_LOOP,NULL);
47
48 al_rest(10.0);
49
50 al_destroy_display(display);
51 al_destroy_sample(sample);
52 return 0;
53}
I was thinking bool al_set_sample_instance_gain(ALLEGRO_SAMPLE_INSTANCE *spl, float val) could be used, is this the best way? Also could someone please explain the relationship between gain, volume, the float val? Thanks |
Neil Roy
Member #2,229
April 2002
![]() |
Good luck with this. I don't like how Allegro 5 handles audio. It is convoluted. I gave up on doing very much with it. --- |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
I think what you want is al_attach_sample_instance_to_mixer and al_set_mixer_gain (5.1.X). My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Gideon Weems
Member #3,925
October 2003
|
NiteHackr said: I don't like how Allegro 5 handles audio. It is convoluted. I gave up on doing very much with it. I'm sorry to hear that. I found the audio API a bit confusing at first but gradually began to realize that it's like that for a reason. After that, things started to seem less confusing. Edgar's right. That's exactly what you want. User9000 said: Also could someone please explain the relationship between gain, volume, the float val? Gain is volume. 1.0 is 100%. Sample gain is applied to the sample before any gain from mixers gets applied. |
|