The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Couldn't open audio device: No available audio device
NiGHTS


Joined: 21 Jun 2011
Posts: 7
I need a step-by-step guide on how to remedy the following error:

Couldn't open audio device: No available audio device

I am running Ubuntu 11.04. I have been using SDL for OpenGL for a while now without any problems, but when I recently added sound support, it claims not to find any audio devices on my system.

This following code compiles perfectly with gcc but fails with the aforementioned error message.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL/SDL_audio.h>

void mixaudio(void *unused, Uint8 *stream, int len) { }

int main(void) {
        if( SDL_Init(SDL_INIT_AUDIO) < 0 ) exit(1);

        SDL_AudioSpec fmt;
        fmt.freq = 44100;
        fmt.format = AUDIO_S16;
        fmt.channels = 2;
        fmt.samples = 512;        /* A good value for games */
        fmt.callback = mixaudio;
        fmt.userdata = NULL;

        if ( SDL_OpenAudio(&fmt, NULL) < 0 ) {
            fprintf(stderr, "Couldn't open audio device: %s\n", SDL_GetError());
            exit(1);
        }
        SDL_Quit();
}


I know this code does nothing but it is not supposed to fail either. I have downloaded demo SDL programs from the SDL website and they all produce similar messages. I have tried using the SDL_Mixer sample code and that also fails.

Yet, if I use Wine and run Windows SDL demo's with sound they work fine. Furthermore, programs such as Firefox, the Gnome movie player and games in Ubuntu all have sound as expected. If I boot to Windows on the same machine, SDL demo programs run without a hitch.

I have looked around google for ideas on how to fix this, and many times they talk about removing pulseaudio and installing libsdl1.2debian-all. That didn't seem to help anything.

Any help is appreciated.
Couldn't open audio device: No available audio device
Ryan C. Gordon
Guest

Quote:
I have looked around google for ideas on how to fix this, and many times
they talk about removing pulseaudio and installing libsdl1.2debian-all.
That didn't seem to help anything.

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.

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


One of those two solutions will (probably) fix your problem.

--ryan.

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Re: Couldn't open audio device: No available audio device
NiGHTS


Joined: 21 Jun 2011
Posts: 7
I tried your first suggestion of running apt-get for those libraries, then downloading the latest SDL source code and recompiling the library. It now works perfectly!

In a related question, when running this program outside of my development environment on another computer, what Ubuntu packages should I install to ensure that it plays sound correctly?

And finally, what the heck is asla or pulseaudio? No one really explains how it relates to SDL and what's its for and how its used.
Couldn't open audio device: No available audio device
Patrick Baggett
Guest

On Thu, Oct 6, 2011 at 2:36 PM, NiGHTS wrote:
Quote:
I tried your first suggestion of running apt-get for those libraries, then downloading the latest SDL source code and recompiling the library. It now works perfectly!

In a related question, when running this program outside of my development environment on another computer, what Ubuntu packages should I install to ensure that it plays sound correctly?

And finally, what the heck is asla or pulseaudio? No one really explains how it relates to SDL and what's its for and how its used.


ALSA: Advanced Linux Sound Architecture.
PulseAudio: A sound "server".


Both of these are well explained in so many other sources it isn't really worth trying to give a poor explanation.


SDL uses different "backends" to support Linux sound. As you'll find out, Linux has a very fragmented and somewhat incompatible series of sound APIs. It is hit or miss whether a certain API is available/useful on a given Linux system. To counteract that, SDL can try different APIs to see which one works. In the end, you see the clean SDL API and don't have to deal with writing backends to support every sound API under the sun.


 
Quote:
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org