Mail Archives: djgpp/1997/05/16/11:06:40
On 16 May 1997 03:00:54 GMT, "Sam Shahrani" <shahrani AT copper DOT ucs DOT indiana DOT edu>
wrote:
>Okay, I posted before, and here I go again. After looking closely at the
>examples that come w/Allegro and some other source code, I still cannot
>figure out how to get my program to play a sound. KEEP IN MIND that this
>program doesn't just need to play a sound. It's a game so I want to be
>able to play the sound at a given time (i.e. an enemy tank fires, the logo
>screen etc.) I really need some help so if you could post some code,
>directions ANYTHING I would be incredibly grateful!!!! THANK YOU!!!
This is the smallest program I could write that properly demonstrates playing a
sound sample with Allegro. You will have to adapt it to suit your needs. This
is tested and known to work:
#include <stdio.h> /* needed for puts() */
#include <conio.h> /* needed for getch() */
#include <allegro.h> /* needed for all of Allegro's stuff */
int main(int argc,char **argv) /* <-- this should make John happy -hi John- */
{
SAMPLE * SoundSample;
argc = argc; /* get rid of compiler warning */
/*
* Checking the return value of allegro_init() isn't really necessary with
* the current version since it always returns success. It's a good idea
* to check it anyway since a future version may return failure.
*/
if (allegro_init() != 0)
{
puts("Can't initialize Allegro");
return 1;
}
if (install_timer() != 0)
{
puts("Can't install timer");
return 1;
}
if (install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,argv[0]) != 0)
{
puts("Can't install sound");
return 1;
}
if ( (SoundSample = load_sample("sound.wav")) == NULL)
{
puts("Can't load sound sample");
return 1;
}
/*
* Play the sample at full volume (255), both speakers (128), the original
* frequency (1000), loop the sound (1)
*/
play_sample(SoundSample,255,128,1000,1);
getch();
allegro_exit(); /* You MUST have this before exiting to DOS */
/*
* Allegro automatically cleans up everything else before exiting
*/
return 0;
}
- Raw text -