I have problems by playing sound.
Here's the code:
| 1 | #include <allegro.h> |
| 2 | |
| 3 | int 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 | } |
| 19 | END_OF_MAIN(); |
I see the picture, the application sleeps 5 secounds, but I hear no sound.
Can everybody help me?
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.
There is no message.
Then I will use another soundsystem, which supports all soundcards(if there is the problem).
If the allegro examples work, the difference may be caused by a allegro.cfg with different settings, in the same directory as the exe.
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.
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
Yes, only Allegro cannot play sound.
The setup program should help troubleshoot. If none of the proposed drivers work, there's definitely a problem between your machine and allegro.
I don't have got the Setup-Program, because I used the Allegro DevPack.:-/
I don't have got the Setup-Program, because I used the Allegro DevPack
Then download and build the library yourself.
And please post the corrected version of your code. The one with full error checking.
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 |
| 5 | void 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 | } |
| 36 | END_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 | |
| 3 | int 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 | } |
| 20 | END_OF_MAIN() //Dont use the ; at the end just END_OF_MAIN() |