How do bypass the SNES audio low pass filter on the pcb?

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.
Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
93143
Posts: 1914
Joined: Fri Jul 04, 2014 9:31 pm

Re: How do bypass the SNES audio low pass filter on the pcb?

Post by 93143 »

Pokun wrote: Tue Dec 10, 2024 2:59 pmI see, so it's more a pushing the hardware to the limits more than the developers back in the day ever did kind of thing, in other words usual homebrew scene stuff.
Most commercial SNES games don't sound as crispy as a typical Mega Drive game, but not every instrument needs that much high-frequency energy, and there are nice-sounding titles that don't sound particularly muffled. One of the best examples is Energy Breaker, which illustrates the principle of selective optimization.

On the homebrew side, a number of tracks from Sonic games have been duplicated on SNES (sadly the video is now private), and they often sound virtually identical, even though I'm pretty sure they just use conventional techniques. There are things the Mega Drive can do that you'd have to get tricky to duplicate on SNES, but by no means all MD games actually did such things.
But is it possible to create crisper samples than normal just using BRRtools? I remember using it many years ago but I think it has been updated since then.
Yes, BRRTools has a feature that boosts the treble before conversion. Last I checked, it wasn't as accurate as my FIR, but it's way easier to use (and might result in less BRR distortion than my filter, but this has not been shown to be an important effect).
I'd like to port my NES sound driver to SNES someday, and for that I need samples and to understand how that Guassian interpolation and stuff works.
If I were you I'd go absolutely nuts on the samples. The NES can't make all that many different sounds, so generating samples at as many pitches as possible is probably the best way to get rich harmonics on the low tones without running into Nyquist folding on the high tones. I'd also try to come up with some way of dynamically switching samples as the pitch changes, so pitch bends can't break this scheme.

The SNES generates noise differently than the NES. Apparently, though, it's possible to approximate it without too much craziness.

You'll still need to leave room for the DPCM samples, but surely they won't take up all that much space in most cases... I suppose if you were willing to implement a streaming feature you could save some space that way, as well as supporting larger quantities of sampled sounds...

Or have I misinterpreted, and you just wanted to make SNES music without starting from scratch with the codebase?

93143 wrote: Mon Dec 09, 2024 8:40 pmAlso, technically anything running at 32 kHz is going to be more "muffled" than the FM synthesis coming out of the YM2612
...from what I'm reading, this may not be true. Apparently there was a substantial lowpass filter involved in the Mega Drive's audio output, and the difference between the Mega Drive and SNES may have been dwarfed by the differences between various models of Mega Drive. Does anyone know more?
User avatar
TmEE
Posts: 1074
Joined: Wed Feb 13, 2008 9:10 am
Location: Norway (50 and 60Hz compatible :P)

Re: How do bypass the SNES audio low pass filter on the pcb?

Post by TmEE »

Yes, the MD outputs vary dramatically between models. Some have the -3db point near 10kHz (most MD1s), some go well past (CDX/Multimega, MD2 VA3 and 4), some distort really badly (MD2 VA0 and VA1).

SNES appears to have consistent performance across models and what happens after the DAC doesn't influence sound very much, all the "damage" is already done in the digital side of things.
Pokun
Posts: 3442
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: How do bypass the SNES audio low pass filter on the pcb?

Post by Pokun »

I made sure to get the non-TMSS Japanese MD1 version (the one with the "Ⓡ" on the logo) partly because it's supposed to be one of the better models soundwise.

Some really late models also replaces the OPN2 (YM2612) with OPN2C (YM3438) which isn't fully compatible, and some games like After Burner II and Hellfire therefore has audio artifacts, yet another reason to get an older model for me.
However there are also some games like Earthworm Jim made for the OPN2C and will have artifacts on the older models, but I don't really like Earthworm Jim anyway (sour grapes).


93143 wrote: Wed Dec 11, 2024 12:48 am Or have I misinterpreted, and you just wanted to make SNES music without starting from scratch with the codebase?
I meant porting in a more loose definition of the word. Yes starting from scratch using the knowledge I've learned from coding a sound-driver/sequencer-engine on NES. I would use the NES version as a model and try to use mostly the same format on my data but extend it in order to support all the features of the S-APU. That would make it possible to use the same tools like MML for it.

It seems a bit different so I'm not sure how much has to be changed, and of course the SPC700 assembly might pose a challenge. I've already written a "light" version of my sound engine for Gameboy (this one mostly just takes sequence data bytes that are directly written to APU registers in a timely manner). My SM83 (GBZ80) skills are quite behind my 6502 skills so it was a bit of a challenge to write it without having any index registers to use but it worked fine once I learned the trick. Once it's finished I could probably port it quite easily to Sega 8-bit systems and MSX too.

As for samples it's a problem for NES too for DPCM. I have searched for a free set of GM1 samples that can be used but have been unable to find a full set. I remember someone posting GM drum samples ripped from a keyboard and converted to DPCM and another ripped from commercial NES games, but I'm not sure either would be fine to use in homebrew as I'm pretty sure they fall under copyright.
For simpler sound effects I could probably record my own, like smacking a soccer ball or bread dough to create a punch effect like sound effect studios do, but I don't have an attic full of all the musical instruments I'd like to use.
User avatar
Bregalad
Posts: 8181
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: How do bypass the SNES audio low pass filter on the pcb?

Post by Bregalad »

Pokun wrote: Tue Dec 10, 2024 2:59 pm Entering raw samples by hand and using the S-APU more like a traditional PSG is an interesting thing about it, though I guess it wouldn't sound very Snessy if using such simple waveforms. It might work well with my NES sound driver though.
For wavetable PSGs it's quite trivial to design normal square, triangle, sawtooth and even sinus waves just using hex values, but on the SNES it's not so straight forward.
For square/rectangle waves use filter 0 and data "9 9 9 9 9 9 9 9 (etc...) | 7 7 7 7 7 7 7 7 (etc...)" (the 9 are actually -7 written in signed 4-bit values)
For triangle waves use filter 1 with the same data and a smaller shift value.
For sine waves use filter 2 with the same data and an even smaller shift value.
I have never tried, but it sounds like if you wanted to port DPCM to the SNES you might try to use filter 1, and port every "0" bit to a BRR value of 7 and ever "1" value with a BRR value of 9.

Of course square/rectangle and triangle waves might benefit from treble boost prior to encoding, which will make the output BRR data look "complex".
Most commercial SNES games don't sound as crispy as a typical Mega Drive game, but not every instrument needs that much high-frequency energy
A strategy I'd find interesting is making sure the percussive samples (drums) are not compressed and decodes to fully 32 kHz samples. Melodic instruments being muffled isn't as much of an issue. Of course it also depends on the muscial style used by the game.
Useless, lumbering half-wits don't scare us.
Pokun
Posts: 3442
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: How do bypass the SNES audio low pass filter on the pcb?

Post by Pokun »

Aha thanks for that explanation. I think I've must have seen a treble boosted square wave before because I remember it didn't make any sense, it wasn't linear like a square wave normally is but rather skewed in a weird way that wasn't explained.

Can the treble boost thing be calculated by hand so that you won't have to turn it into a WAV and run it through BRR?
User avatar
Bregalad
Posts: 8181
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: How do bypass the SNES audio low pass filter on the pcb?

Post by Bregalad »

Good question.
You might attemps using filter 1, and data "7 0 0 0 0 0 0 (etc.) | 9 0 0 0 0 0 0 0 (etc.)", with the shift value to maximum (12), and see what's coming out of it. This should rather result in a low-cut filtered square wave than a treble-boosted square wave, though, but it might sound close enough.
Useless, lumbering half-wits don't scare us.
Pokun
Posts: 3442
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: How do bypass the SNES audio low pass filter on the pcb?

Post by Pokun »

I see thanks.

I guess I'll have to try out various things next time I feel like doing some SNES programming.
tepples
Posts: 22993
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)

Re: How do bypass the SNES audio low pass filter on the pcb?

Post by tepples »

You might be able to counter the by adding a treble boost to your square wave. This imitation of Gibbs overshoot will make Gaussian resampling sound more like OpenMPT "cubic" resampling.

weak: 7 6 6 6 ... 6 6 6 7 9 A A A ... A A A 9
strong: 7 5 5 5 ... 5 5 5 7 9 B B B ... B B B 9
Pokun
Posts: 3442
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: How do bypass the SNES audio low pass filter on the pcb?

Post by Pokun »

So how would I make for example a falling sawtooth using these methods for manual treble boost?

A visual diagram of the samples dotted out makes it much easier to me.
This is the raw sawtooth I'm trying to make before any treble boost is applied:

Code: Select all

        Time→
Level↓  ----------------
7       .o..............
6       ..o.............       o sample
5       ...o............       . empty slot
4       ....o...........
3       .....o..........
2       ......o.........
1       .......o........
0       ........o.......
F (-1)  .........o......
E (-2)  ..........o.....
D (-3)  ...........o....
C (-4)  ............o...
B (-5)  .............o..
A (-6)  ..............o.
9 (-7)  o..............o
8 (-8)  ................
        ----------------
