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.