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 > DMA, Timers, Argh!

#49952 - wiz - Wed Aug 03, 2005 10:40 pm

Hello,

I'm following Deku's sound tutorial, which is really fantastic, but because I'm thick its taking a while for me to understand the first part (Timer and DMA)

For now there are 2 simple things I would like to clear up..

1) What *is* the _L and _H and _X representing on the reg defines? e.g. REG_SOUNDCNT_H (actually this is not a "sound" related question at all)

2) after a lot of messing and testing I have raw sound playing without any stopping in the code below:

I would like to know why its using DMA1, why not DMA2 - I havent set it up to use any... so whats all that about? whats telling it which to use? I dont like when things just work without knowing why or how. ;)

Code:

REG_SOUNDCNT_H = SOUNDA_TIMER1 | SOUNDA_VOLUME_100 | SOUNDA_LOUT | SOUNDA_ROUT | SOUNDA_FIFO_RESET;
REG_SOUNDCNT_X = SOUND_ENABLE;

REG_TM1D = 65536 - 800;
REG_TM1CNT = TIMER_ENABLE;

REG_DMA1SAD = (u32) (s8*)TestSndSample;
REG_DMA1DAD = (u32) &(REG_FIFO_A_H);
REG_DMA1CNT_H = DMA_DEST_FIXED | DMA_REPEAT | DMA_WORD | DMA_MODE_FIFO | DMA_ENABLE;


Thanks!!

p.s Deku if you read this, I think there is a small bug on page one.. on the line REG_TM0D = 65536 - (16777216 / soundFreq); <- I changed this to REG_TM1D for it to work.

#49953 - poslundc - Wed Aug 03, 2005 11:20 pm

wiz wrote:
1) What *is* the _L and _H and _X representing on the reg defines? e.g. REG_SOUNDCNT_H (actually this is not a "sound" related question at all)


_L and _H stand for Low and High, and represent the lower and upper 16-bits of a 32-bit register, respectively. I almost always just refer to the entire register without splitting it up into _L and _H within my code, and there are extremely few situations that actually require you to do so.

Quote:
I would like to know why its using DMA1, why not DMA2 - I havent set it up to use any... so whats all that about? whats telling it which to use? I dont like when things just work without knowing why or how. ;)


DMAs 1 and 2 are intended (but not required) to work with sound and have a special mode for doing so. Other than that, there's no difference between 1 and 2 other than that 1 will preempt 2 if the two should its trigger fire while 2 is running. You are given both so that you may use both at once for stereo sound.

Dan.

#49957 - wiz - Wed Aug 03, 2005 11:42 pm

Great thanks Poslundc, all makes sense, :)

but I'm still a little puzzled because if I change my code to read DMA2's instead of DMA1's it does not play the sound anymore?

I'm just missing something obvious ;)

#49958 - wiz - Wed Aug 03, 2005 11:49 pm

ahh,

is it because SOUNDB is linked to DMA2, and SOUNDA is linked to DMA1 ?

#58696 - SittingDuck - Tue Oct 25, 2005 1:24 pm

wiz wrote:
ahh,

is it because SOUNDB is linked to DMA2, and SOUNDA is linked to DMA1 ?


Yes. I have heard somewhere that they are 'hard-wired' that way.

#71377 - nmain - Sun Feb 12, 2006 6:53 am

poslundc wrote:


DMAs 1 and 2 are intended (but not required) to work with sound and have a special mode for doing so.


Just to clarify: You can use DMA 1&2 to do other things, but you can't use other DMA channels to fill the direct sound.

#72516 - SittingDuck - Sun Feb 19, 2006 11:43 am

Yes, I think so.