> I had in fact rounded off a lot, and it seemed to help a bit correcting it
Yeah... rounding off will throw the notes off tune when you get at higher frequencies. Especially true at lower sample rates.
> The triangle channel is still off key, though, it's probably a +-1 error in one
> of the counters
I hear it in both samples you uploaded... it also sounds like your linear counter still needs a little more work (the notes are playing too long on the tri channel in Duck Tales... and there are a few weird notes in SMB2 that seem out of place, but I could be imagining it).
Don't have any ideas on this one... I would say just review you triangle code... maybe there's a typo somewhere that's causing this odd behavior.
Your tri channel should be making another step in it's tri-step generator every 'freq+1' cycles.. also, there should be 32 steps for the complete wave (make sure you're going D,E,F,F,E,D instead of D,E,F,E,D... that could throw the tri off tune.. and also 2,1,0,0,1,2 instead of 2,1,0,1,2). If you're doing both of those the pitch should be right on.
> About the envelope decay stuff: Is it true, as the doc says, that the volume
> should _always_ be decremented by one, regardless of whether the decay is
> enabled or not?
Ah... from what I can tell the doc is accurate.. but the evelope/decay hardware does -not- change the volume level at all. There's actually an internal value aside from the volume... I think the doc refers to it as the envelope/decay counter, but it's been a while. This counter (not the volume) is decreased on decay clocks even if decay is enabled. It keeps counting down until it hits zero (in which case it stops counting.... or loops back to F if decay looping is on). The only register write that directly changes this value is a write to the 4th register of the channel (4003->Square 1, 4007->Square 2, 400F->Noise) which sets the value to F.
If decay is enabled, the volume level is IGNORED, and this internal counter is the output volume.
Otherwise, the internal counter is ignored, and the volume is output as normal.