• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Fredrik Elmegren

Compressed sound, what format to use?

15 posts in this topic

[size=3]Hi![/size]

[size=3]I'm about to start implementing support for playing compressed sound for our game engine. Unsurprisingly we're on a tight budget both performance-wise and memory-wise. I've been looking at the ADPCM-wav-compression and it could be a possible solution, although it would require a lot of extra hacking. We use OpenAL, and unfortunately it doesn't natively support ADPCM which would mean we'd have to 'manually' decompress the sound before sending it to OpenAL. [/size]

[size=3]Right, so my question to you is: What sound compression would you recommend us using? As I said, performance is a big thing for us so the it can't have a large inpact on that.[/size]

Cheers!
/ Freddy

[size=3]ps. an audio-section here in the forums would be nice! [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] [/size]
0

Share this post


Link to post
Share on other sites
I would indeed also vote for Ogg Vorbis format. It is a good format that can be used easily in combination with OpenAL. The encoder and decoders are also not emcumbered with wierd licenses, so you can freely use it.
0

Share this post


Link to post
Share on other sites
While I would also recommend Vorbis (what's usually miscalled OGG, we're talking about the encoding format here, guys), take into account he is worried about performance. I guess he's expecting a large amount of sound sources all having to get decompressed at the same time.

I have used Vorbis in the past in some games to store both the background music and sound effects. By this I mean the sound data was loaded into memory as-is (still Vorbis) and then decompressed during playback. This was done to save memory (even though it may have been overkill for sound effects). Didn't seem to have any impact on performance at all (and it was a quite old computer for today's standards - the CPU was a 2.4 GHz Pentium IV, also the game was software rendered), but then again at most you had the background music and a couple of sound effects going on.

I have absolutely no idea of a good compression format that has good decompression performance. ADPCM is very fast to decompress, but the compression ratio isn't all that good in comparison to newer encoding methods.

EDIT: also it may be worth a shot to use Vorbis for background music and something more lightweight for sound effects. There would be only one music going on so performance isn't much of an issue there, while sound effects are short so space usage isn't much of an issue there. Sounds like it could be a good trade-off (even better would be to let users specify what format to use for each sound source if possible, ideally explaining what's the best way to use each format).

EDIT 2: also in case you wonder, ADPCM is [i]fast[/i]. I know of a homebrew sound engine that can do ADPCM playback at 22 KHz on a 3.58 MHz Z80 (and that's an 8-bit processor!), so in the case of ADPCM performance would be the least of your worries. Just don't expect all that much compression from it (although it's still significant compared to uncompressed).
1

Share this post


Link to post
Share on other sites
Thank you all for your replies!

Sik you're spot on. We have [b]a lot[/b] of sound loaded into memory, where all the larger sound files already are vorbis compressed. It's all the smaller (400kb and less) uncompressed sounds we're trying to reduce the size of. I did some testing and came to the conclusion that Ogg Vorbis is not a viable solution for us as it would be too expensive performance-wise to decode.

ADPCM seems to be the way to go here. We'd be able to compress all of our uncompressed wav down to a 1/4 in size which is quite nice. But, as I mentioned, we're using OpenAL which doesn't support ADPCM on Windows. This means I'll have to make a hack that decodes/decompresses the ADPCM-sound before sending it to OpenAL.

Please reply if you think there's anything I should keep in mind when doing this.

Again, thank you all [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
0

Share this post


Link to post
Share on other sites
Hi, it would help if you tell us what kind of CPU budget you have (a Pentium II processor? an Intel Core 2 Duo? Single or Dual core? An ARM for cellphones? iPhone? Android?) and what is your memory budget (16MB? 128MB? 256? 512? 4GB?) and how much memory you're using already without sounds loaded, and how much time in seconds you have in sounds.

I personally use raw pcm for sounds (most of them areEdit: Somehow half of my post was cut. A GD.Net bug? I have to go, I'll repost later. Still answer the question above
0

Share this post


Link to post
Share on other sites
[quote name='Matias Goldberg' timestamp='1325695484' post='4899625']
Hi, it would help if you tell us what kind of CPU budget you have (a Pentium II processor? an Intel Core 2 Duo? Single or Dual core? An ARM for cellphones? iPhone? Android?)
[/quote]

If it's a Windows app, I would look into XAct. Doesn't matter what the file format is because it's compressed down into XAct specific file (*.xwb). The amount of compression can be set.
0

Share this post


Link to post
Share on other sites
I wrote some code to decode ADPCM, but I found a bad flaw in the specification. It introduces unnecessary padding at the end of the file.
0

Share this post


Link to post
Share on other sites
[quote name='happytrooper' timestamp='1325689492' post='4899603']Please reply if you think there's anything I should keep in mind when doing this.[/quote]
Well, here's another suggestion but I guess you'll kill me for this =P

Basically you could try reducing the quality of sound effects when size becomes problematic. People can't distinguish between 8-bit and 16-bit samples unless they're audiophiles, and many sound effects can be downsampled without much distortion (how much you can downsample depends on the sound effect - low pitched ones aren't affected much, high pitched ones are less tolerant). I have tried this before and it worked pretty well.

One thing to take into account though is that if you downsample you should avoid interpolation at all costs, because that's what makes them sound worse. It doesn't help it usually happens at the hardware level so it's hard to avoid... Generally you do this by setting the audio output at a higher sample rate and then repeating samples when playing back (e.g. if the sound is 11025 Hz and the output is 44100 Hz you'd repeat each sample four times). This ensures the audio output sounds clear and not muffled.

Besides that, yeah, not much to say. ADPCM is extremely fast to process so you probably shouldn't worry all that much about it, and most likely Vorbis is being decompressed in software on most computers anyways.
1

Share this post


Link to post
Share on other sites
Right!

So I've implemented a decoder ([url="http://wiki.multimedia.cx/index.php?title=IMA_ADPCM"]http://wiki.multimedia.cx/index.php?title=IMA_ADPCM[/url]) to decode my IMA ADPCM sound.. buuuut the sound gets errrmm.. I'll let this picture talk for me:

[img]http://i39.tinypic.com/353bb0x.png[/img]

See the 'chunks' in the wave? (Oh, and it sounds like it looks btw) The first 'chunk' is perfect but then it goes dooownhill.. Any clue from just looking at this what I might be doing wrong? If not I'll post some code.

Cheers!
1

Share this post


Link to post
Share on other sites
I suspect you're not resetting the parameters at the start of each block. See http://wiki.multimedia.cx/index.php?title=Microsoft_IMA_ADPCM for how it does that for MS ADPCM.
1

Share this post


Link to post
Share on other sites
[quote name='Adam_42' timestamp='1327515078' post='4906158']
I suspect you're not resetting the parameters at the start of each block. See [url="http://wiki.multimedia.cx/index.php?title=Microsoft_IMA_ADPCM"]http://wiki.multimed...osoft_IMA_ADPCM[/url] for how it does that for MS ADPCM.
[/quote]

That sounds about right! Thanks for your reply! Although .. I'm having a bit of troubling getting my head around this.. Does this mean I should do the decoding in chunks? Right now I'm applying the decoding algorithm to the entire data:

[source]int decode(int16* dst, const uint8* src, uint srcSize)[/source]
where srcSize is the size of the encoded data in bits and my predictedValue and stepIndex continuously follow through to the next nibble-iteration. Do I need to instead do this per block (block align in fmt-chunk?)?

perhaps something like this:
[source]int decode(int16* dst, const uint8* src, int srcOffset, uint srcSize)[/source]
where srcOffset is the current offset into the source data?

Thanks in advance!
0

Share this post


Link to post
Share on other sites
That sounds about right to me. Note that the MS-ADPCM format stores the predictedValue and stepIndex at the start of each block. I suspect your data will be similar.

You should be able to work out how much extra header data there is - if there was no block header the compression ratio would be exactly 4:1.
1

Share this post


Link to post
Share on other sites
The audio I'm working with comes from .wav-files which I presume means I should follow this: [url="http://wiki.multimedia.cx/index.php?title=Microsoft_IMA_ADPCM"]http://wiki.multimed...osoft_IMA_ADPCM[/url]
I'm a bit confused on the [i]"This field reveals the size of a [b]block [/b]of IMA-encoded data."[/i] and that it then says [i]"an individual [b]chunk [/b]of data begins with the following preamble:"[/i]. I'm guessing they both refer to the same thing?

So, from what I've interpreted I should do something like this:

[code]foreach(adpcm_block in raw_audio_data)
{
var predictedValue = bytes 0 - 1 of adpcm_block
var stepIndex = byte2 of adpcm_block
// ignore byte 3 of adpcm_block
foreach(4bit nibble in adpcm_block) // this would start on byte 4 (the fifth byte) in the block?
{
decompress(nibble)
}
}[/code]

Does that look correct? If it does I'll have to post some code because I can't get it bloody right! [img]http://public.gamedev.net//public/style_emoticons/default/angry.png[/img]
0

Share this post


Link to post
Share on other sites
I don't think block and chunk are the same thing, if you follow the link to the WAVEFORMATEX structure details and then onto the MSDN page you'll find the following;

[quote]
Block alignment, in bytes. The block alignment is the minimum atomic unit of data for the [b]wFormatTag[/b] format type. If [b]wFormatTag[/b] is WAVE_FORMAT_PCM, [b]nBlockAlign[/b] must equal ([b]nChannels[/b] × [b]wBitsPerSample[/b]) / 8. For non-PCM formats, this member must be computed according to the manufacturer's specification of the format tag.
[/quote]

So for a 16bit stereo sample you get (2 x 16) / 8 or 4 bytes per sample.

A 'chunk' on the other hand looks to be header + audio data, which will of course be larger than 4 bytes ;)
1

Share this post


Link to post
Share on other sites
Hey phantom and thanks for your reply!

[quote name='phantom' timestamp='1328811614' post='4911391']
I don't think block and chunk are the same thing, if you follow the link to the WAVEFORMATEX structure details and then onto the MSDN page you'll find the following;

[quote]
Block alignment, in bytes. The block alignment is the minimum atomic unit of data for the [b]wFormatTag[/b] format type. If [b]wFormatTag[/b] is WAVE_FORMAT_PCM, [b]nBlockAlign[/b] must equal ([b]nChannels[/b] × [b]wBitsPerSample[/b]) / 8. For non-PCM formats, this member must be computed according to the manufacturer's specification of the format tag.
[/quote]

So for a 16bit stereo sample you get (2 x 16) / 8 or 4 bytes per sample.

A 'chunk' on the other hand looks to be header + audio data, which will of course be larger than 4 bytes ;)
[/quote]

That's exactly what caused my confusion in the first place! Pulling apart wav-files I've been extracting various chunks ([url="http://www.sonicspot.com/guide/wavefiles.html"]look here[/url]), which makes the following

[quote]If the IMA data is monaural, an individual chunk of data begins with the following preamble:
bytes 0-1: initial predictor (in little-endian format)
byte 2: initial index
byte 3: unknown, usually 0 and is probably reserved
[/quote]

make no sense to me, at least if they are referring to the header+data-[i]chunks[/i]. But I would think they're actually referring to the blocks - on the other hand I heard/read/can't remember somewhere that IMA ADPCM cannot be decompressed per-block which would contradict each block having a header, that could've been in a dream though.. CONFUSED [img]http://public.gamedev.net//public/style_emoticons/default/blink.png[/img] !

Edit: Uh, I'm running so many parallell possible solutions to this little problem - I'll go back to the one I was working on when posting the images above and apply my new knowledge. This thread can be put on ice for now.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0