Mail Archives: djgpp/1999/08/16/21:22:36
I think your problem is....
play_sample() function doesn't wait until the wav file finish playing..
Instead it return immediatley after the internal voice allocation and
settings..
Refer to the source code of allegro below...
/* play_sample:
* Triggers a sample at the specified volume, pan position, and frequency.
* The volume and pan range from 0 (min/left) to 255 (max/right), although
* the resolution actually used by the playback routines is likely to be
* less than this. Frequency is relative rather than absolute: 1000
* represents the frequency that the sample was recorded at, 2000 is
* twice this, etc. If loop is true the sample will repeat until you call
* stop_sample(), and can be manipulated while it is playing by calling
* adjust_sample().
*/
int play_sample(SAMPLE *spl, int vol, int pan, int freq, int loop)
{
int voice = allocate_voice(spl);
if (voice >= 0) {
voice_set_volume(voice, vol);
voice_set_pan(voice, pan);
voice_set_frequency(voice, absolute_freq(freq, spl));
voice_set_playmode(voice, (loop ? PLAYMODE_LOOP : PLAYMODE_PLAY));
voice_start(voice);
release_voice(voice);
}
return voice;
}
END_OF_FUNCTION(play_sample);
And.. I corrected your source..
#include <allegro.h>
#include <iostream.h>
void main()
{
int voice;
SAMPLE *amazing;
allegro_init();
install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL);
amazing = load_wav("c:\\amazing.wav");
voice = allocate_voice(amazing);
if (voice >= 0) {
voice_set_volume(voice, 255);
voice_set_pan(voice, 128);
voice_set_playmode(voice, PLAYMODE_PLAY);
voice_start(voice);
while (1) {
if (!voice_check(voice)) break;
if (voice_get_position(voice) < 0) break;
}
deallocate_voice(voice);
}
if (amazing) destroy_sample(amazing);
allegro_exit();
}
Or.. you can simply put rest(...) function between play_sample() and
allegro_exit()..
Seunghwan Ji
- Raw text -