Page 1 of 1
Simple sound engine crashes
Posted: Fri Nov 11, 2011 4:37 am
by Dren
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.
Re: Simple sound engine crashes
Posted: Fri Nov 11, 2011 12:25 pm
by WinterMute
Can we see the code you're using, it's difficult to say what the problem might be otherwise.
Re: Simple sound engine crashes
Posted: Fri Nov 11, 2011 9:50 pm
by Dren
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.
Re: Simple sound engine crashes
Posted: Sat Nov 12, 2011 12:19 am
by mtheall
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;
}
Re: Simple sound engine crashes
Posted: Sat Nov 12, 2011 2:02 pm
by Dren
Ah, so it was irqInit()! I must've been reading an obsolete resource. It works fine now. Thanks!
Re: Simple sound engine crashes
Posted: Mon Nov 14, 2011 2:54 am
by mtheall
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.