Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Cannot play Sound

This thread is locked; no one can reply to it. rss feed Print
Cannot play Sound
raphael01
Member #7,618
August 2006

I have problems by playing sound.
Here's the code:

1#include <allegro.h>
2 
3int main() {
4 BITMAP *initScreen;
5 SAMPLE *snaresound;
6 allegro_init();
7 install_keyboard();
8 install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, 0);
9 set_color_depth(16);
10 set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);
11 initScreen = load_bitmap("gfx/redcap.bmp",NULL);
12 snaresound = load_sample("sfx/snare.wav");
13 acquire_screen();
14 draw_sprite(screen,initScreen,0,0);
15 release_screen();
16 play_sample(snaresound, 255, 128, 1000, 0);
17 rest(5000);
18}
19END_OF_MAIN();

I see the picture, the application sleeps 5 secounds, but I hear no sound.
Can everybody help me?

Richard Phipps
Member #1,632
November 2001
avatar

First. Add error checking to make sure the sound system is being setup correctly and that the sound is being loaded correctly.

If that finds no errors, then try moving the install sound line till after the gfx mode has been setup.

raphael01
Member #7,618
August 2006

There is no message.
Then I will use another soundsystem, which supports all soundcards(if there is the problem).

Audric
Member #907
January 2001

If the allegro examples work, the difference may be caused by a allegro.cfg with different settings, in the same directory as the exe.

Arthur Kalliokoski
Second in Command
February 2005
avatar

Probably not the problem, but you can hear sounds from other apps, right? I've had that bite me a few times when reinstalling OS.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

CIRCLE
Member #5,301
December 2004

I get an error every time I run it changing sounds to everything I have but to early in morning for me to see the problem

-I edit a lot. Prepare thyself.

raphael01
Member #7,618
August 2006

Yes, only Allegro cannot play sound.

Audric
Member #907
January 2001

The setup program should help troubleshoot. If none of the proposed drivers work, there's definitely a problem between your machine and allegro.

raphael01
Member #7,618
August 2006

I don't have got the Setup-Program, because I used the Allegro DevPack.:-/

LennyLen
Member #5,313
December 2004
avatar

Quote:

I don't have got the Setup-Program, because I used the Allegro DevPack

Then download and build the library yourself.

gnolam
Member #2,030
March 2002
avatar

And please post the corrected version of your code. The one with full error checking.

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

CIRCLE
Member #5,301
December 2004

Just got home from work and noticed that there are no replies that 'help' so try this out

1#include "allegro.h"
2#define MODE GFX_AUTODETECT_WINDOWED
3#define WIDTH 640
4#define HEIGHT 480
5void main(void)
6{
7 BITMAP *initScreen;
8 SAMPLE *snaresound;
9 allegro_init();
10 set_color_depth(16);
11 set_gfx_mode(MODE,WIDTH,HEIGHT,0,0);
12 if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, "") != 0)
13 {
14 allegro_message("Error with sound");
15 return;
16 }
17 snaresound = load_sample("sfx/snare.wav");
18 if (!snaresound)
19 {
20 allegro_message("Error reading wav file");
21 return;
22 }
23 initScreen = load_bitmap("gfx/redcap.bmp",NULL);
24 if (!initScreen)
25 {
26 allegro_message("Error reading BMP file");
27 return;
28 }
29 draw_sprite(screen,initScreen,0,0);
30 play_sample(snaresound, 255, 128, 1000, 0);
31 rest (4000);
32 destroy_sample(snaresound);
33 remove_sound();
34 return;
35}
36END_OF_MAIN()

You shouldn't have to change anything I used all your variables and file locations just compile and run. If there is an error this will tell you.

This is you old code I just moved a few things around and works fine now

1#include <allegro.h>
2 
3int main() {
4 BITMAP *initScreen;
5 SAMPLE *snaresound;
6 allegro_init();
7 set_color_depth(16);
8 set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);
9 install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, 0);
10 install_keyboard();
11
12 initScreen = load_bitmap("gfx/redcap.bmp",NULL);
13 snaresound = load_sample("sfx/snare.wav");
14 acquire_screen();
15 draw_sprite(screen,initScreen,0,0);
16 release_screen();
17 play_sample(snaresound, 255, 128, 1000, 0);
18 rest(5000);
19}
20END_OF_MAIN() //Dont use the ; at the end just END_OF_MAIN()

-I edit a lot. Prepare thyself.

Go to: