Ogg playback for Mac apps

Member
Posts: 20
Joined: 2010.09
Post: #1
Hello,

Although personally I'm fine with using mp3's, other Mac devs are hell-bent on using ogg's for their projects. GM apps only support mp3's, therefore, you can only use mp3's, wavs, and the 'common' sound files.

Since I'm happy with mp3, other people developed an Extension that lets you play back ogg's... however, you need to install system frameworks for openAL and Vorbis decoders... not very user friendly, and definitely not App Store friendly. They seem to be having trouble either including the frameworks inside the app bundle or inside the dylib itself. I believe Apple also isn't very happy with you using frameworks on App Store apps.

Therefore, I decided to do a little research on the subject myself. As some of you may know, I'm completely new to OS X programming and I'm quite the noob at C programming... what would be the easiest, cheapest, fastest way of writing a BSD C dylib wrapper for OGG playback on OS X? Preferably in a way where you don't have to use frameworks? The dylib also needs to be 32bit, which I think (I'm not sure) rules out openAL in Snow Leopard.

Any hints?
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
OpenAL is a system framework included with Mac OS X since 10.4 (as I recall, might've been 10.3 even), so there's no need to include your own. With a little bit of effort, you can compile libogg, libvorbis, and libvorbisfile yourself and statically link to them.

On 10.6, I just checked my system OpenAL and it's built for both i386 and x86_64, so linking to it from 32-bit code shouldn't be a problem.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
http://onesadcookie.com/svn/Third-Party will build you many architectures of static libs for ogg & vorbis. It hasn't been updated in a while, so things like versions and URLs might need tweaking.
Quote this message in a reply
Member
Posts: 33
Joined: 2010.09
Post: #4
You might be fine with using MP3s, but you'll still need a license to actually get away with it Wink
Quote this message in a reply
Member
Posts: 227
Joined: 2008.08
Post: #5
I've taken a liking to stb_vorbis lately, it's small (one header), it's straightforward, and it's pretty easily connected to OpenAL.

http://nothings.org/stb_vorbis/
Quote this message in a reply
Member
Posts: 40
Joined: 2010.03
Post: #6
Just wanted to help explain why ogg is loved so much, from an audio designer's point of view. Ogg gets a bit better compression and quality compared to mp3, but the real beauty is being able to loop seamlessly. Unless you have some fancy code or tools, mp3s add a bit of silence (data, really) before/after the actual song, thus on repeat you'll hear a bit of silence, ruining the perfect loop.

Best of luck in your ogging!

Original Music and Sound Design for Video Games
http://www.harrymack.com
Quote this message in a reply
Member
Posts: 21
Joined: 2008.05
Post: #7
(May 8, 2011 08:42 AM)Oddity007 Wrote:  I've taken a liking to stb_vorbis lately, it's small (one header), it's straightforward, and it's pretty easily connected to OpenAL.

http://nothings.org/stb_vorbis/

Hello there,
I got this working-ish.... I'm doing a decode from memory and it seems to stop after a minute of playing. Is there some setting somewhere that is making it not decoded the entire thing to memory?

(I'm using xcode4 and c++)
Thanks!
Quote this message in a reply
Member
Posts: 227
Joined: 2008.08
Post: #8
I wouldn't advise decoding completely into memory as uncompressed sound files can be huge (on the order of GB, sometimes) Instead, I'd look into streaming. It's likely that you are decoding only a small chunk, if that is the case, then you just need to queue the buffers to play on a source.

This is how I do it (Sorry that the code sucks):
http://gist.github.com/965399
Quote this message in a reply
Member
Posts: 33
Joined: 2010.09
Post: #9
Definitely always stream music and other long ambient loops (or longer speech), yes. You should probably implement some sort of sound cache for handling sound effects, too. Anything that needs to be available instantly, like weapon effects, probably should preload. Or at least buffer on first use.

I like this thing for iOS: OpenALManager (formerly ObjectAL)
The author is active on the Cocos2D forums, and has mentioned he doesn't want to limit it only to iOS Modifying it for OS X is supposedly easy. Great little library if you want some fancy caching handled and just want to get on with your game Smile
Quote this message in a reply
Member
Posts: 21
Joined: 2008.05
Post: #10
(May 10, 2011 02:18 PM)Oddity007 Wrote:  I wouldn't advise decoding completely into memory as uncompressed sound files can be huge (on the order of GB, sometimes) Instead, I'd look into streaming. It's likely that you are decoding only a small chunk, if that is the case, then you just need to queue the buffers to play on a source.

This is how I do it (Sorry that the code sucks):
http://gist.github.com/965399

Hey! Thanks!
I was able to take your code and merge it with my own stuff and get it all to work! This saved me a ton of time and research. Thanks!
Quote this message in a reply
Member
Posts: 20
Joined: 2010.09
Post: #11
Ah, those statics, didn't even remotely know that could be done. Great.

I'll mess around with this. Thanks a lot. Grin
Quote this message in a reply
Post Reply