I must admit I find Allegro 5 sound interface somewhat confusing. Unlike it's graphic part, it seems somewhat low-level and requires some manual management. And somehow, lacks volume setting for anything, but single sample instance. But maybe I just don't have enough experience with sound APIs. I never tried incorporate sound in my games before. Anyway, I'm trying to write a wrapper for it for my "engine" (it's more of a collection of classes than a real game engine) and I ran into some problems.
Should I be able to attach to one mixer and play two instances of the same ALLEGRO_SAMPLE? When I try to do so, Allegro crashes.
A flattened code for this case looks like this:
I expect this to either play music with a 500ms echo or assert somewhere inside Allegro with the message that I can't do this. Instead, I get crash at:
case ALLEGRO_AUDIO_DEPTH_INT16: s[i] = buf->s16[(spl->pos>>MIXER_FRAC_SHIFT)*maxc + i]; break;
I was unable to quickly determine which part of expression causes crash. s[i] seems valid.
So, the usual question. What am I doing wrong, or is this a bug in Allegro? I'm using monolith build of Allegro 5.0.5 on Windows 7 64-bit.
Should I be able to attach to one mixer and play two instances of the same ALLEGRO_SAMPLE?
Yes.
The simpler API, by the way, looks like:
al_install_audio(); al_init_acodec_addon(); al_reserve_samples(n); spl = al_load_sample(file); al_play_sample(spl, gain, pan, speed, loop, NULL);
which is really no more difficult than Allegro 4.
Oh, thanks I misunderstood that part of documentation.
EDIT: That does not explain crash, though, so I would still like to get some response on that. Was I using API in the wrong way?
Also, there is a problem with al_play_sample, because you can't do anything with it after it has been started. It seems strange to me. I have SAMPLE_ID. I can stop it. Shouldn't I be able to adjust its gain, at least? Or is there any architectural problems which prevent me from doing this?
EDIT2: OK, I have found what led to crash. I was loading the same file into two different ALLEGRO_SAMPLEs, then creating an INSTANCE of each and trying to play them. While I still don't understand why should this crash library, now at least I can avoid this crash.