SDL2 on ubuntu audio fails to open

I am having a problem getting SDL2 audio working on both Ubuntu 32bit 12.04
and 12.10 (on two different machines). If anyone could help me resolve this
matter I’d very much appreciate your advice. I have built SDL2 using with
the following commands:

hg clone http://hg.libsdl.org/SDL
mkdir build
cd build
cmake …/SDL
make

Here is cmake’s output:
http://www.codebot.org/sdl/cmake.txt

I also wrote a short audio test which outputs the following (note the
failure on SDL_OpenAudio):

Number of drivers: 3
driver 0: dsp
driver 1: disk
driver 2: dummy
Number of capture devices: 0
Number of output devices: 0
SDL failed to open audio: No such audio device
Done test

Audio test source code:

procedure ProccessAudio(userdata: Pointer; stream: PUInt8; len: Integer);
cdecl;
begin
end;

procedure PrintAudioDrivers;
var
I, J: Integer;
begin
J := SDL_GetNumAudioDrivers;
WriteLn('Number of drivers: ‘, J);
for I := 0 to J -1 do
WriteLn(’ driver ', I, ': ', SDL_GetAudioDriver(I));
end;

procedure PrintAudioDevices(iscapture: LongInt);
const
DeviceType: array[0…1] of AnsiString = (‘capture’, ‘output’);
var
I, J: Integer;
begin
J := SDL_GetNumAudioDevices(iscapture);
WriteLn('Number of ', DeviceType[iscapture], ’ devices: ‘, J);
for I := 0 to J -1 do
WriteLn(’ device ', I, ': ', SDL_GetAudioDeviceName(I, iscapture));
end;

procedure TestSound;
var
Desired, Obtained: TSDL_AudioSpec;
begin
if SDL_Init(SDL_INIT_AUDIO) <> 0 then
begin
WriteLn('SDL failed to initialize audio: ', SDL_GetError);
Exit;
end;
PrintAudioDrivers;
PrintAudioDevices(0);
PrintAudioDevices(1);
Desired.freq := 22050;
Desired.format := AUDIO_U8;
Desired.channels := 2;
Desired.samples := 512;
Desired.callback := ProccessAudio;
Desired.userdata := nil;
if SDL_OpenAudio(@Desired, @Obtained) <> 0 then
WriteLn('SDL failed to open audio: ', SDL_GetError);
SDL_Quit;
WriteLn(‘Done test’);
end;

No ALSA and no PulseAudio? Really? I’d imagine that isn’t helping your
case. Not sure if that’s the problem but you really would want to fix
that in the first place. Any reason why ALSA or PulseAudio support may
not be being built?

2013/4/11, Anthony Walter :> I am having a problem getting SDL2 audio working on both Ubuntu 32bit 12.04

and 12.10 (on two different machines). If anyone could help me resolve this
matter I’d very much appreciate your advice. I have built SDL2 using with
the following commands:

hg clone http://hg.libsdl.org/SDL
mkdir build
cd build
cmake …/SDL
make

Here is cmake’s output:
http://www.codebot.org/sdl/cmake.txt

I also wrote a short audio test which outputs the following (note the
failure on SDL_OpenAudio):

Number of drivers: 3
driver 0: dsp
driver 1: disk
driver 2: dummy
Number of capture devices: 0
Number of output devices: 0
SDL failed to open audio: No such audio device
Done test

Audio test source code:

procedure ProccessAudio(userdata: Pointer; stream: PUInt8; len: Integer);
cdecl;
begin
end;

procedure PrintAudioDrivers;
var
I, J: Integer;
begin
J := SDL_GetNumAudioDrivers;
WriteLn('Number of drivers: ‘, J);
for I := 0 to J -1 do
WriteLn(’ driver ', I, ': ', SDL_GetAudioDriver(I));
end;

procedure PrintAudioDevices(iscapture: LongInt);
const
DeviceType: array[0…1] of AnsiString = (‘capture’, ‘output’);
var
I, J: Integer;
begin
J := SDL_GetNumAudioDevices(iscapture);
WriteLn('Number of ', DeviceType[iscapture], ’ devices: ‘, J);
for I := 0 to J -1 do
WriteLn(’ device ', I, ': ', SDL_GetAudioDeviceName(I, iscapture));
end;

procedure TestSound;
var
Desired, Obtained: TSDL_AudioSpec;
begin
if SDL_Init(SDL_INIT_AUDIO) <> 0 then
begin
WriteLn('SDL failed to initialize audio: ', SDL_GetError);
Exit;
end;
PrintAudioDrivers;
PrintAudioDevices(0);
PrintAudioDevices(1);
Desired.freq := 22050;
Desired.format := AUDIO_U8;
Desired.channels := 2;
Desired.samples := 512;
Desired.callback := ProccessAudio;
Desired.userdata := nil;
if SDL_OpenAudio(@Desired, @Obtained) <> 0 then
WriteLn('SDL failed to open audio: ', SDL_GetError);
SDL_Quit;
WriteLn(‘Done test’);
end;

As Sik said, the CMake output makes it clear that SDL isn’t being built
with support for ALSA or Pulse. You’d want to make sure that the
development headers for both of those are installed; quickest way is to run
"sudo apt-get build-dep libsdl1.2" (which will install all the -dev
prerequisites for SDL 1.2), clearing your build/ directory, then have
another go at running CMake.On 11 April 2013 13:32, Sik the hedgehog <sik.the.hedgehog at gmail.com> wrote:

No ALSA and no PulseAudio? Really? I’d imagine that isn’t helping your
case. Not sure if that’s the problem but you really would want to fix
that in the first place. Any reason why ALSA or PulseAudio support may
not be being built?

2013/4/11, Anthony Walter :

I am having a problem getting SDL2 audio working on both Ubuntu 32bit
12.04
and 12.10 (on two different machines). If anyone could help me resolve
this
matter I’d very much appreciate your advice. I have built SDL2 using with
the following commands:

hg clone http://hg.libsdl.org/SDL
mkdir build
cd build
cmake …/SDL
make

Here is cmake’s output:
http://www.codebot.org/sdl/cmake.txt

I also wrote a short audio test which outputs the following (note the
failure on SDL_OpenAudio):

Number of drivers: 3
driver 0: dsp
driver 1: disk
driver 2: dummy
Number of capture devices: 0
Number of output devices: 0
SDL failed to open audio: No such audio device
Done test

Audio test source code:

procedure ProccessAudio(userdata: Pointer; stream: PUInt8; len: Integer);
cdecl;
begin
end;

procedure PrintAudioDrivers;
var
I, J: Integer;
begin
J := SDL_GetNumAudioDrivers;
WriteLn('Number of drivers: ‘, J);
for I := 0 to J -1 do
WriteLn(’ driver ', I, ': ', SDL_GetAudioDriver(I));
end;

procedure PrintAudioDevices(iscapture: LongInt);
const
DeviceType: array[0…1] of AnsiString = (‘capture’, ‘output’);
var
I, J: Integer;
begin
J := SDL_GetNumAudioDevices(iscapture);
WriteLn('Number of ', DeviceType[iscapture], ’ devices: ‘, J);
for I := 0 to J -1 do
WriteLn(’ device ', I, ': ', SDL_GetAudioDeviceName(I, iscapture));
end;

procedure TestSound;
var
Desired, Obtained: TSDL_AudioSpec;
begin
if SDL_Init(SDL_INIT_AUDIO) <> 0 then
begin
WriteLn('SDL failed to initialize audio: ', SDL_GetError);
Exit;
end;
PrintAudioDrivers;
PrintAudioDevices(0);
PrintAudioDevices(1);
Desired.freq := 22050;
Desired.format := AUDIO_U8;
Desired.channels := 2;
Desired.samples := 512;
Desired.callback := ProccessAudio;
Desired.userdata := nil;
if SDL_OpenAudio(@Desired, @Obtained) <> 0 then
WriteLn('SDL failed to open audio: ', SDL_GetError);
SDL_Quit;
WriteLn(‘Done test’);
end;


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I installed many of dependencies as you advised, but now test program locks
up when SDL_OpenAudio is called. My cmake’s output now looks like this:

http://www.codebot.org/sdl/cmake2.txt

And my test program outputs this, but locks up when trying to
call SDL_OpenAudio:

Number of drivers: 7
driver 0: pulseaudio
driver 1: alsa
driver 2: dsp
driver 3: esd
driver 4: nas
driver 5: disk
driver 6: dummy
Number of output devices: 1
device 0: System audio output device
Number of capture devices: 0

of those are installed; quickest way is to run “sudo apt-get build-dep
libsdl1.2” (which will install all the -dev prerequisites for SDL 1.2),
clearing your build/ directory, then have another go at running CMake.

Slightly offtopic, but it’s more than 10 years that I use *apt *and I
didn’t know that awesome build-dep option, thanks :)On Thu, Apr 11, 2013 at 7:45 AM, Scott Percival wrote:


Bye,
Gabry

Bah, I think I know what this’ll be… you’ll need to download the patch
from here - http://bugzilla.libsdl.org/show_bug.cgi?id=1709 , and apply it
to your source tree.On 11 April 2013 15:46, Gabriele Greco <gabriele.greco at darts.it> wrote:

On Thu, Apr 11, 2013 at 7:45 AM, Scott Percival <@Scott_Percival wrote:

of those are installed; quickest way is to run “sudo apt-get build-dep
libsdl1.2” (which will install all the -dev prerequisites for SDL 1.2),
clearing your build/ directory, then have another go at running CMake.

Slightly offtopic, but it’s more than 10 years that I use *apt *and I
didn’t know that awesome build-dep option, thanks :slight_smile:


Bye,
Gabry


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Wow, thank you! You guys are really helpful.

Patching cmake/sdlchecks.cmake seems to have corrected the lock up. I’ll
have to test a project on my other computer to see if SDL audio plays
sounds as expected, but it’s looking good now.

Really? It’s that bug again? Nice one Scott.

Jonny DOn Thu, Apr 11, 2013 at 8:22 AM, Anthony Walter wrote:

Wow, thank you! You guys are really helpful.

Patching cmake/sdlchecks.cmake seems to have corrected the lock up. I’ll
have to test a project on my other computer to see if SDL audio plays
sounds as expected, but it’s looking good now.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

This is a follow up.

The my tests show the SDL2 audio system no longer hangs or issue failures,
but I’ve had some time to write a test program to play a WAV audio file and
it definitely doesn’t sound right. I can hear part of the audio but it’s so
badly distorted it’s near impossible to recognize. I tried a few different
WAV files and have the same results with each.

To verify my code is correct, I tested it with SDL1 using the version from
Ubuntu’s repositories and it works/plays sound perfectly. This tells me
that either my build of SDL2 and/or its dependencies is messed up, or that
there is a problem somewhere in the SDL2 source code.

Here is the output of my last SDL 2.0 cmake:
http://www.codebot.org/sdl/cmake.txt
(includes patch to cmake/sdlchecks.cmake for thread issue mentioned in
previous messages)

Oh dear, I attached the wrong cmake log to my last message. Here is my
latest cmake output:

http://www.codebot.org/sdl/cmake3.txt

Just to avoid mistakes: are you 100% sure the SDL2 audio buffer is
exactly the same as SDL1’s? Because if you’re passing it data in the
wrong format it sure won’t sound right. Recheck the documentation just
to be sure you’re doing it right.

If it isn’t that then yeah something else may be broken.

2013/4/11, Anthony Walter :> Oh dear, I attached the wrong cmake log to my last message. Here is my

latest cmake output:

http://www.codebot.org/sdl/cmake3.txt

Yes, I am 100% sure. The only difference in my code is a conditional line
where I specify the linking library.

Here is my test source code (The language is Free Pascal. I am writing the
bindings for SDL 2.0). The only difference is the commenting out at line
193.

http://pastebin.com/Z93c3NBB

Update.

I built and ran my test application on a third computer which has Windows 7
installed. I get the similar results, which is normal audio using SDL1, and
badly distorted/hard to recognize audio using SDL 2. In the case of this
Windows test the audio echos all over itself until you can’t make out
anything, whereas on Linux the audio just sounds really
strange/unrecognizable.

For the Windows version of SDL 1, I used the binary package from the
libsdl.org website located here:
http://www.libsdl.org/release/SDL-1.2.15-win32.zip

And instead of building SDL 2.0 myself for 32 Windows, I used a build
mentioned a few days ago in this mailing list:
http://forums.libsdl.org/viewtopic.php?p=36455#36455

If anyone want to give it a listen, here is a binary (plus sample audio
clip) of the Windows test for both SDL 1 and SDL 2:
http://www.codebot.org/sdl/sdl_audio_test_win32.zip

As it seems to me you’re using SDL directly (with no additional library
like SDL_mixer). One difference I encountered lies in the call to the
"mixaudio" callback with the following format:

void mixaudio(void *userdata, Uint8 *stream, int len);

Basically, while SDL 1.2 clears the stream buffer with zeros, SDL 2 does
not.

Reference (from the forums): http://forums.libsdl.org/viewtopic.php?t=8272On 04/12/2013 02:16 AM, Anthony Walter wrote:

Update.

I built and ran my test application on a third computer which has
Windows 7 installed. I get the similar results, which is normal audio
using SDL1, and badly distorted/hard to recognize audio using SDL 2. In
the case of this Windows test the audio echos all over itself until you
can’t make out anything, whereas on Linux the audio just sounds really
strange/unrecognizable.

For the Windows version of SDL 1, I used the binary package from the
libsdl.org http://libsdl.org website located here:
http://www.libsdl.org/release/SDL-1.2.15-win32.zip

And instead of building SDL 2.0 myself for 32 Windows, I used a build
mentioned a few days ago in this mailing list:
http://forums.libsdl.org/viewtopic.php?p=36455#36455

If anyone want to give it a listen, here is a binary (plus sample audio
clip) of the Windows test for both SDL 1 and SDL 2:
http://www.codebot.org/sdl/sdl_audio_test_win32.zip


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Also the length of the buffer isn’t guaranteed, so you NEED to use the
last parameter no matter what.

This is why I asked if you’re 100% sure the buffer is exactly the same
as in 1.2, because SDL2 changed some of the semantics. Also if you
pass a structure to the “desired” parameter instead of NULL when
setting the format then SDL2 is free to choose whatever it can find
rather than converting your specified format to the one the system
needs.

2013/4/12, NY00123 :> As it seems to me you’re using SDL directly (with no additional library

like SDL_mixer). One difference I encountered lies in the call to the
"mixaudio" callback with the following format:

void mixaudio(void *userdata, Uint8 *stream, int len);

Basically, while SDL 1.2 clears the stream buffer with zeros, SDL 2 does
not.

Reference (from the forums): http://forums.libsdl.org/viewtopic.php?t=8272

On 04/12/2013 02:16 AM, Anthony Walter wrote:

Update.

I built and ran my test application on a third computer which has
Windows 7 installed. I get the similar results, which is normal audio
using SDL1, and badly distorted/hard to recognize audio using SDL 2. In
the case of this Windows test the audio echos all over itself until you
can’t make out anything, whereas on Linux the audio just sounds really
strange/unrecognizable.

For the Windows version of SDL 1, I used the binary package from the
libsdl.org http://libsdl.org website located here:
http://www.libsdl.org/release/SDL-1.2.15-win32.zip

And instead of building SDL 2.0 myself for 32 Windows, I used a build
mentioned a few days ago in this mailing list:
http://forums.libsdl.org/viewtopic.php?p=36455#36455

If anyone want to give it a listen, here is a binary (plus sample audio
clip) of the Windows test for both SDL 1 and SDL 2:
http://www.codebot.org/sdl/sdl_audio_test_win32.zip


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

It’s working! In the callback I added logic to fill the stream with
silence. Thanks everyone.

Sik,I apologize for the miscommunication. I thought you were asking if I
was sure my source code was the same, but I see SDL 2.0 handles bytes in
the stream passed to the callback differently in this slight way.

Yeah, that’s exactly the reason why I asked, I was aware SDL2 changed
the semantics a bit so I wanted to make sure you really were using the
same settings :stuck_out_tongue: Otherwise you wouldn’t have issues in the first
place.

SDL2 doesn’t fill the buffer with silence because, well, you were
always supposed to fill in the entire buffer in the first place.
Filling the buffer with data that will get overwritten anyway is a
waste of time.

2013/4/12, Anthony Walter :> It’s working! In the callback I added logic to fill the stream with

silence. Thanks everyone.

Sik,I apologize for the miscommunication. I thought you were asking if I
was sure my source code was the same, but I see SDL 2.0 handles bytes in
the stream passed to the callback differently in this slight way.

SDL2 doesn’t fill the buffer with silence because, well, you were
always supposed to fill in the entire buffer in the first place.
Filling the buffer with data that will get overwritten anyway is a
waste of time.

That’s a good point, but this “hidden API change” is maybe the number one
migration problem in the SDL 1.2 -> 2.0 path :)–
Bye,
Gabry

Technically you were still supposed to fill the entire buffer in SDL1
as far as I know :stuck_out_tongue:

2013/4/15, Gabriele Greco <gabriele.greco at darts.it>:>> SDL2 doesn’t fill the buffer with silence because, well, you were

always supposed to fill in the entire buffer in the first place.
Filling the buffer with data that will get overwritten anyway is a
waste of time.

That’s a good point, but this “hidden API change” is maybe the number one
migration problem in the SDL 1.2 -> 2.0 path :slight_smile:


Bye,
Gabry