Cannot play Sound
raphael01

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

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

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

Audric

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

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.

CIRCLE

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

raphael01

Yes, only Allegro cannot play sound.

Audric

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

raphael01

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

LennyLen
Quote:

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

Then download and build the library yourself.

gnolam

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

CIRCLE

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()

Thread #586970. Printed from Allegro.cc