Initializing SDL_Mixer gives the error "No audio device available"

I am working on a C ++ application that uses SDL / SDL_Mixer to play wav files. I am developing a Mac application without any problems. However, I really need an application to run on Linux, so I am installing VirtualBox on my Windows 7 machine with Ubuntu 12.04 LTS. Compilation works fine until I try to initialize the system. SDL_Mixer then issues the error message "No audio device available."

Here is the code where the error occurs:

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 searched extensively for online solutions, and I tried to verify the installation of libraries, etc. However, since it is possible that I missed something, any suggestions on the base library are welcome, and I will confirm that I configured them.

+4
source share
1 answer

In the same situation, I got exactly the same problem, but with ubuntu 14.04LTS (Virtual box, W7 as the host). But the problem is not in 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 Gordon, who writes:

"If you created your own SDL, you probably did not have developer headers for PulseAudio (or ALSA), so it tries to use / dev / dsp, which does not exist on many modern Linux systems (hence SDL_Init (SDL_INIT_AUDIO) successfully but no devices were found when trying to open it.) "APT-get install libasound2-dev libpulse-dev" and rebuild SDL ... let configure script find new headers so that it includes PulseAudio and ALSA support.

I effectively created an SDL and SDL mixer from the source, but without any headers from pulseAudio or ALSA. After installing the libraries mentioned and recompiled both SDL and SDL_mixer (v1.2), the sounds work fine.

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

"If you have not created your own SDL, perhaps you can force it to use a different audio path: SDL_AUDIODRIVER = momentum. / Mytestprogram or SDL_AUDIODRIVER = alsa./mytestprogram"

I have not tried this since the first solution was good in my case.

+2
source

Source: https://habr.com/ru/post/1410901/


All Articles