gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Audio > Need a little help - Not sure if this belongs here though.

#15352 - ramirez - Wed Jan 21, 2004 8:50 am

Well, I am becoming more interested about audio programmg, and I thought about buying a book about it, and what I want is a recommendation for a good book.
I'd like to have a book that covers the information needed for writing your own mixers (the sample handling etc.)
I'd also like to notice that I am a beginner when it comes to audio programming, so I don't want a book that is meant for hardcore audio programmers, if you get my point. :)
If the book covers theory and the things needed for programming the stuff, that'd be great.
Thanks.

#15390 - animension - Wed Jan 21, 2004 9:27 pm

While this isn't a book, it's an article I found useful:

http://www.gamedev.net/reference/articles/article1823.asp

Hope it helps.
_________________
"Beer is proof that God loves us and wants us to be happy."
-- Benjamin Franklin

#15394 - ramirez - Wed Jan 21, 2004 10:33 pm

animension wrote:
While this isn't a book, it's an article I found useful:

http://www.gamedev.net/reference/articles/article1823.asp

Hope it helps.

I've read this ages ago, but thanks anyway.
I do know about the sound hardware of GBA, but what I need to read more about is writing the actual mixers, i.e. what kind of concepts does it involve etc.
The article you pointed out only explains about the sound hardware and how to play the samples. The other 2 parts of that article serie was supposed to explain how to write a multichannel mixer, but unfortunately they were never released. :(

#15395 - gb_feedback - Wed Jan 21, 2004 11:00 pm

ramirez: I think it would be worth your looking at tepples' excellent Tetanus On Drugs. If I recall correctly there is the source of a capable mixer there. It is unsullied by sordid* asm so it is easy to follow. He uses the '2 mixer buffers - fill one while playing the other' method, with 304 bytes per buffer which last exactly one frame at 18xxx Hz (sorry I've forgotten).

I expect there's a link at the bottom of one of tepples' postings.

Once you've got your head round the basic concept you'll be glad you didn't waste money on books, and you can adapt the principle to more suit your own application.


* satire - please don't flame
_________________
http://www.bookreader.co.uk/

#15397 - animension - Thu Jan 22, 2004 12:15 am

Ramirez:

Mixing multiple channels of audio as an abstract concept involves 4 steps:

1) Read sample from each channel compensating for differences in the the audio sample's frequency to the mixing frequency (eg, if you are mixing at 16KHz and sampling a 22KHz audio file, you need to skip a few samples of the wave data otherwise the sample will playback at a slower rate than originally digitized. Mixing at a higher frequency than the audio was originally digitized requires some sort of interpolation -- creating new samples where they didn't exist in the original file).
2) Add the values of these samples together
3) Decide what to do if the total value of all samples from each channel goes above the maximum value; viz, if you add the values of the samples from several channels and their totals go above +127 (max signed 8-bit value), you want to do something so it doesn't go above 127, either by clipping the total down to 127 or scaling it by taking the total and averaging based on the number of samples mixed.
4) Add the mixed sample to the inactive buffer and repeat from step 1 for as many samples as you want to mix at once.

That's all there is to it, really. Other things like volume adjusting and panning entail scaling the audio's sample to a ratio prior to that channel's sample being added to the total of all channels' samples.

Most audio processing theory can be learned from general digital signal processing books. However, a lot of these books contain a heavy amount of mathematics, so if you are new to DSP and want to avoid being innundated by lengthy mathematical proofs, etc, I suggest a book that doesn't delve so deep in math but focuses on explaining the how's and why's of DSP. I recall seeing several books on Amazon's website that are along these lines, but as I don't have time to find them and link to them, you'll have to search there.

Hope this helps.
_________________
"Beer is proof that God loves us and wants us to be happy."
-- Benjamin Franklin

#15400 - tepples - Thu Jan 22, 2004 2:39 am

gb_feedback wrote:
ramirez: I think it would be worth your looking at tepples' excellent Tetanus On Drugs. If I recall correctly there is the source of a capable mixer there.

Yup. The Tri Engine mixer is mono and a little slow (compared to, say, AAS's), but it's nice to learn from, and it's extensible: if you have some sort of other 16-bit audio stream, such as one produced by decompression of an 8ad stream, the mixer can mix on top of that. The Tri Engine also has the beginning of a music engine that can play through both the mixer and the GBC tone generators. It plays files written in my own form of textual notation; I haven't yet written converters from more popular formats. I welcome contributions.

Quote:
He uses the '2 mixer buffers - fill one while playing the other' method, with 304 bytes per buffer which last exactly one frame at 18xxx Hz (sorry I've forgotten).

A Vblank switched audio buffer will run at 16777216/280896 times the buffer length, in this case 18157 Hz. The sound engine's source code contains instructions to reconfigure it for any other Vblank-friendly playback rate.

Quote:
I expect there's a link at the bottom of one of tepples' postings.

TOD M3, available for download here, contains the Tri Engine.

Quote:
Once you've got your head round the basic concept you'll be glad you didn't waste money on books

True, although you might want to have some sort of digital signal processing book next to you to help you with the theory. I found Elements of Computer Music by F. Richard Moore (ISBN: 0132525526) rather informative without involving heavy formulae every step of the way.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#15410 - ramirez - Thu Jan 22, 2004 6:56 am

Ok, thanks.
I downloaded the game with source, didn't take a look at the source yet, but I must admit that game truly is amazing.
Thanks a lot.

EDIT. In what mode that was coded in?