I see now that you are skipping out level 8 (-8) to make the square wave have an odd number of levels, so that it has a middle point to give it a 50% duty cycle. I guess I should have started and ended at 8 for a sawtooth or triangle to give them full amplitude though.



So I guess perhaps something like this using Bregalad's method:

900... 700... 611... 522... 433... 344... 255... 166... 077...
F66... E55... D44... C33... B22... A11... (900... next period)


And maybe like this with Tepples' method:

Weak:
9AA... 9766... 655... 544... 433... 322... 211... 100...
0FF... FEE... EDD... DCC... CBB... BAA... A99... (9AA...)

Strong:
9BB... 9755... 644... 533... 422... 311... 200... 0FF...
FEE... EDD... DCC... CBB... BAA... A99... (9BB...)

Or is the ladder more zigzag up and down like: 544... 455... 322... 233... 100... 011...?
Like for each sample point in your raw waveform you add extra points that alternates level a bit up and down from the raw sample point?
And for raising/falling edges you make an extra squiggle right before the jump/drop like this jump from 9 (-7) to 7: 9BB...BB9755...?
User avatar
Bregalad
Posts: 8181
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: How do bypass the SNES audio low pass filter on the pcb?

Post by Bregalad »

The only reason I avoided the value 8 (-8 actually) in above examples is to guarantee symmetry and to lower the chance to have overflow issues - although overflow can be exploited and many games actually do this.

For your sawtooth, what you probably want is to exagerate the sharp edges of the sawtooth to give a trebble boost.

With filter 0 it would look like the following :
< 7 6 5 5 4 4 4 3 3 3 2 2 2 1 1 1 0 0 0 F F F E E E D D D C C C B B B A A 9 8 >
However you'll have a staircase in the falling part of the sample. It would be easier and more accurate to encode this with filter 1 and maximum shift as something like
<7 D E F F F F F F (etc...) F F E D >
Useless, lumbering half-wits don't scare us.
Pokun
Posts: 3442
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: How do bypass the SNES audio low pass filter on the pcb?

Post by Pokun »

OK, I guess I have to check up on the shifting because I forgot what all that meant.
Thanks anyway.
93143
Posts: 1914
Joined: Fri Jul 04, 2014 9:31 pm

Re: How do bypass the SNES audio low pass filter on the pcb?

Post by 93143 »

...I'm pretty sure you want 16 samples per cycle, not 15.

Or some multiple thereof (for lower notes at least; a 16-sample cycle would brickwall at ~2 kHz for a middle C, which is extremely muffled), with a more sophisticated encoding algorithm and an actual designed prefilter so you roughly mirror the Gaussian muffling curve rather than just eyeballing a random amount of brightening.
tepples
Posts: 22993
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)

Re: How do bypass the SNES audio low pass filter on the pcb?

Post by tepples »

The converter that I developed, wav2brr.py from lorom-template, uses "an actual designed prefilter". It has 15 taps; a close approximation is [-1 6 -1]/4. I haven't had a chance to apply it to single-cycle waveforms.
nocash
Posts: 1494
Joined: Fri Feb 24, 2012 12:09 pm

Re: How do bypass the SNES audio low pass filter on the pcb?

Post by nocash »

Pokun wrote: Tue Dec 17, 2024 5:32 pm So how would I make for example a falling sawtooth using these methods for manual treble boost?
A visual diagram of the samples dotted out makes it much easier to me.
This is the raw sawtooth I'm trying to make before any treble boost is applied...
This chapter has some ascii arts drawings for simple waveforms before/after gaussian interpolation:
https://problemkaputt.de/fullsnes.htm#s ... spbrrpitch
Basically, to generate a square wave or sawtooth wave, repeat each sample several times, and then play it higher sample rate.

Of course that only works for simple waveforms that don't require much memory. If you have a lot of waveforms then applying boost would be more memory friendly than simply repeated each sample.
Oh, if you need very pitch tones, the you might exceed the maximum sample rate when repeating the samples too many times.
But I think you sawtooth example might already sound okay as-is. The rising edge will be a little bit less sharp as desired, but otherwise it should be all fine.
homepage - patreon - you can think of a bit as a bottle that is either half full or half empty
Pokun
Posts: 3442
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: How do bypass the SNES audio low pass filter on the pcb?

Post by Pokun »

You mean the sawtooth is fine without trebble boost?
In FULLSNES it seems square waves sort of becomes sine waves after the interpolation.

Thanks for the concrete tips anyway, the number of samples per cycle is something I've been looking for.