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 > Exact clock rate of the bus ?

#102034 - raphzore - Sun Sep 10, 2006 12:43 am

Hello,

To calculate timer's value accuratly, we need to know the base clock rate of the nds (so it's bus clock rate I suppose).

The matter is that in the nocash doc (http://nocash.emubase.de/gbatek.htm#dsinterrupts) it's said that bus clock is at 1FF61FEh Hz and in neimod's one (http://neimod.com/dstek/) it's 2000000h Hz.

In libnds 2000000 Hz value is used for the TIMER_FREQ macro, but who is right ?

I know that it could sound as a weird question, because 2000000 and 1FF61FE are really close values, but I would need as much accuracy as I could have.

Thanks (and sorry for my english if I've done some mistakes) :).

#102036 - Sausage Boy - Sun Sep 10, 2006 1:14 am

I would personally trust gbatek over dstek, generally. It does seem like gbatek has the exact value and dstek has it rounded off, but I really don't know anything about this stuff.
_________________
"no offense, but this is the gayest game ever"

#102038 - tepples - Sun Sep 10, 2006 2:30 am

That's an 0.12 percent difference, which is within tolerance for variation in clock speed from unit to unit. The CPU clock in a handheld doesn't need to be extremely accurate because players of single-player game often can't tell the difference in rates from one unit to the next. Multiplayer games have to correct for the fact that systems in a network may gain or lose a frame's worth of cycles (280896 on the GBA or 560190 on the DS) every few minutes.

What do you need such a highly accurate time base for anyway, so that we can suggest other ways of going about what you ultimately want to do?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#102039 - raphzore - Sun Sep 10, 2006 3:23 am

It was only audio related, to base my calculation (for finding good multiple of some frequencies) on the good value.

Because I would like to avoid detuning without resampling.

But I'm only at the beginning of the whole thing, I'm looking for some ways to make the sound streaming as light as possible.

The ds has a quite nice sound hardware mixer :) !

#102044 - tepples - Sun Sep 10, 2006 4:37 am

The Nintendo DS DAC uses pulse-width modulation. It is a 10-bit DAC, and a 10-bit PWM DAC has 1024 steps in its sequence. So no matter the CPU frequency, the 10-bit PWM DAC runs once every 1024 ARM7 CPU cycles. If the CPU frequency is 0x02000000 Hz = 33554432 Hz, the DAC runs at 32768 Hz. If the CPU frequency is 0x01FF61FE = 33513982 Hz, the DAC runs at 32728.5 Hz. Unless you're trying to use two systems to generate quadraphonic audio, you can just pretend that all the CPUs run at 0x02000000 Hz for program simplicity.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#102060 - raphzore - Sun Sep 10, 2006 11:53 am

Thanks for this infos ans explanations :) !

So in the hardware how the "re-sampling" work ? If I read a 22050 Hz sound data on channel 1, the channel will take 1 word every 4/22050 sec (I think).

So to be able to play this without affecting the sound's pitch, the dac needs to have 32768 value / sec to read, and this values need to be "re-sampled" from the 22050 Hz channel.

Am I going wrong ?

If not, how is this process done ?

I know it's not really the original subject of the topic, but you seem to have a really good knowledge about it :) !

#102073 - tepples - Sun Sep 10, 2006 4:06 pm

Resampling audio is a bit like stretching an image to a different size. Do you know how rotation and extended rotation backgrounds work?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#102077 - raphzore - Sun Sep 10, 2006 4:53 pm

In fact I know how resampling works, so for the image streching (1D->2D).

But I was wondering how the ds do it (because there is several ways, in term of quality). Simple "stretching" ? linear filtering ? more complexe filtering ?

Is it virtually CPU free (so not using the ALU that are used when doing ours calculations) ? Or if not, when using 16 channels, the arm7 would be a little busy no ?

Don't hesitate to say me if I'm totaly wrong in anything, I'm not really sure of my knowledge ^^.

About rotation I don't know anything about it, in which way is it linked to this problem ?

Anyway, thanks again for spending time answering me, I appreciate it :).

You are involved in the DevKitPro developpement ?

#102080 - tepples - Sun Sep 10, 2006 5:45 pm

The nearest-neighbor resampling performed by the hardware doesn't take any CPU time. But for something of higher quality, such as cubic interpolation, you're going to need to spend a bit of time in your ARM7 program.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#102081 - raphzore - Sun Sep 10, 2006 5:55 pm

Great, thanks a lot :) !

#102120 - raphzore - Mon Sep 11, 2006 12:38 am

In fact I came up with another question ^^.

Are the sound DMA of the DS still reading 4 words (16 bytes) at a time, like the general purpose DMA of the GBA ?