xcodesdl-2sdl-mixeroggvorbis

How do I use OGG with SDL_Mixer?


I can't seem to get SDL_Mixer to initialize with OGG support enabled. I know that I must link with libogg, libvorbis and libvorbisfile but it still won't work. I have .dylibs, .frameworks and .as of these three libraries and I've tried them all.

I'm copying the dylibs/frameworks into the Frameworks folder of the app package in the build phases tab.

I have Runpath Search Paths set to @executable_path/../Frameworks in the build settings tab.

But Mix_Init(MIX_INIT_OGG) keeps returning the error OGG support not available.

I'm using the latest Homebrew versions of all of the mentioned libraries. I'm not sure what else to try.

I have a finished game with 300MB of wavs as the music.

Update

I’ve managed to mix some Objective C with C++ and get some sound playing with AVAudioPlayer but it’s horrendous code. I’m having to cast to void * to make sure my music player class is compatible with my C++ code base. The garbage collector is so annoying. All it does is get in your way. You have to fight it with bridge casts.

I’d really like to use SDL_Mixer or a simple C library.


Solution

  • I got the Objective C music player fully implemented but I just can’t stand Objective C. I found a brilliant library called stb_vorbis. I’ve used a few of the other stb libraries so I knew this one would be great. Playing the audio data from this library is actually pretty easy. All I really had to do was call stb_vorbis_get_samples_short_interleaved inside of SDL2’s audio callback. I didn’t have to do any mixing because I only need to play music. The implementation was so simple that it actually worked perfectly the first time I ran it! This because stb_vorbis and SDL2 are both C libraries so they just make sense (unlike Objective C which should be burned).

    TL;DR

    If you just want to play music and either can’t use SDL_Mixer or don’t want to use SDL_Mixer then you can just feed the data from stb_vorbis into SDL2’s audio callback.