SDL2 and SDL_sound incompatibility?

Ever since I started using SDL2, SDL_sound hasn’t worked for me.
Every time I try to play a sound file, SDL_sound says “Sound format unsupported”. I’m trying to play a basic wav file, which is one I’m sure used to play fine with SDL_sound. I don’t think any of the decoders are actually loading.

Does anyone know if SDL_sound does indeed work with SDL2 (and with specifically Mac 10.8 )? Are there any tricks to getting it to work?

SDL_sound comes with an old playsound.pbproj sample project that no longer seems to work. If anyone knows of a functional example, I’d love to see it.

Does anyone know if SDL_sound does indeed work with SDL2 (and with
specifically Mac 10.8 )? Are there any tricks to getting it to work?

Just tried it on 10.8 with SDL2, and it’s working for the .wav file I
tried. Is it possible that you’re trying to play an .ogg or something
and didn’t build it with Vorbis (or whatever) support?

SDL_sound comes with an old playsound.pbproj sample project that no
longer seems to work.

Another good argument for CMake. :stuck_out_tongue:

–ryan.

Ryan C. Gordon wrote:

Does anyone know if SDL_sound does indeed work with SDL2 (and with
specifically Mac 10.8 )? Are there any tricks to getting it to work?

Just tried it on 10.8 with SDL2, and it’s working for the .wav file I
tried. Is it possible that you’re trying to play an .ogg or something
and didn’t build it with Vorbis (or whatever) support?

SDL_sound comes with an old playsound.pbproj sample project that no
longer seems to work.

Another good argument for CMake. :stuck_out_tongue:

–ryan.

It’s definitely a valid .wav file (one that worked before).
Have you tried getting something like the sample playsound.c to compile with CMake? Have you tried compiling with an Xcode project?

Now that you tell me it’s possible, I’ll see if I can figure out what my problem was.

I posted an updated Xcode project maybe a year ago. It may be out of
date again, but should be easy to bring up to date:
https://www.assembla.com/spaces/SDL_sound_CoreAudio/documents

Also, I have a contributed a native Core Audio decoder for SDL_sound.
That uses very little of the SDL infrastructure and leverages mostly
Core Audio to do everything. I would expect that to be immune from
differences between SDL 1.2 and 2.0. (The plugin came out of a project
where I couldn’t use SDL/SDL_sound and I backported it to SDL_sound
for everybody to use.)

-Eric

P.S. I like CMake too.On 8/15/12, Trev wrote:

Ryan C. Gordon wrote:

Does anyone know if SDL_sound does indeed work with SDL2 (and with
specifically Mac 10.8 )? Are there any tricks to getting it to work?

Just tried it on 10.8 with SDL2, and it’s working for the .wav file I
tried. Is it possible that you’re trying to play an .ogg or something
and didn’t build it with Vorbis (or whatever) support?

SDL_sound comes with an old playsound.pbproj sample project that no
longer seems to work.

Another good argument for CMake. :stuck_out_tongue:

–ryan.

It’s definitely a valid .wav file (one that worked before).
Have you tried getting something like the sample playsound.c to compile with
CMake? Have you tried compiling with an Xcode project?

Now that you tell me it’s possible, I’ll see if I can figure out what my
problem was.


Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/

Eric Wing wrote:> On 8/15/12, Trev <@Trevor_Agnitti> wrote:

Ryan C. Gordon wrote:

Does anyone know if SDL_sound does indeed work with SDL2 (and with
specifically Mac 10.8 )? Are there any tricks to getting it to work?

Just tried it on 10.8 with SDL2, and it’s working for the .wav file I
tried. Is it possible that you’re trying to play an .ogg or something
and didn’t build it with Vorbis (or whatever) support?

SDL_sound comes with an old playsound.pbproj sample project that no
longer seems to work.

Another good argument for CMake. :stuck_out_tongue:

–ryan.

It’s definitely a valid .wav file (one that worked before).
Have you tried getting something like the sample playsound.c to compile with
CMake? Have you tried compiling with an Xcode project?

Now that you tell me it’s possible, I’ll see if I can figure out what my
problem was.

I posted an updated Xcode project maybe a year ago. It may be out of
date again, but should be easy to bring up to date:
https://www.assembla.com/spaces/SDL_sound_CoreAudio/documents

Also, I have a contributed a native Core Audio decoder for SDL_sound.
That uses very little of the SDL infrastructure and leverages mostly
Core Audio to do everything. I would expect that to be immune from
differences between SDL 1.2 and 2.0. (The plugin came out of a project
where I couldn’t use SDL/SDL_sound and I backported it to SDL_sound
for everybody to use.)

-Eric

P.S. I like CMake too.

Thanks, Eric. That framework you linked works great on my mac version, but I still haven’t been able to figure out how to get SDL_sound running on the iPad/iPhone. That framework doesn’t seem to work for that. I’m not sure if it was intended to.
If anyone has any tips/suggestions, I’d love to hear them.

Thanks, Eric. That framework you linked works great on my mac version, but I
still haven’t been able to figure out how to get SDL_sound running on the
iPad/iPhone. That framework doesn’t seem to work for that. I’m not sure if
it was intended to.
If anyone has any tips/suggestions, I’d love to hear them.

I didn’t make an iOS Xcode project for this. However, it’s actually
the same exact thing because the code is identical between Mac and
iOS. The big difference is that you have to build a static library
(not a dynamic library or framework) for iOS.

The easiest thing to do is create a new Xcode project for iOS for a
static library. Import all the files in use by the Mac Xcode project
and copy over all the preprocessor defines set in the Mac Xcode
project.

Also, in your actual app, you will need to link to AudioToolbox.framework.

One additional note, if you are using Ogg, you might want to look at
Tremor instead of Vorbis. I think I sent Ryan my Tremor stuff too. But
just to get started, I would just try to get the base case going the
Core Audio backend and worry about the extras later.

-Eric–
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/

I made a new IOS static library with Xcode and added all the files referenced from the mac project.
I added the same preprocessor macros:
SOUND_SUPPORTS_COREAUDIO SOUND_SUPPORTS_MPGLIB SOUND_SUPPORTS_QUICKTIME SOUND_SUPPORTS_OGG SOUND_SUPPORTS_WAV SOUND_SUPPORTS_AIFF SOUND_SUPPORTS_AU SOUND_SUPPORTS_MIKMOD SOUND_SUPPORTS_RAW SOUND_SUPPORTS_SHN SOUND_SUPPORTS_VOC

I added the .a static library to my project (as well as the SDL_sound source files). That initially built fine until I realized the decoders weren’t loading. (Sound_AvailableDecoders found none.) I then realized I needed to include those preprocessor macros BOTH in my project as well as while making the static library. I was initially just doing the latter.

With the preprocessor macros in place, I started to encounter some build errors. Several files (such as au.c and aiff.c) reference a member of Sound_SampleInternal called “total_time”, but if you look at the definition of Sound_SampleInternal in SDL_sound_internal.h, that struct has no such member. So my guess is that I either have an outdated SDL_sound_internal.h file that’s missing a total_time definition, or my decoder files are outdated and shouldn’t be referencing total_time.

Any idea where I’m going wrong?

I made a new IOS static library with Xcode and added all the files
referenced from the mac project.
I added the same preprocessor macros:
SOUND_SUPPORTS_COREAUDIO SOUND_SUPPORTS_MPGLIB SOUND_SUPPORTS_QUICKTIME
SOUND_SUPPORTS_OGG SOUND_SUPPORTS_WAV SOUND_SUPPORTS_AIFF SOUND_SUPPORTS_AU
SOUND_SUPPORTS_MIKMOD SOUND_SUPPORTS_RAW SOUND_SUPPORTS_SHN
SOUND_SUPPORTS_VOC

For iOS, you should remove
SOUND_SUPPORTS_MPGLIB
SOUND_SUPPORTS_QUICKTIME
SOUND_SUPPORTS_WAV
SOUND_SUPPORTS_AIFF
SOUND_SUPPORTS_AU
SOUND_SUPPORTS_RAW
SOUND_SUPPORTS_VOC

I think CoreAudio handles all those formats natively.

