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 > Possible PSG bug in libnds and other audio questions...

#167077 - Rotsiser_Mho - Sat Feb 28, 2009 8:25 am

Hi all,

I'm brand new to DS development, so if my problem here is stupid, I apologize in advance.

I created a very tiny program to mess around with the PSG sound channels. Unfortunately, it seems that no matter what I set the duty cycle to, it all sounds the same. I've checked out the PSG capabilities in AXE so I know I can hear the difference, but that code seems a bit out of date (I'm assuming the hip new thing is to not write custom ARM7 code?).

In any case, here is how I have my code set up currently. It's horrible, but I don't think I'm doing anything wrong. If so, libnds is not correctly passing the duty cycle parameter on to the appropriate sound register. Any thoughts?

Also, what would be the most efficient way to get a close approximation of the NES triangle wave? Can the PSG come reasonably close?
Thanks!

Code:

soundEnable();
mySound1 = soundPlayPSG(DutyCycle_12, 2094,5, 64);
mySound2 = soundPlayPSG(DutyCycle_87, 2094,5, 64);
while(1)  {
   scanKeys();
   touchRead(&touch);
   if(keysHeld() & KEY_TOUCH) {
   if (touch.rawy < 2000) {
      if (touch.rawx <= 760)
         soundSetFreq(mySound1, 1047 * 2);
      if ((touch.rawx > 760) && (touch.rawx <= 1235))
         soundSetFreq(mySound1, 1175 * 2);
      if ((touch.rawx > 1235) && (touch.rawx <= 1675))
         soundSetFreq(mySound1, 1319 * 2);
      if ((touch.rawx > 1675) && (touch.rawx <= 2130))
         soundSetFreq(mySound1, 1397 * 2);
      if ((touch.rawx > 2130) && (touch.rawx <= 2570))
         soundSetFreq(mySound1, 1568 * 2);
      if ((touch.rawx > 2570) && (touch.rawx <= 3010))
         soundSetFreq(mySound1, 1760 * 2);
      if ((touch.rawx > 3010) && (touch.rawx <= 3480))
         soundSetFreq(mySound1, 1976 * 2);
      if (touch.rawx > 3480)
         soundSetFreq(mySound1, 2093 * 2);
      soundResume(mySound1);
      soundPause(mySound2);
      }
   else {
      if (touch.rawx <= 760)
         soundSetFreq(mySound2, 1047 * 2);
      if ((touch.rawx > 760) && (touch.rawx <= 1235))
         soundSetFreq(mySound2, 1175 * 2);
      if ((touch.rawx > 1235) && (touch.rawx <= 1675))
         soundSetFreq(mySound2, 1319 * 2);
      if ((touch.rawx > 1675) && (touch.rawx <= 2130))
         soundSetFreq(mySound2, 1397 * 2);
      if ((touch.rawx > 2130) && (touch.rawx <= 2570))
         soundSetFreq(mySound2, 1568 * 2);
      if ((touch.rawx > 2570) && (touch.rawx <= 3010))
         soundSetFreq(mySound2, 1760 * 2);
      if ((touch.rawx > 3010) && (touch.rawx <= 3480))
         soundSetFreq(mySound2, 1976 * 2);
      if (touch.rawx > 3480)
         soundSetFreq(mySound2, 2093 * 2);
      soundResume(mySound2);
      soundPause(mySound1);
      }
   }
else {
      soundPause(mySound1);
      soundPause(mySound2);
   }
   swiWaitForVBlank();
}

#167078 - Dwedit - Sat Feb 28, 2009 10:08 am

A NES triangle wave is a 32 byte looping waveform, consisting of 15 steps going up and down. Just use the DS's normal sound channels for that.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."