Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » allegro 3.0 crashes when trying to play a wav file

This thread is locked; no one can reply to it. rss feed Print
allegro 3.0 crashes when trying to play a wav file
jktech
Member #23,248
May 2022

the sound is installed, the file can be find but for some reason it doesnt load. i dont know what might be happening here. i am coding with djgpp 2.01. should i update it or try to find other compatible library for audio support?

Dizzy Egg
Member #10,824
March 2009
avatar

You will need to post some code to be able to get the correct help.

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

jktech
Member #23,248
May 2022

this is my code until the part that crashes (the play_sample)

#SelectExpand
1#include <ALLEGRO.H> 2void main() 3{ 4 int game[2][2]={{640,480},{320,240}}; 5 int cine[2][2]={{640,400},{320,200}}; 6 int bigsmall=0; 7 int cinegame=0; 8 BITMAP *buffer; 9 BITMAP *buffer2; 10 PALLETE pal; 11 int c, w, h; 12 int last_retrace_count; 13 allegro_init(); 14 install_keyboard(); 15 install_mouse(); 16 install_timer(); 17 install_sound(6, 5, NULL); 18 set_color_depth(15); 19 set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0); 20 set_pallete(pal); 21 BITMAP *bg=load_pcx("y.pcx",pal); 22 BITMAP *mainmenu=load_pcx("x.pcx",pal); 23 BITMAP *cursor=load_pcx("cursor.pcx",pal); 24 BITMAP *text=create_bitmap(320, 240); 25 BITMAP *title=create_bitmap(320, 20); 26 text_mode(0x7C1F); 27 drawing_mode(5, mainmenu, 0, 0); 28 if (set_gfx_mode(0, cine[bigsmall][0], cine[bigsmall][1], 0, 0) != 0) { 29 allegro_exit(); 30 printf("Error setting graphics mode\n%s\n\n", allegro_error); 31 exit(1); 32 } 33 buffer = create_bitmap(SCREEN_W, SCREEN_H); 34 buffer2 = create_bitmap(320, 240); 35 set_projection_viewport(0, 0, SCREEN_W, SCREEN_H); 36 37 38 last_retrace_count = retrace_count; 39 int aloop=0; 40 bool menubool=true; 41 int menu=0; 42 int menuidx=0; 43 int keycode=0; 44 bool turnoff=false; 45 int soundtest=install_sound(-1, -1,NULL); 46 position_mouse(0,0); 47 SAMPLE *music=load_wav("edit.wav"); 48 play_sample(music,255,90,22050,0);

Chris Katko
Member #1,881
January 2002
avatar

[edited]

 SAMPLE *music=load_wav("edit.wav");

this code doesn't include checking the pointers to see if they're null--which is returned when the file cannot be loaded or cannot be found.

if(music == NULL)printf("AHH!\n");

Example code in the docs shows this:

  SAMPLE *sample = load_wav("scream.wav");
      if (!sample)
   abort_on_error("Couldn't scare user!"); // you don't have to use abort_on_error

Also, there's allegro_error which gets populated on errors with a message describing the error:

https://www.allegro.cc/manual/4/api/using-allegro/allegro_error

It's a good idea to check that if things are breaking somewhere.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

jktech
Member #23,248
May 2022

thats the only error ,look at the attachment picture "DIGMID patch set not found" (the F is me testing output)

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

The latest version that works with djgpp is 4.2.3 with the corresponding makefile.

The most modern version of Allegro doesn't work with DJGPP or DOS, and is hardware accelerated unlike Allegro 4. Try Allegro 5 today.

jktech
Member #23,248
May 2022

sorry edgar but i want to code for DOS actually.. and allegro seems like a rather good and complete library for DOS gamedev

Peter Hull
Member #1,136
March 2001

I don't have the docs for Allegro 3 (which dates from last century) but A4 is pretty much the same (and I recommend you get Allegro 4 even if you don't want to go to 5)

The description of play_sample is (https://liballeg.org/stabledocs/en/alleg026.html#play_sample)

int play_sample(const SAMPLE *spl, int vol, int pan, int freq, int loop);

Triggers a sample at the specified volume, pan position, and frequency. 
The parameters `vol' and `pan' range from 0 (min/left) to 255 (max/right). 
Frequency is relative rather than absolute: 1000 represents the frequency 
that the sample was recorded at, 2000 is twice this, etc. If `loop' is 
not zero, the sample will repeat until you call stop_sample(), and can be 
manipulated while it is playing by calling adjust_sample().

So your play_sample(music,255,90,22050,0) is not correct, try play_sample(music,255,128,1000,0)

Can you get any sound out of Allegro (e.g. using the demo game or example programs)? If not you may have to edit your allegro.cfg to pick a usable sound card.

[edit] - is your problem that it doesn't load (stated in your first post) or it crashes (second post)?

jktech
Member #23,248
May 2022

well it crashes when playing because it doesnt load. i cant play something thats null.. the wav file i use is a music wav.. i put in my attachments.
(also it was 1000 freq before and i tried it so i changed to the file freq.. but still not working.... and this song is just for test.. i might make my own in future).
the problem seems like this DIGMID thing that wont load

Dizzy Egg
Member #10,824
March 2009
avatar

If the wav file is null after you load it, then you probably aren’t loading it. You need to make sure the wav file is in the same folder where your executable runs from; if you’re using Codeblocks, for example, the program will run from the main project folder, not from /bin/debug. Try to load the file with the full path, for example c:\myproject\music.wav (or wherever it actually is). That way you can confirm that if the wav isn’t null, the audio works properly.

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

Peter Hull
Member #1,136
March 2001

Apologies, I thought you'd already done the check for NULL as Chris Katko suggested you do in an earlier post. Unfortunately (on A4 anyway) a missing file doesn't put anything into allegro_error so it's not useful as a diagnostic.

The 'DIGMID' is for MIDI files, not WAV, so (I assume you're not going to use MIDI files?) you can use MIDI_NONE(=0) for the second parameter in install_sound.

    install_sound(6, 0, NULL);

I don't know what the '6' is, I always used DIGI_AUTODETECT (=-1) there.

Also you should check the return value of install_sound, if it is -1 the sound didn't initialize.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

jktech
Member #23,248
May 2022

the sound initialize, and now i disabled midi i get "gus driver not written yet" and the sigsegv is still happening i fear that is what edgar said.. i am not sure what kind of codec/encoding allegro use to open WAV, i tried my best to get as close to it as possible.. i used unsigned 8-bit PCM and 22050HZ since allegro's function "load_wav" have variables called "bits" set as 8 and "freq" set as 22050.
but i dont really know what kind of encoding it needs.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Allegro 3.0 is REALLY old. You should at least update to 4.2.3. It has the same API but there are years and years of bug fixes. That alone may solve your .wav issue.

freq in the parameter list is the frequency you want to play the sample at. This should almost always be 1000 for normal speed.

Peter Hull
Member #1,136
March 2001

I spent a bit of time on this and I just couldn't build allegro 3.0 (from liballeg.org) with DJGPP 2.03 - it objected to some of the macros used in the assembly functions. How did you do it, jktech? I was using FreeDOS in a VirtualBox emulator.

Having said that, your edit.wav file plays OK on Allegro 4.2 on the same platform.

Can you get sound from the setup.exe program or the demo game?

Can you try your program with a different wav , for example one that comes with the Allegro demo?

Are you sure you've checked the return codes of everything that can fail?

Otherwise I'm out of ideas :(

Go to: