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 > Sound panning adjustment

#144747 - polloymedio - Tue Nov 06, 2007 4:36 pm

hey all! well, i was trying to program a panning function for the ARM7 , but for some reason, it isnt going as well as i thought it would... anyways, here's the function

Code:
static void snd_SetChannelPan(u8 channel, u8 pan)
{
   if (channel < SND_MAX_CHANNELS){
      if (pan > 127) pan = 127;
      SCHANNEL_CR(channel) = SOUND_PAN(pan);
      //SCHANNEL_PAN(channel) = pan;
   }
}


I also tried modificating the SCHANNEL_PAN(channel) directly, but no results... btw, im using these macros

Code:
#define SOUND_PAN(n)         ((n) << 16)

//---------------------------------------------------------------------------------
// registers
//---------------------------------------------------------------------------------
#define SCHANNEL_CR(n)            (*(vuint32*)(0x04000400 + ((n)<<4)))
#define SCHANNEL_PAN(n)            (*(vuint8*)(0x04000402 + ((n)<<4)))


any ideas? I really don't think there's something wrong with the function, I made a similar function for volume control and it did work. (Difference is i used SCHANNEL_VOL(channel) = volume instead.)

Thanx in advance!

#144756 - ingramb - Tue Nov 06, 2007 7:36 pm

The SCHANNEL_CR register has bits to control lots of things besides just the pan (like volume, channel enable, etc.).

When you do "SCHANNEL_CR(channel) = SOUND_PAN(pan)", you're setting everything else in the register to 0, which turns off the channel.

If you do this, you'll preserve the old values:
Code:

u32 value = SCHANNEL_CR(channel) & ~(7 << 16);
SCHANNEL_CR(channel) = value | SOUND_PAN(pan);


The first line grabs the existing value of the register, and masks off the 7 bits that make up the pan field. The second line writes combines the exiting value with the new pan value.

#144758 - polloymedio - Tue Nov 06, 2007 8:06 pm

Thanks for the reply! I also saw about 3 days ago the same problem with the SCHANNEL_CR(channel) = SOUND_PAN(pan); and i did try doing this SCHANNEL_CR(channel) |= SOUND_PAN(pan);
nevertheless same results.. I tried your solution too, but it doesnt work for me... hmmm... maybe im calling the procedure in the wrong place? I call it at the end of the PA_IPCManage function for tests. Also, im calling from the ARM9
Code:

if (Pad.Newpress.A) {
   PA_Print(0, "-");
   PA_PlaySimpleSound(1, saberoff);
}


in the main game loop...

#144761 - ingramb - Tue Nov 06, 2007 8:18 pm

Sound registers can only be changed on the arm7.

#144764 - polloymedio - Tue Nov 06, 2007 8:30 pm

yea i know that... I am calling to play a sound in the ARM9, and from the arm7 in the PA_IPCManage function, im calling my pan function for test reasons... Thanks for the quick reply though! :)