Simple sound engine crashes

Post Reply
Dren
Posts: 11
Joined: Wed Mar 16, 2011 10:12 pm

Simple sound engine crashes

Post by Dren » Fri Nov 11, 2011 4:37 am

Hi, I'm attempting to port a gameboy emulator to the ds. I'm unable to play any kind of sound with libnds's sound.h. I call soundEnable() at the beginning of my code, presumably this powers on the sound hardware? As I attempt to call a function such as soundPlayPSG and soundPlayNoise, the ds crashes immediately. I'm unsure exactly how it's supposed to work, but calling soundSetFreq, soundSetVol, etc doesn't crash, but doesn't produce any sound either. It's said that the functions should work from the arm9 side, so I shouldn't have to make an arm7.cpp? Thanks in advance for any help.

WinterMute
Site Admin
Posts: 2003
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: Simple sound engine crashes

Post by WinterMute » Fri Nov 11, 2011 12:25 pm

Can we see the code you're using, it's difficult to say what the problem might be otherwise.
Help keep devkitPro toolchains free, Donate today

Personal Blog

Dren
Posts: 11
Joined: Wed Mar 16, 2011 10:12 pm

Re: Simple sound engine crashes

Post by Dren » Fri Nov 11, 2011 9:50 pm

There isn't much I haven't said.

Code: Select all

int main(void)
{
	irqInit();
	irqEnable(IRQ_VBLANK);

	consoleDemoInit();
	consoleDebugInit(DebugDevice_CONSOLE);

	soundEnable();
	while (true)
	{
		soundPlayPSG(DutyCycle_50, 500, 100, 64);
		// Crashes here
		printf("This command is never executed.\n");

		swiWaitForVBlank();
	}
	return 0;
}
It leaves me with simply a white top screen and black bottom screen.

mtheall
Posts: 211
Joined: Thu Feb 03, 2011 10:47 pm

Re: Simple sound engine crashes

Post by mtheall » Sat Nov 12, 2011 12:19 am

From the documentation it appears that you are only supposed to call this function once. You can use its return value to pause, resume, kill, etc. The interrupt handlers have already been initialised when you reach main, calling irqInit again will remove the fifo handlers and crash when you attempt to use functions that communicate with the arm7.

Your code should look like this:

Code: Select all

int main(void)
{
   consoleDemoInit();
   consoleDebugInit(DebugDevice_CONSOLE);

   soundEnable();
   soundPlayPSG(DutyCycle_50, 500, 100, 64);
   while (true)
   {
      printf("This command is never executed.\n");
      // you don't know this never executed. it could have just not been flushed to vram yet
      swiWaitForVBlank();
   }
   return 0;
}

Dren
Posts: 11
Joined: Wed Mar 16, 2011 10:12 pm

Re: Simple sound engine crashes

Post by Dren » Sat Nov 12, 2011 2:02 pm

Ah, so it was irqInit()! I must've been reading an obsolete resource. It works fine now. Thanks!

mtheall
Posts: 211
Joined: Thu Feb 03, 2011 10:47 pm

Re: Simple sound engine crashes

Post by mtheall » Mon Nov 14, 2011 2:54 am

Oh yeah I guess I accidentally didn't copy that part from your code. I believe irqInit() is automatically called before main() now, among other things. If you are worried about reading outdated tutorials, you should take a look at the NDS examples that are optional to install during the devkitPro Updater. They are actually more up-to-date than any guide I've ever seen for this stuff.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest