# Ogg as mixchunk?

**URL:** <https://discourse.libsdl.org/t/ogg-as-mixchunk/15072>\
**Category:** SDL Development\
**Created:** [January 4, 2008, 3:55pm UTC](https://discourse.libsdl.org/t/ogg-as-mixchunk/15072 "2008-01-04T15:55:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neil\_White](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/n/eada6e/32.png) [@Neil\_White](https://discourse.libsdl.org/u/Neil_White)\
**Post date:** [January 4, 2008, 3:55pm UTC](https://discourse.libsdl.org/t/ogg-as-mixchunk/15072/1 "2008-01-04T15:55:58Z")

</div>

can anyone guide me as to how to load / convert a ogg file into a mix chunk? i  
have done a breif poking around for assistance on the web, but afaict ogg is  
only loadable as a music, er, chunk.

apologies if i have missed the big neon lights telling me how to achieve this.

i have seen games that use oggs as sound files but am not sure if they are  
loaded and then unencoded as ogg each time they play? if so then i think this  
would be to proccesor intensive. and not so hot for low powered devices.

I have a few long sounds i want to use as a semi backing noise in my game, but  
would prefer to use mixchunks, but would also prefer to use ogg’s as the  
original file format to keep disk size down.

any help, tips, whatever please…

---

<div class="post-metadata">

**Author:** ![Neil\_White](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/n/eada6e/32.png) [@Neil\_White](https://discourse.libsdl.org/u/Neil_White)\
**Post date:** [January 4, 2008, 3:59pm UTC](https://discourse.libsdl.org/t/ogg-as-mixchunk/15072/2 "2008-01-04T15:59:37Z")

</div>

Quoting neil at [cloudsprinter.com](http://cloudsprinter.com):

> can anyone guide me as to how to load / convert a ogg file into a mix  
> chunk? i  
> have done a breif poking around for assistance on the web, but afaict ogg is  
> only loadable as a music, er, chunk.

and at some point i will be wanting to store my sound files as oggs in  
a header  
file so it is part of a final binary… and nobody is talking me out of it,  
except the person that explains it isnt possible 😉

---

<div class="post-metadata">

**Author:** ![James\_Barrett](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/j/5f9b8f/32.png) [@James\_Barrett](https://discourse.libsdl.org/u/James_Barrett)\
**Post date:** [January 5, 2008, 2:26am UTC](https://discourse.libsdl.org/t/ogg-as-mixchunk/15072/3 "2008-01-05T02:26:40Z")

</div>

neil at [cloudsprinter.com](http://cloudsprinter.com) wrote:

> can anyone guide me as to how to load / convert a ogg file into a mix chunk? i  
> have done a breif poking around for assistance on the web, but afaict ogg is  
> only loadable as a music, er, chunk.
> 
> apologies if i have missed the big neon lights telling me how to achieve this.
> 
> i have seen games that use oggs as sound files but am not sure if they are  
> loaded and then unencoded as ogg each time they play? if so then i think this  
> would be to proccesor intensive. and not so hot for low powered devices.
> 
> I have a few long sounds i want to use as a semi backing noise in my game, but  
> would prefer to use mixchunks, but would also prefer to use ogg’s as the  
> original file format to keep disk size down.
> 
> any help, tips, whatever please…

Hi, I don’ t know if this will be of any help, but I load ogg sound  
affects using SDL\_mixer by calling Mix\_LoadWAV(). It returns a  
Mix\_Chunk\*. I load all of my sound files during the init phase, and  
store the Mix\_Chunks in a map. Then play them as I need them. I recently  
had to compile SDL\_mixer and libvorbis for linux and windows so I may be  
able to help if you run into any problems getting those installed.

Jim

---

<div class="post-metadata">

**Author:** ![Neil\_White](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/n/eada6e/32.png) [@Neil\_White](https://discourse.libsdl.org/u/Neil_White)\
**Post date:** [January 5, 2008, 1:30pm UTC](https://discourse.libsdl.org/t/ogg-as-mixchunk/15072/4 "2008-01-05T13:30:25Z")

</div>

> > can anyone guide me as to how to load / convert a ogg file into a mix chunk?  
> >   
> > any help, tips, whatever please…
> 
> Hi, I don’ t know if this will be of any help, but I load ogg sound  
> affects using SDL\_mixer by calling Mix\_LoadWAV(). It returns a  
> Mix\_Chunk\*.

ok… i thought i had tried this and crashed… i’ll try again… the  
whole WAV bit  
kinda throws me off.

> I load all of my sound files during the init phase, and  
> store the Mix\_Chunks in a map.

i dont know what you mean hear by map… could you elaborate a bit?

> Then play them as I need them. I recently  
> had to compile SDL\_mixer and libvorbis for linux and windows so I may be  
> able to help if you run into any problems getting those installed.

when i get the chance i am curretntly testing RISC OS versions of various SDL  
and related libaries… there isnt much optimisation going on behind the scenes  
and i am not of the skills to do so, last time i attempted to test OGG playing  
as music it was a bit painful… but that was on a 245mhz StrongARM chip.

so that guy that was asking about ARM code in SDL… RISC OS needs you 😉

---

<div class="post-metadata">

**Author:** ![icculus](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/icculus/32/81_2.png) [@icculus](https://discourse.libsdl.org/u/icculus)\
**Post date:** [January 6, 2008, 7:48am UTC](https://discourse.libsdl.org/t/ogg-as-mixchunk/15072/5 "2008-01-06T07:48:52Z")

</div>

> > can anyone guide me as to how to load / convert a ogg file into a mix  
> > chunk? i  
> > have done a breif poking around for assistance on the web, but afaict ogg is  
> > only loadable as a music, er, chunk.

The increasingly-misnamed Mix\_LoadWAV() will handle them. Just pass a  
buffer of .ogg data instead of a .buffer of .wav, and it’ll do the right  
thing with it.

> and at some point i will be wanting to store my sound files as oggs in  
> a header  
> file so it is part of a final binary… and nobody is talking me out of it,  
> except the person that explains it isnt possible 😉

People say they want to do this, from time to time, and I still can’t be  
convinced there is _any_ scenario where that’s a good idea.

If you want to have one self-contained .exe, append a .zip file to it  
and open yourself at runtime. That lets you not keep all your data in  
static memory (after all, that .ogg is wasted RAM once you decode it),  
lets you be more nimble about adding and changing out the data, and is  
just less messy than the nasty-looking header you’re going to have in  
revision control otherwise.

But, hey, do what you like.

–ryan.

---

<div class="post-metadata">

**Author:** ![Solra\_Bizna](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@Solra\_Bizna](https://discourse.libsdl.org/u/Solra_Bizna)\
**Post date:** [January 6, 2008, 11:02am UTC](https://discourse.libsdl.org/t/ogg-as-mixchunk/15072/6 "2008-01-06T11:02:39Z")

</div>

All of this is true, but embedding a zip file into the EXE (and  
similar strategies) is fairly nonportable. Not only do you have to  
write OS-specific code for it, but on UNIX-likes in particular it’s  
fairly complex and fragile OS-specific code. (I wouldn’t know about  
Windows.)  
Come to think of it, didn’t someone mention a library that  
encapsulates this a while back?  
The header embedding method does have its uses. Recently, for  
instance, I used it to store the default ROM of a simulator for a  
16-bit fixed-word computer. If the user provided an alternate ROM  
image it overwrote the compiled-in ROM. The ROM’s size in the  
architecture is fixed (at a humongous 180Kiwords) so it didn’t need to  
be resizable. It also had the bonus of allowing me to program test  
ROMs using preprocessor macros instead of bullying the assembler into  
working early.  
It occurs to me that you could avoid memory wastage with obscene  
memory allocation code that reuses statically allocated memory, but  
don’t do that.  
-:sigma.SBOn Jan 6, 2008 12:48 AM, Ryan C. Gordon wrote:

> > and at some point i will be wanting to store my sound files as oggs in  
> > a header  
> > file so it is part of a final binary… and nobody is talking me out of it,  
> > except the person that explains it isnt possible 😉
> 
> People say they want to do this, from time to time, and I still can’t be  
> convinced there is _any_ scenario where that’s a good idea.
> 
> If you want to have one self-contained .exe, append a .zip file to it  
> and open yourself at runtime. That lets you not keep all your data in  
> static memory (after all, that .ogg is wasted RAM once you decode it),  
> lets you be more nimble about adding and changing out the data, and is  
> just less messy than the nasty-looking header you’re going to have in  
> revision control otherwise.

---

<div class="post-metadata">

**Author:** ![Neil\_White](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/n/eada6e/32.png) [@Neil\_White](https://discourse.libsdl.org/u/Neil_White)\
**Post date:** [January 6, 2008, 12:14pm UTC](https://discourse.libsdl.org/t/ogg-as-mixchunk/15072/7 "2008-01-06T12:14:18Z")

</div>

> That lets you not keep all your data in  
> static memory (after all, that .ogg is wasted RAM once you decode it),

i never really thoguth about this like this, but i guess as long as all  
my data  
isnt consuming much more than about 20 ish meg then i wont worry about it too  
much, but then i should worry about it if i want it to be nice on low  
powered (  
low memory )machines, i guess i should set a limit on just how low  
powered this  
game should be able to run on.

The main reason i want all the files in the exe are a) so they cant get messed  
about possibly messing up the game b) er, perhaps so linux bods can  
easilly run  
and pass around the game without the rigmarole of $HOME and all that jazz of  
where the data is and who owns it and what not.  
Basically i just want it to be simple to download and use for everything it is  
compiled for, apart from issues about where SDL runtime libraries are, just  
simple. if that makes sence.

When i compile something for RISC OS everything SDL like goes into the final  
binary anyway… there is no sdl.dll or whatever… i’m still not sure where the  
various licences for sdl stand on this…

current rate of development the game might be at commercially viable  
level and i  
might be happy with it by about 2017 😉 i refuse to just say b\*llocks  
to it and  
release it as GPL and forget about it…
