soundSetVolume() bug?

Post Reply
Camden Flannagan
Posts: 1
Joined: Thu Feb 01, 2024 6:02 pm

soundSetVolume() bug?

Post by Camden Flannagan » Sat Feb 03, 2024 11:10 pm

Hello. I'm trying to program a synthesizer for my DS, and have been using the PSG to practice implementing audio envelopes before I move on to using samples. Unfortunately, my program has been crashing, and although I believe I've narrowed down the problem to soundSetVolume(), I have no idea what is wrong, or how to fix it. Here is an excerpt of my code (I'll also attach the full file and a .txt describing the context of the crashes in detail)

Code: Select all

pianoScanKeys();
down.VAL = pianoKeysDown();
held.VAL = pianoKeysHeld();
up.VAL = pianoKeysUp();

// this loops through the sounds array and the PianoKeys bitfields to detect key presses, play sounds,
// change sound volume, and kill sounds.
int bitfieldShift;
for (int i = 0; i < 13; i++) {
	bitfieldShift = i + ((i >= 11) ? 2 : 0); // because of the gap in the PianoKeys bitfield, skip 11 and 12
	// if the key was just pressed, start the sound
	if (down.VAL & 1<<bitfieldShift)
		sounds[i].sid = soundPlayPSG( // the sounds array holds some information about the sounds of each key
			DutyCycle_25,
			pitches[pitch + (12 * octave) + i],
			startVolume,
			64
		);
	// if the key is being held, change the volume of the sound according to the envelope
	else if (held.VAL & 1<<bitfieldShift)
		soundSetVolume( // <-- PROBLEM HERE
			sounds[i].sid,
			attackDecaySustain(sounds[i].time++) // <-- I've tried replacing this with a constant, but crashes still occured
		);			
	// if the key was just released kill the sound.
	else if (up.VAL & 1<<bitfieldShift) {
		sounds[i].time = 0; // set time back to zero to reset the envelope
		soundKill(sounds[i].sid);
		sounds[i].sid = 0;
	}
}
Attachments
main.c
The full code
(8.12 KiB) Downloaded 37 times
crash info.txt
file containing a more detailed crash report
(664 Bytes) Downloaded 35 times

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

Re: soundSetVolume() bug?

Post by WinterMute » Mon Oct 21, 2024 11:49 am

Apologies for taking so long to reply to this.

Unfortunately there isn't really enough code here to look at this properly. There are a number of structs and arrays missing which means we can't compile this code.

From a brief glance I suspect that probably what's happening is that you're filling the fifo queue by calling soundSetVolume faster than the arm7 can handle. Generally we would advise calling pianoScanKeys no more than once per frame which may help - just add a swiWaitForVBlank in your main loop where you have pianoScanKeys.

We have some libnds updates in the pipeline which include updates to the 7<->9 communication layer which may help. Stay tuned.

Help keep devkitPro toolchains free, Donate today

Personal Blog

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests