#122900 - FRuMMaGe - Fri Mar 23, 2007 11:45 am
I have searched around and I can find lots of tutorials for playing sound, but none for playing music. What code do I use to start/stop a music track?
#122905 - OOPMan - Fri Mar 23, 2007 12:57 pm
Sound and music are actually the same thing.
Music is just a long sequenc of sounds...
Hence, playing music involves playing sound...
Hence, you want to stream the music, piece by piece into a buffer and play the sound data stored in that buffer...
_________________
"My boot, your face..." - Attributed to OOPMan, Emperor of Eroticon VI
You can find my NDS homebrew projects here...
#122912 - FRuMMaGe - Fri Mar 23, 2007 1:47 pm
OOPMan wrote: |
Sound and music are actually the same thing.
Music is just a long sequenc of sounds...
Hence, playing music involves playing sound...
Hence, you want to stream the music, piece by piece into a buffer and play the sound data stored in that buffer... |
But any music track stored in raw format is enourmous. There must be a way of playing in-game music without increasing the file size by 500%
#122913 - kusma - Fri Mar 23, 2007 1:54 pm
FRuMMaGe wrote: |
But any music track stored in raw format is enourmous. There must be a way of playing in-game music without increasing the file size by 500% |
If size is a concern, then you might want to look into either some kind of compression (ogg, mp3, adpcm, gsm etc) or tracked music (mod, xm, it, s3m etc).
#122914 - FRuMMaGe - Fri Mar 23, 2007 2:00 pm
Does the DS read mp3 files natively? If not, does it read any music files without the need for complicated code, such as midi.
#122916 - kusma - Fri Mar 23, 2007 2:09 pm
The only compressed audio format the DS can play natively is ADPCM. If I'm not mistaken, the ADPCM variant that the DS supports is the IMA-ADPCM variant - the most common ADPCM codec out there (supported by sox among others). IMA-ADPCM is 4 bit per sample, so it gives a 4:1 compression rate compared to 16bit PCM data at the cost of some noise in silent parts of the soundtrack (this can be worked around by having a noisy soundtrack).
If you want something more than that, it's going to cost CPU-cycles, and you'll need a decoder. There are luckily already people who has gone through the process of writing decoders, and some of them are even fast enough to use.
#122917 - FRuMMaGe - Fri Mar 23, 2007 2:16 pm
So how do I play these files? The same way I play raw?
#122918 - kusma - Fri Mar 23, 2007 2:18 pm
FRuMMaGe wrote: |
So how do I play these files? The same way I play raw? |
More or less, you just need to pick the ima-adpcm format instead of pcm8 or pcm16. Check out http://nocash.emubase.de/gbatek.htm#dssound for more info.
#122919 - tepples - Fri Mar 23, 2007 2:18 pm
Do you know what a "ring buffer" is, and why you would use one for audio?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.