soundSetVolume() bug?
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;
}
}