APU: triangle frequency over $7E0

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
APU: triangle frequency over $7E0
by on (#30967)
Summer Carnival '92 Recca often writes values of over $7E0 to the triangle frequency registers, it's safe to say that these frequencies are too low to be audible, so I presume it does this to shut off the triangle wave (similar to Megaman 2 writing a very short frequency to one of the squarewaves at the titlescreen).

On emulators though, you're able to hear to hear the single steps of the triangle waveform as an annoying highpitched noise in the background of every Recca song, unless you ignore writes >$7E0. Am I doing the right thing by ignoring these writes or does it sound the same on the NES?

by on (#30968)
I see no reason why it should be silenced for low frequencies. Even on the lowest frequency of $7ff, the wave should be audibile (above 20 Hz) if I'm not mistaking, that is arround a A-0 note, that is 4 octaves below the regular A-4 who is 440 Hz, that should be arround 27 Hz so it's a audible frequency. You'd need high quality loudspeakers to hear this, tough, so chances are that this isn't audible trough the average-sized speakers of an average TV.

It's well known that the highest frequencies are technically silented (as opposed to them oscillating too fast to be audible). In fact I remember the terribly inacurate NES emulator REW played some high sound in some game like early Capcom games that silences channel by writing period $0 but still have channel enabled with nonzero volume. This was rather annoying.

by on (#30970)
The thing is, on NES emulators a low frequency triangle wave basically gets converted to a low volume squarewave with a frequency 32 (or 16?) times higher of that of the triangle wave.

by on (#30971)
The triangle has 16 steps, both when the ramps goes up and down, I guess that make it 32 times higher, but the base frequency will still always be in the audible range.

by on (#30975)
Quote:
It's well known that the highest frequencies are technically silented (as opposed to them oscillating too fast to be audible).

Then it's a well-known myth. Here is a recording of the NES playing triangle waves of the noted periods:

Image

Note how the amplitude immediately jumps to the center when switching to periods 0 and 1, and how the phase is different when switching back to $FF than it was just before it was switched to 0 or 1, as it is when switching to periods 2 and 3.

The triangle wave plays at all periods, 0-$7FF. At the lowest two periods, the resulting frequency is above audible so it basically outputs a value between 7 and 8 on the DAC. This is different than not running, due to the DAC level and the fact that the phase will be constantly changing. Emulators with insufficient low-pass filtering to remove frequencies above the Nyquist limit would probably render these as awful sounds, causing one to erroneously conclude that the wave doesn't run at these periods if one assumes that these emulators are accurate. Please don't make conclusions about NES hardware based on inaccurate emulators.

At the highest period, as Bregalad says, the fundamental is around 27 Hz, but the step nature of the wave means there is also something like a saw wave at 32x that frequency, 874 Hz, so it's never inaudible. This is a recording of the NES playing the triangle at highest period (27 Hz), followed by a saw wave at 874 Hz:

nes_tri_max_period.mp3

I remember the data sheet for the AY-8910 sound chip claiming that it could do sub-audible frequencies since the square wave channel could go lower than 20 Hz, totally missing the fact that a square wave has a ton of higher harmonics.

by on (#30976)
Thanks for correcting me. So the frequencies are cut-of by a highpass filter, but still technically runs. If that goes for triangle periods $0 and $1, I assume this remains true for square periods $0, $1, $2 and $3 (since the square wave outputs one octave higher for the same period).

Quote:
I remember the data sheet for the AY-8910 sound chip claiming that it could do sub-audible frequencies since the square wave channel could go lower than 20 Hz, totally missing the fact that a square wave has a ton of higher harmonics.

Yes, the base frequency won't be audible (exept for elephants) but the harmonics will.

by on (#30979)
Bregalad wrote:
Thanks for correcting me. So the frequencies are cut-of by a highpass filter, but still technically runs. If that goes for triangle periods $0 and $1, I assume this remains true for square periods $0, $1, $2 and $3 (since the square wave outputs one octave higher for the same period).

The square channels' frequency sweep units test for periods below 8 and disable the channel (forcing output to zero) if the condition is true. Thus, periods below 8 are never audible, not because they're out of audible range, but because the channel is physically stopped.

Of course, the MMC5's square channels don't have sweep units, so I suppose what you say may be valid there.

by on (#30980)
Quote:
Thus, periods below 8 are never audible, not because they're out of audible range, but because the channel is physically stopped.

Oh, and previously I just assumed it was the same for triangle channel. So this is only due to sweep, but is it always the case ? The sweep units disable periods above $3ff if sweep is down, but they let them go lower if the sweep it up, regardless if sweep actually occur. I always trough it is weird.

by on (#30981)
Thanks for the recording.
/me slaps Recca's audio programmer around a bit with a large trout

by on (#30987)
Yeah, I noticed this on recca LOOONG ago and I hacked the NSF I was using to silence it if 07FFh or whatever it was is being played. Another game that does this is solitare. It's super annoying since I can easily hear it on both when I play them on a TV using a real NES.

If you don't know it is there, you might not notice it at first, but once you know it's there, you will hear it ALL the time and it will be real annoying.

On my FPGA, I kill the triangle for values under 7FDh and for values over 002h. This can be turned off with "strict" emulation though. I just kill them 'cause games like megaman 2 will "silence" the triangle channel by forcing it to 00h or 001h (can't remember which).

This causes the triangle channel to pop and I found that highly annoying. Killing it for 000h or 001h prevents the popping and everyone's happy :-) On a real NES it pops of course because you are effecting a DC level change (as shown on the audio trace).

You can hear it the most on the "get equipped with..." drum track on MM2. When one of the triangle downsweep ends, listen for the POP. There's another when it starts, but it isn't so bad because the triangle is being turned on then.

by on (#30988)
- Is this related with Code Masters logo too?

by on (#30997)
kevtris wrote:
Yeah, I noticed this on recca LOOONG ago and I hacked the NSF I was using to silence it if 07FFh or whatever it was is being played. Another game that does this is solitare.

BPS's Tetris game does this at times too. You can especially hear it in "Technotris". In fact, the artifacts from early emulators and early NSF players while playing "Technotris" led me to misinterpret the way the ostinato was supposed to sound.

by on (#30998)
Fx3 wrote:
- Is this related with Code Masters logo too?

I've always wondered about that one...on a real console, and in modern emulators, it sounds like an electrical buzzing/crackling noise, but I swear some older emulators rendered it as a really low frequency hum (not sure if it was square or triangle).

by on (#31334)
By the way, if anyone has played the japanese Dragon Quest 3, you'll notice this triangle thing is REALLY noticeable in the main menu.