9

I am working on a C++ application which uses SDL/SDL_Mixer to play wav files. I've been developing the application on a Mac without much problem. However, I do need this application to work on Linux, so I put VirtualBox on my Windows 7 machine with Ubuntu 12.04 LTS. Compilation works fine, until I actually try to initialize the system. Then, SDL_Mixer gives an error "No available audio device."

Here is the code where the error is thrown:

using namespace std;

void simple_sound_init() {
    if (SDL_Init(SDL_INIT_AUDIO) == -1) {
        fprintf(stderr, "init SDL error: %s\n", SDL_GetError());
        SDL_Quit();
        exit(1);
    }

    if (Mix_OpenAudio(SOUNDSAMPLERATE, MIX_DEFAULT_FORMAT, 1, 1024) != 0) {
        fprintf(stderr, "initialize audio error: %s\n", Mix_GetError());
        Mix_CloseAudio();
        SDL_Quit();
        exit(1);
    }

    Mix_ChannelFinished(simple_sound_channel_finised);
}

The exact error I get is:

initialize audio error: No available audio device

P/S: I have searched extensively online for solutions and I've tried checking over the libraries install, etc. However, since it is possible that I've missed something, any basic library suggestions are welcome, and I will confirm that I have them set up.

genpfault
  • 51,148
  • 11
  • 85
  • 139
A.P.
  • 123
  • 1
  • 6
  • maybe you didn't set your virtual box properly – BЈовић May 05 '12 at 19:38
  • Any suggestions on how I may have set it up incorrectly? Sound works fine (other than this of course) with all other programs and the Guest Additions have been installed. – A.P. May 05 '12 at 20:35

1 Answers1

8

I got exactely the same problem in the same situation, but with ubuntu 14.04LTS (Virtual box, W7 as host). But the problem is not the VM configuration (the sound works fine with other ubuntu applications).

I found the answer there: http://forums.libsdl.org/viewtopic.php?t=7609&sid=40fdb9756b8e22e1b8253cda3338845f

Thanks to Ryan C. Gordon who writes:

"If you built your own SDL, you probably didn't have development headers for PulseAudio (or ALSA), so it's trying to use /dev/dsp, which doesn't exist on many modern Linux systems (hence, SDL_Init(SDL_INIT_AUDIO) succeeds, but no devices are found when you try to open one). "apt-get install libasound2-dev libpulse-dev" and rebuild SDL...let the configure script find the new headers so it includes PulseAudio and ALSA support."

I had effectively built SDL and SDL-mixer from source but without any headers from pulseAudio or ALSA. After installing the libs mentionned and recompiled both SDL and SDL_mixer (v1.2), the sounds works fine.

If the problem is still there, he also talks about another solution:

"If you didn't build your own SDL, maybe you can force it to use a different audio path: SDL_AUDIODRIVER=pulse ./mytestprogram or SDL_AUDIODRIVER=alsa ./mytestprogram"

I did not try that as the first solution was the good one in my case.

MaXx
  • 121
  • 2
  • 6
  • I can confirm this step is still required in Ubuntu Mate 20.04 with SDL 1.2, I am not sure if this is necessary for SDL 2, though. – jrh May 25 '20 at 20:24
  • Still getting "no audio device available" and quite a few other problems with a custom build of SDL 1.2 on Ubuntu Mate 20.04; there may be more steps needed for a proper installation. – jrh Jun 02 '20 at 21:07