Highly compressed sound playback confusion

Alright, while I’m really not much of a newbie to SDL or SDL-related
libs, there is one aspect that I’ve never looked much into and now its
come to bite me in the ass…

Over at Tux Typing we had some /great/ music donated to us many months
ago for inclusion in our project. This music is stored in Ogg Vorbis
files. As you all know, decoding OGG/MP3 files on-the-fly can be rather
CPU intensive…

Well, I know there must be a way to decompress them before hand, keep
them in memory in a cache of some sort, and then just play them back
without taxing the CPU anymore. But for the life of me I can’t figure
out a practical (and cross-platform :wink: way of doing this. Searching
through the SDL mailing list archives only showed it can be done, just
not how.

Can this be done using SDL_mixer? (I don’t want to suddenly switch to
SDL_Sound in the middle of a stable branch :wink: Can anyone point me to
some code that does this already, so I can see how it’s done?–
Sam “Criswell” Hart <@Sam_Hart> AIM, Yahoo!:
Homepage: < http://www.geekcomix.com/snh/ >
PGP Info: < http://www.geekcomix.com/snh/contact/ >
Tux4Kids: < http://www.tux4kids.org/ >

Can this be done using SDL_mixer? (I don’t want to suddenly switch to
SDL_Sound in the middle of a stable branch :wink: Can anyone point me to
some code that does this already, so I can see how it’s done?

All you need to do is decompress the file once - decompress it to a WAV
file and store it on the hard disk, then stream it from there. The
Ogg/Vorbis libs should already have a way that you can feed it the
Ogg/Vorbis stream and it’ll spit raw samples out the other end.

–>Neil-------------------------------------------------------------------------------
Neil Bradley What are burger lovers saying
Synthcom Systems, Inc. about the new BK Back Porch Griller?
ICQ #29402898 “It tastes like it came off the back porch.” - Me

At 05:36 PM 8/10/02 -0700, you wrote:

Well, I know there must be a way to decompress them before hand, keep
them in memory in a cache of some sort, and then just play them back
without taxing the CPU anymore. But for the life of me I can’t figure
out a practical (and cross-platform :wink: way of doing this. Searching
through the SDL mailing list archives only showed it can be done, just
not how.

It’s not a SDL function that you’re looking for – you want to use
libvorbis to do the decompression, which should give you a wave (or blocks
of a wave) that you can feed through SDL_Mixer to play.

There’s libvorbis documentation up on the 'net somewhere, but generally
you’re looking for the ov_read() function. libvorbis is simple and you
could use whatever lib you want to play the pcm data, but if you’re
worried about CPU, then I second the recommendation about decoding the
entire thing to a wav first.

– chris (@Christopher_Thielen)On Sat, 2002-08-10 at 17:48, Christopher Subich wrote:

Well, I know there must be a way to decompress them before hand, keep
them in memory in a cache of some sort, and then just play them back
without taxing the CPU anymore. But for the life of me I can’t figure
out a practical (and cross-platform :wink: way of doing this. Searching
through the SDL mailing list archives only showed it can be done, just
not how.

It’s not a SDL function that you’re looking for – you want to use
libvorbis to do the decompression, which should give you a wave (or blocks
of a wave) that you can feed through SDL_Mixer to play.

Can this be done using SDL_mixer? (I don’t want to suddenly switch to
SDL_Sound in the middle of a stable branch :wink: Can anyone point me to
some code that does this already, so I can see how it’s done?

The latest SDL_mixer will let you playback raw audio samples, so (if you
don’t want to use SDL_sound) you could write something that calls
vorbisfile directly.

Alternately:

#include "SDL_sound.h"
Sound_Init();
Sound_Sample *sample = Sound_NewSampleFromFile(filename);
Sound_DecodeAll(sample);
// use sample->buffer as a raw waveform with SDL_mixer.
Sound_FreeSample(sample);
Sound_Quit();

–ryan.

I’m aware of that. I know conceptially how its done, I was just hoping
someone out there could point me to some code that already does it so I
can see how its done.

libvorbis doesn’t seem to have the most easily accessable documentaion
(at least, perusing xiph.org, doesn’t yeild me the sort of information
I’m looking for… but I may just be being net-blind and somehow missing
it ;-)On Sat, 2002-08-10 at 17:48, Christopher Subich wrote:

At 05:36 PM 8/10/02 -0700, you wrote:

Well, I know there must be a way to decompress them before hand, keep
them in memory in a cache of some sort, and then just play them back
without taxing the CPU anymore. But for the life of me I can’t figure
out a practical (and cross-platform :wink: way of doing this. Searching
through the SDL mailing list archives only showed it can be done, just
not how.

It’s not a SDL function that you’re looking for – you want to use
libvorbis to do the decompression, which should give you a wave (or blocks
of a wave) that you can feed through SDL_Mixer to play.


Sam “Criswell” Hart <@Sam_Hart> AIM, Yahoo!:
Homepage: < http://www.geekcomix.com/snh/ >
PGP Info: < http://www.geekcomix.com/snh/contact/ >
Tux4Kids: < http://www.tux4kids.org/ >

Ultimately, it looks like this might be even easier of a transition then
all of a sudden including the vorbis libraries (which, from what I’ve
seen, look like they have lots of caveats for different platforms I’d
have to familierize myself with).

How cross-platform is SDL_sound at this moment? Currently, Tux Typing
compiles and runs on many different platforms (Linux, Win32, MacOS,
BeOS, Solaris, etc., etc.) and I don’t want to all of a sudden cut off
our users if I made the switch right now ;-)On Sun, 2002-08-11 at 09:59, Ryan C. Gordon wrote:

Can this be done using SDL_mixer? (I don’t want to suddenly switch to
SDL_Sound in the middle of a stable branch :wink: Can anyone point me to
some code that does this already, so I can see how it’s done?

The latest SDL_mixer will let you playback raw audio samples, so (if you
don’t want to use SDL_sound) you could write something that calls
vorbisfile directly.

Alternately:

#include "SDL_sound.h"
Sound_Init();
Sound_Sample *sample = Sound_NewSampleFromFile(filename);
Sound_DecodeAll(sample);
// use sample->buffer as a raw waveform with SDL_mixer.
Sound_FreeSample(sample);
Sound_Quit();


Sam “Criswell” Hart <@Sam_Hart> AIM, Yahoo!:
Homepage: < http://www.geekcomix.com/snh/ >
PGP Info: < http://www.geekcomix.com/snh/contact/ >
Tux4Kids: < http://www.tux4kids.org/ >

How cross-platform is SDL_sound at this moment? Currently, Tux Typing
compiles and runs on many different platforms (Linux, Win32, MacOS,
BeOS, Solaris, etc., etc.) and I don’t want to all of a sudden cut off
our users if I made the switch right now :wink:

SDL_sound runs on all those platforms, and if it doesn’t, it’s a bug.

–ryan.