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.

DS development > Correct settings for RAW sound

#130631 - tondopie - Tue Jun 05, 2007 10:48 pm

WHat are the corrct settings for the RAW files used in NDS sound?
I need to know Channels(Mono, Stereo?) Sample Rate and encoder.
_________________
Development Blog: http://teendev.org
Homebrew Podcast: http://homebrewcast.net
Web Design: http://xtendesign.net

#130639 - DragonMinded - Wed Jun 06, 2007 1:07 am

That depends on the raw sample you use...
_________________
Enter the mind of the dragon.

http://dragonminded.blogspot.com

Seriously guys, how hard is it to simply TRY something yourself?

#130640 - tondopie - Wed Jun 06, 2007 1:46 am

i guess I will just have to try stuff ou myself then...
_________________
Development Blog: http://teendev.org
Homebrew Podcast: http://homebrewcast.net
Web Design: http://xtendesign.net

#130645 - tepples - Wed Jun 06, 2007 3:15 am

  • Channels: 1
  • Sample rate: any, up to 32768 Hz
  • Formats: 8-bit signed with no header, 16-bit signed with no header, IMA ADPCM with a header as described in GBATEK

_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#130647 - tondopie - Wed Jun 06, 2007 3:38 am

thanks, it works!
_________________
Development Blog: http://teendev.org
Homebrew Podcast: http://homebrewcast.net
Web Design: http://xtendesign.net

#130685 - NeX - Wed Jun 06, 2007 5:14 pm

I use 44100hz 16-bit samples with 1 channel.

#130688 - Dood77 - Wed Jun 06, 2007 6:02 pm

tepples wrote:
up to 32768 Hz

NeX wrote:
I use 44100hz

Overkill? :-/
_________________
If I use a term wrong or something then feel free to correct, I?m not much of a programmer.

Original DS Phat obtained on day of release + flashme v7
Supercard: miniSD, Kingston 1GB, Kingston 2GB
Ralink chipset PCI NIC

#130707 - tepples - Wed Jun 06, 2007 10:04 pm

Any sound played through the DS sound hardware at a frequency other than 32768 Hz will be resampled to 32768 Hz with nearest-neighbor algorithm.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#130714 - NeX - Wed Jun 06, 2007 11:26 pm

Oh, well. It sounds pretty good anyway.

#130719 - Dood77 - Thu Jun 07, 2007 12:51 am

tepples wrote:
Any sound played through the DS sound hardware at a frequency other than 32768 Hz will be resampled to 32768 Hz with nearest-neighbor algorithm.

Does this cost cycles?
_________________
If I use a term wrong or something then feel free to correct, I?m not much of a programmer.

Original DS Phat obtained on day of release + flashme v7
Supercard: miniSD, Kingston 1GB, Kingston 2GB
Ralink chipset PCI NIC

#130911 - tepples - Sat Jun 09, 2007 5:13 am

Fetching samples from RAM always costs cycles. It has since the NES. A higher sample rate means the hardware must perform more fetches per second.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#131189 - norfair - Tue Jun 12, 2007 2:23 am

I'm wondering what buffer size I should use if I want to time buffer swapping on the vblank. For a 32768Hz rate, with 16 bit signed samples, how big should the buffer be?

#131191 - tepples - Tue Jun 12, 2007 2:47 am

Vblank triggered buffer swapping is not recommended on Nintendo DS because 2*3*5*71*263 = 560190 cycles per frame isn't exactly a nice round number. It's better to use a timer. The opening theme of Animal Crossing Wild World appears to use segments of roughly 1 kilosample.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#131199 - DekuTree64 - Tue Jun 12, 2007 4:11 am

DS has hardware looping though, so you don't need to use timer interrupts to restart the DMA like you did on GBA if you didn't synchronize with VBlank. Just cascade a couple of timers together (with the low timer running at the same rate as the sound channel) and read the value of the upper timer each VBlank to keep track of how many samples have been played.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#131201 - norfair - Tue Jun 12, 2007 4:20 am

Thank you for the replies!

Deku, I was in fact trying to extend the theory in your GBA sound tutorial to the DS. Thanks for the clarification :)

#131244 - tepples - Tue Jun 12, 2007 11:32 pm

DekuTree64 wrote:
DS has hardware looping though, so you don't need to use timer interrupts to restart the DMA like you did on GBA if you didn't synchronize with VBlank.

But how well does this hardware looping work with an ADPCM stream?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#131254 - DekuTree64 - Wed Jun 13, 2007 1:36 am

tepples wrote:
DekuTree64 wrote:
DS has hardware looping though, so you don't need to use timer interrupts to restart the DMA like you did on GBA if you didn't synchronize with VBlank.

But how well does this hardware looping work with an ADPCM stream?

Not very well. The hardware looping saves the state of the decoder when it hits the loop point, and then restores it on each repetition. And you can't read back the decoder state either, so you can't even restart the channel with a timer interrupt when the buffer wraps.

One way I can think of to do it is to encode your data in frames that each start with the decoder in the same state. Then make your ring buffer equal to the frame size (plus 4 bytes for the initial ADPCM header), and stream data into it during VBlank with the sample counter method I mentioned before.

You might need to do a bit of extra processing on the data before encoding, to make sure there are no pops at frame boundaries (i.e. if your chosen frame start state has the sample value at 0, and the previous frame ended with 32000, then you'd get a loud pop). One trick you can use for that sort of thing is to look ahead and behind the frame boundary for a sample value that's close enough to 0, and then insert/remove single samples at random locations to line it up.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#131255 - tepples - Wed Jun 13, 2007 3:50 am

In that case, it might just be easier to decode the ADPCM in software.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.