I added the .a static library to my project (as well as the SDL_sound source
files). That initially built fine until I realized the decoders weren’t
loading. (Sound_AvailableDecoders found none.) I then realized I needed to
include those preprocessor macros BOTH in my project as well as while making
the static library. I was initially just doing the latter.

I could be mistaken, but that doesn’t sound right to me. Your project
should only include SDL_sound.h which touches none of those defines.
Only compiling SDL_sound needs to know about those flags. You compile
the static library and you make your project link to it.

With the preprocessor macros in place, I started to encounter some build
errors. Several files (such as au.c and aiff.c) reference a member of
Sound_SampleInternal called “total_time”, but if you look at the definition
of Sound_SampleInternal in SDL_sound_internal.h, that struct has no such
member. So my guess is that I either have an outdated SDL_sound_internal.h
file that’s missing a total_time definition, or my decoder files are
outdated and shouldn’t be referencing total_time.

total_time is probably from the tip of the revision control branch. My
friends and I added that back in 2003, but there hasn’t been another
former release of SDL_sound since then. Use the tip, not the stable
release.

-EricOn 9/18/12, Trev wrote:

Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/

I downloaded the latest version and it has total_time defined correctly in SDL_sound_internal.h, so that resolves that issue.

I made an IOS static library project, and added the files from your mac xcode project. You said for the iOS version, I should omit SOUND_SUPPORTS_MPGLIB, SOUND_SUPPORTS_QUICKTIME, SOUND_SUPPORTS_WAV, SOUND_SUPPORTS_AIFF, SOUND_SUPPORTS_AU, SOUND_SUPPORTS_RAW, and SOUND_SUPPORTS_VOC.

I assume that means I should also omit
aiff.c
au.c
raw.c
voc.c
wav.c

And that static library was defined with just these preprocessor macros:
SOUND_SUPPORTS_COREAUDIO SOUND_SUPPORTS_OGG SOUND_SUPPORTS_MIKMOD SOUND_SUPPORTS_SHN

That resulted in a 162KB static library, which I then added to my project, along with SDL_sound.h and nothing else. I tried compiling my project and I got an error that basic SDL_sound functions were not defined, such as Sound_GetError and Sound_Init. I thought those were supposed to be defined within the static library but that error implies otherwise. I added those same files I added while making the static library and my project compiled successfully and the sound files play correctly.

So my program currently supports:

Supported sound formats:

  • Shorten-compressed audio data
    File extension "SHN"
    Written by Ryan C. Gordon .
    http://www.icculus.org/SDL_sound/

  • Decode audio through Core Audio through
    File extension "aif"
    File extension "aiff"
    File extension "aifc"
    File extension "wav"
    File extension "wave"
    File extension "mp3"
    File extension "mp4"
    File extension "m4a"
    File extension "aac"
    File extension "caf"
    File extension "Sd2f"
    File extension "Sd2"
    File extension "au"
    File extension "next"
    File extension "mp2"
    File extension "mp1"
    File extension "ac3"
    File extension "3gpp"
    File extension "3gp2"
    File extension "amrf"
    File extension "amr"
    File extension "ima4"
    File extension "ima"
    Written by Eric Wing <ewing . public @ playcontrol.net>.
    http://playcontrol.net

And that’s plenty of sound formats for my uses.

Thanks for helping me get it to work.

Eric, it seems like you’re using version 1.0.1 of SDL_sound at https://www.assembla.com/spaces/SDL_sound_CoreAudio/documents/ and I’m curious why you aren’t using 1.0.3.

So I don’t know what the versions are any more. I think I’m usually on
tip (whenever tip is when I happen to pull). The problem is that my
patch Duration way back in 2003-4 or whatever introduced an API change
and maybe some binary compatibility issues. It went into a different
branch which was supposed to be for 1.1. Anyway, whatever I do is
usually intended for that to-be 1.1 branch because I need the Duration
stuff for what I do.On 9/20/12, Trev wrote:

Eric, it seems like you’re using version 1.0.1 of SDL_sound at
https://www.assembla.com/spaces/SDL_sound_CoreAudio/documents/ and I’m
curious why you aren’t using 1.0.3.


Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/