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 > GBA MOD player

#173881 - gelinlonlin - Thu May 06, 2010 11:45 am

I am do a GBA mod player now,and i have seen this:http://deku.gbadev.org/program.html
Now, i have a problem.In deku's code,there is a DMA3 using for sound.
I can not understand it.like i=0, for what?
IN sound.c:
s32 i, curChn;

// If you want to use a higher frequency than 18157,
// you'll need to make this bigger.
// To be safe, it would be best to set it to the buffer
// size of the highest frequency we allow in freqTable
s16 tempBuffer[304];

// zero as much of the buffer as we'll actually use,
// rounding samples up to nearest 2 for memset32
i = 0;
Dma3(tempBuffer, &i, (samplesToMix+1)*sizeof(s16)/4, DMA_MEMSET32);

thanks for explaining.

#173883 - Maximus32 - Thu May 06, 2010 12:00 pm

It's a fast (dma) version of memset, clearing the tempBuffer to 0. The only difference is this function does 32bit at a time, where memset does 8bit at a time.
_________________
Bricks-OS, Operating System for Game Consoles

#173885 - Ruben - Thu May 06, 2010 1:32 pm

Yeah, as was mentioned earlier, it's just a DMA-based memset32 to clear the mixing buffer. IMO, it'd probably be best to have the buffer in RAM rather than the stack and use CPU-based clearing rather than DMA to make sure there are no conflicts.

So something like...
Code:
//outside the function
static s16 MixingBuffer[304];

//in the function...
int i = (samplesToMix+1)*sizeof(s16) / sizeof(u32);
u32 *dst = (u32*)MixingBuffer;
do {
  *dst++ = 0;
} while(--i);

#173888 - Dwedit - Thu May 06, 2010 8:10 pm

I thought CPU-based memsets were faster than DMA on the GBA. Assuming of course you are using the stmia instruction with at least 8 registers.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#173897 - Ruben - Fri May 07, 2010 3:30 am

Yeah, I'm pretty sure it is faster as DMA would have to load from the source address for every write even if it's fixed source.