0

I want to making a game with allegro4 on ubuntu.So I improving myself whit tutorials. Today I want to add a sound in my game.

However I can't run the sound. When I compile my code and run the "output" program the terminal give that message:

ALSA lib rawmidi_hw.c:233:(snd_rawmidi_hw_open) open /dev/snd/midiC0D0 failed: No such file or directory

But Program still run.Then When I press the up button(for listening the sound) the program screen is shut down and the terminal give that message :

Shutting down Allegro due to signal #11
Segmentation fault (core dumped)

Here is my code:

#include <allegro.h>

void start();
void finish();

int main(){

        start();

        SAMPLE *soundfile=load_sample("sound.wav");


        while(!key[KEY_ESC]){

             if(key[KEY_UP]){
                play_sample(soundfile,255,128,1000,0);
             }  
        }
        finish();
        return 0;
}

END_OF_MAIN()

void start(){
        int depth,res;
        allegro_init();
        depth = desktop_color_depth();
        if(depth == 0) depth=32;
        set_color_depth(depth);
        res=set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640,480,0,0);
        if(res!=0){
                allegro_message("%s\n", allegro_error);               
                exit(-1);
        }
        install_timer();
        install_keyboard();
        install_mouse();
        install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,"A");
}


void finish(){
  clear_keybuf();
}
ad absurdum
  • 19,498
  • 5
  • 37
  • 60
  • The error message: _No such file or directory_ is pretty direct. Try using relative path. Change this: `"sound.wav"` to this: `"./sound.wav"`, or you can put in the full address. – ryyker Aug 01 '17 at 12:55
  • @ryyker no change :( – Tarkan Genç Aug 01 '17 at 13:09
  • First, you should be checking return values from functions such as `load_sample()`, `install_timer()`, `install_keyboard()`, etc. This may be a stupid question, but shouldn't the Allegro functions be prefixed with `al_`, e.g., `al_load_sample()`? – ad absurdum Aug 01 '17 at 13:12
  • @David Bowling I did a lot of example and I don't use "al_". I watch this youtube tutorial(https://www.youtube.com/watch?v=E8DCOwjAf9g) and the man who record the video can run the sound file. – Tarkan Genç Aug 01 '17 at 13:24
  • If you set a break-point in your debugger on the line: `play_sample(soundfile,255,128,1000,0);`, can you confirm that execution flow is even making it there ? If not, try commenting out the while and if constructs surrounding that statement and run your code. Then you can go back and debug your exe flow control statements ( `while(){...}` and `if(){...}` later. – ryyker Aug 01 '17 at 15:05
  • @TarkanGenç-- Ah, the documentation I was looking at was for Allegro 5, where the function names have been changed. I did not notice the Allegro 4 in the text of your question at first, but only the Allegro 5 tag, which is wrong. The video you linked to shows a C++ program (`main.cpp`) being developed in a MS Visual C++ IDE. Are you using a C compiler or a C++ compiler? Best to use correct tags to avoid confusion. Again, when code has problems, check return values to be sure that functions are behaving as expected. – ad absurdum Aug 01 '17 at 19:19
  • You should init the acodec addon. `al_init_acodec_addon()` – Promitheas Nikou May 13 '22 at 06:10

0 Answers0