VRC7/YM2413/OPLL Custom Patches

Discuss NSF files, FamiTracker, MML tools, or anything else related to NES music.

Moderator: Moderators

User avatar
Ben Boldt
Posts: 1148
Joined: Tue Mar 22, 2016 8:27 pm
Location: Minnesota, USA

VRC7/YM2413/OPLL Custom Patches

Post by Ben Boldt »

I have been playing with some VRC7 stuff and just started poking at the custom patch. I know the built-in patches of the VRC7 and YM2413 from the siliconpr0n website:

VRC7:

Code: Select all

   | 00 01 02 03 04 05 06 07 | Name
---+-------------------------+----------------
 0 | -- -- -- -- -- -- -- -- | (Custom Patch)
 1 | 03 21 05 06 E8 81 42 27 | Buzzy Bell
 2 | 13 41 14 0D D8 F6 23 12 | Guitar
 3 | 11 11 08 08 FA B2 20 12 | Wurly
 4 | 31 61 0C 07 A8 64 61 27 | Flute
 5 | 32 21 1E 06 E1 76 01 28 | Clarinet
 6 | 02 01 06 00 A3 E2 F4 F4 | Synth
 7 | 21 61 1D 07 82 81 11 07 | Trumpet
 8 | 23 21 22 17 A2 72 01 17 | Organ
 9 | 35 11 25 00 40 73 72 01 | Bells
 A | B5 01 0F 0F A8 A5 51 02 | Vibes
 B | 17 C1 24 07 F8 F8 22 12 | Vibraphone
 C | 71 23 11 06 65 74 18 16 | Tutti
 D | 01 02 D3 05 C9 95 03 02 | Fretless
 E | 61 63 0C 00 94 C0 33 F6 | Synth Bass
 F | 21 72 0D 00 C1 D5 56 06 | Sweep
YM2413:

Code: Select all

   | 00 01 02 03 04 05 06 07 | Name
---+-------------------------+----------------
 0 | -- -- -- -- -- -- -- -- | (Custom Patch)
 1 | 71 61 1E 17 D0 78 00 17 | Violin
 2 | 13 41 1A 0D D8 F7 23 13 | Guitar
 3 | 13 01 99 00 F2 C4 11 23 | Piano
 4 | 31 61 0E 07 A8 64 70 27 | Flute
 5 | 32 21 1E 06 E0 76 00 28 | Clarinet
 6 | 31 22 16 05 E0 71 00 18 | Oboe
 7 | 21 61 1D 07 82 81 10 07 | Trumpet
 8 | 23 21 2D 14 A2 72 00 07 | Organ
 9 | 61 61 1B 06 64 65 10 17 | Horn
 A | 41 61 0B 18 85 F7 71 07 | Synthesizer
 B | 13 01 83 11 FA E4 10 04 | Harpsichord
 C | 17 C1 24 07 F8 F8 22 12 | Vibraphone (same)
 D | 61 50 0C 05 C2 F5 20 42 | Synthesizer Bass
 E | 01 01 55 03 C9 95 03 02 | Acoustic Bass
 F | 61 41 89 03 F1 E4 40 13 | Electric Guitar
I am wondering if other pre-made patches are available anywhere. Yamaha made pianos with lots of built-in patches, I actually had a PSS-140 as a kid which would contain 100 various YM2413 patches. Has anyone gotten the patches from such a keyboard?

The problem I have is that there are so many settings, I think it will be difficult to create the sounds I want without lots of starting points to pick from.

Maybe a different approach: How about an NES test ROM that lets you tweak the settings -- has anyone created anything like that?
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: VRC7/YM2413/OPLL Custom Patches

Post by rainwarrior »

Ben Boldt wrote: Sun Sep 13, 2020 3:55 pmMaybe a different approach: How about an NES test ROM that lets you tweak the settings -- has anyone created anything like that?
CopyNES has a "VRC7 tuner" utility that will let you play with the custom VRC7 patch with a live Lagrange Point cart in your NES, which is what was used to work on the by-ear attempts to duplicate the built-in set.

Though if you don't care about doing it on the original hardware, you could just use Famitracker to edit and audition custom patches. It also lets you copy from the existing built-ins to use as a starting point. Once you have a set you like, you could put those into an OPLL emulator I guess? (e.g. rebuild Famitracker with the new patch set.)

OPLL is also a subset of OPL2. If you know which settings to avoid changing in the patch, you could audition whatever you were hoping to do using an OPL2 or emulator (e.g. trackers for Adlib etc.).
lidnariq
Posts: 11430
Joined: Sun Apr 13, 2008 11:12 am

Re: VRC7/YM2413/OPLL Custom Patches

Post by lidnariq »

Schism tracker, Adlib Tracker 2, (or Screamtracker 3 in DOSBOX) support editing OPL2 patches.

Alsa includes a library of General MIDI OPL2 patches in alsa-tools. ("std.sb")

The only difference that I remember between the single custom patch in OPLL and OPL2 is the reduced library of waveshapes. (OPLL only supports "sine◜◝◟◞" and "half-wave-rectified sine◜◝--"; OPL2 additionally supports "full-wave-rectified-sine◜◝◜◝" and "◜-◜-"). I transcribed an OPL2 tune by Skaven to Famitracker and I thought it was a pretty close match.
User avatar
Ben Boldt
Posts: 1148
Joined: Tue Mar 22, 2016 8:27 pm
Location: Minnesota, USA

Re: VRC7/YM2413/OPLL Custom Patches

Post by Ben Boldt »

Okay thanks for the advice. I do still have that PSS-140 stored away. If I can get ahold of it again some day I will sniff out its 100 patches for us with my oscilloscope.

Kind of a side-question, some time ago I put names of the instruments into our VRC7 audio wiki page, based on a forum post from plgDavid. However, I see some different names in Famitracker. Do we know if any of these names came from a real source or have people probably just created names for them in modern times?
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: VRC7/YM2413/OPLL Custom Patches

Post by rainwarrior »

Ben Boldt wrote: Wed Sep 16, 2020 9:02 pmKind of a side-question, some time ago I put names of the instruments into our VRC7 audio wiki page, based on a forum post from plgDavid. However, I see some different names in Famitracker. Do we know if any of these names came from a real source or have people probably just created names for them in modern times?
I think I might have named them for Famitracker? At least, I think I once had a conversation with JSR about it and he ended up using the names I gave? Not sure.

I think for standard OPLL you might be able to get "official" names off a Casio keyboard that uses it, perhaps? (Though, even there I think the named instruments tend to be custom ones. The built-in ones might only show up anonymously in accompaniment patterns.)

However, with VRC7 they're custom made for Konami, so I dunno how you'd track down any names they might have given them. If you're really lucky maybe there's some VRC7 patent document or something.

Funnily enough I think the names plgDavid and I independently came up for them seem to overlap more than they diverge.
User avatar
Memblers
Site Admin
Posts: 4044
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: VRC7/YM2413/OPLL Custom Patches

Post by Memblers »

Seems like it should be possible to rip patches from a VGM file. I'm assuming the parameters don't/can't changed while the note plays (I'm not well-versed in the Yamaha stuff), one could store the channel's current register settings when a note-on is triggered. Discarding duplicate sets, and parsing the whole file, would then allow a quick rip of every patch used in the song.
User avatar
Ben Boldt
Posts: 1148
Joined: Tue Mar 22, 2016 8:27 pm
Location: Minnesota, USA

Re: VRC7/YM2413/OPLL Custom Patches

Post by Ben Boldt »

rainwarrior wrote: Wed Sep 16, 2020 11:36 pm I think for standard OPLL you might be able to get "official" names off a Casio keyboard that uses it, perhaps? (Though, even there I think the named instruments tend to be custom ones. The built-in ones might only show up anonymously in accompaniment patterns.)
As far as I knew from Wikipedia, only these Yamaha keyboards used the YM2413:

PSS-170, PSS-270, SHS-10, PSS-140, SHS-200, PSR-6

You mention Casio; are there other keyboards using this? It is possible that I will find matching patches and can correlate those to a name.
Memblers wrote: Thu Sep 17, 2020 1:45 am Seems like it should be possible to rip patches from a VGM file.
Neat idea.
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: VRC7/YM2413/OPLL Custom Patches

Post by rainwarrior »

Memblers wrote: Thu Sep 17, 2020 1:45 amI'm assuming the parameters don't/can't changed while the note plays (I'm not well-versed in the Yamaha stuff), one could store the channel's current register settings when a note-on is triggered.
You can modify the parameters while a note is in flight, though I think actual use of this is pretty rare.
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: VRC7/YM2413/OPLL Custom Patches

Post by rainwarrior »

Ben Boldt wrote: Thu Sep 17, 2020 5:59 amAs far as I knew from Wikipedia, only these Yamaha keyboards used the YM2413
I thought there were some Casio ones as well using OPLL, but I don't remember details, possibly was mistaken.
User avatar
Ben Boldt
Posts: 1148
Joined: Tue Mar 22, 2016 8:27 pm
Location: Minnesota, USA

Re: VRC7/YM2413/OPLL Custom Patches

Post by Ben Boldt »

Okay cool, thanks for the info. I am kind of playing with VRC7 lately and tossing around ideas, etc. I have been working on hacking Tetris to run on VRC7 and play FM music and making some progress on that. Not ready yet to commit to completing it but just having fun for the most part.

https://youtu.be/3EmI11nho-w

I find that the VRC7 (other than the audio) is actually extremely simple, nothing fancy like the MMC5, leading me to think that a reproduction of it might not be too crazy. It MIGHT be possible with just a fast microcontroller and change notification interrupts, not sure on that but something I am interested to look into. This would be asking a lot from a micro, but could be cheap and not require level shifting as lots of micros have 5V tolerant inputs (unlike FPGAs and CPLDs)... It is a pipe dream at best right now. We're talking interrupts happening at MHz speeds especially for the PPU banking and mirroring. Doesn't seem likely at the moment but who knows.

But anyway, on the topic of microcontrollers, even if the banking logic needs to be offloaded to discrete logic or a CPLD, I think a microcontroller may still be well-suited to emulating the YM2413 engine. From what I am reading, it looks like the YM2413 DAC is 16-bit. Most cheap microcontroller DACs are 10-bit or 12-bit. Alternatively, could use a "poor-man's DAC" using a PWM and low-pass filter to cut off frequencies above 20kHz, not sure that would be much better. In my mind (and my theory may be completely wrong on this), the PWM frequency needs to be at least 20kHz, with a granularity of 2^16, so basically that PWM needs to have internal clocking 20kHz * 2^16 = 1.31 GHz which is not realistic. So I don't think the PWM can be better audio quality than the DAC. Getting an external 16-bit DAC is cost-prohibitive; I have never understood why external DACs cost so much. Maybe it is possible to build a discrete DAC out of a resistor ladder. Not sure how well I can trust voltage of the microcontroller output pins, may need a buffer for each pin, but at least that is a way to get a pretty cheap 16-bit DAC...

I have started to wonder, how on earth does the Everdrive put out VRC7 audio? Does anyone know what it is using for a DAC? The audio output of the NES/Famicom is pretty noisy anyway... Maybe you can't tell the difference between 12-bit and 16-bit through that noise? Maybe the VRC7 doesn't really put out 16-bit quality audio? Just looking for any insight you guys have on these sorts of questions.
lidnariq
Posts: 11430
Joined: Sun Apr 13, 2008 11:12 am

Re: VRC7/YM2413/OPLL Custom Patches

Post by lidnariq »

Ben Boldt wrote: Sat Sep 19, 2020 10:31 am But anyway, on the topic of microcontrollers, even if the banking logic needs to be offloaded to discrete logic or a CPLD, I think a microcontroller may still be well-suited to emulating the YM2413 engine.
Back in the day, I had a Sound Blaster clone that must have stuffed an OPL2 emulator into a OTP 8051. Maybe some day I'll be able to dump it. It only had an 8 bit DAC, although maybe it's a floating point output multiplied in hardware by the TL074.

Internally, Yamaha's FM synthesizers use a logsin table and an exp table. NukeyKT has written an implementation: https://github.com/nukeykt/Nuked-OPLL
Alternatively, could use a "poor-man's DAC" using a PWM and low-pass filter to cut off frequencies above 20kHz, not sure that would be much better. In my mind (and my theory may be completely wrong on this), the PWM frequency needs to be at least 20kHz, with a granularity of 2^16, so basically that PWM needs to have internal clocking 20kHz * 2^16 = 1.31 GHz which is not realistic.
No one uses 16-bit PWM for audio; everyone uses some form of delta-sigma DAC instead. Sometimes it's a normal R-2R DAC with ΔΣ on the LSB, sometimes it's just a 1-bit DAC with lots of noise shaping.
Not sure how well I can trust voltage of the microcontroller output pins
At least Microchip does some comprehensive testing of the current-sourcing capabilities of the pins.
Maybe the VRC7 doesn't really put out 16-bit quality audio?
Looking in the corner of the die, I think it's a floating point DAC, with 7 bits of fraction and 3 bits of exponent. https://siliconpr0n.org/map/konami/vrc_ ... &y=924&z=6

I think it does go to a 16 bit output stage at the end, after it's decoded.
User avatar
Ben Boldt
Posts: 1148
Joined: Tue Mar 22, 2016 8:27 pm
Location: Minnesota, USA

Re: VRC7/YM2413/OPLL Custom Patches

Post by Ben Boldt »

Wow, I have never heard of delta-sigma DAC, either that or I forgot it completely. I have been reading up on it now. It looks like it is basically implementing a poor-man's PWM again but this time with known slopes and a feedback loop. I am wondering if there is a way to mitigate overhead in the micro from this sort of scheme. My goal still being the simplest/cheapest/easiest solution, directly using a 12-bit DAC is attractive, but not sure the perceived loss of quality with 12-bit DAC versus a feedback design. A DAC is rock-solid, it will go exactly where it is told (complete with sharp edges) and I am not sure if that is good or bad for perceived quality. Interesting things to think about.
lidnariq
Posts: 11430
Joined: Sun Apr 13, 2008 11:12 am

Re: VRC7/YM2413/OPLL Custom Patches

Post by lidnariq »

Ben Boldt wrote: Sat Sep 19, 2020 12:00 pm It looks like it is basically implementing a poor-man's PWM again but this time with known slopes and a feedback loop.
That feedback loop is the important bit. The idea behind ΔΣ is that you can put noise in higher frequencies to get greater effective bitdepth in lower frequencies. (Or you can change the noise shaping to get a different band for desired and rejected frequencies).
I am wondering if there is a way to mitigate overhead in the micro from this sort of scheme.
The newer raspberry Pi DAC implementations use a 7-bit PWM DAC with ΔΣ noise shaping. But the Raspberry Pi, at lowest capabilities, is still a 700MHz ARM.

FPGAs and CPLDs are very well suited to ΔΣ noise shaping, because 1st and 2nd order ones are literally just some subtractors.

(Higher order noise shaping has to have explicit filter design to remain stable in a DSP sense)
My goal still being the simplest/cheapest/easiest solution
Just use a lower-depth PWM DAC and worry about quality later, then. It's easy enough to go back and revisit that part of the design.
it will go exactly where it is told (complete with sharp edges) and I am not sure if that is good or bad for perceived quality.
All real hardware has to deal with slew rates. Part of DAC design is accounting for this, whether you need a controllable voltage reference (e.g. I²C), audio output, or video DACs.

The actual hardware in the OPLL actually emits new samples at 447kHz (crystal÷8), rotating between all nine voices in sequence. I don't know if the VRC7 multiplexes its output at a slower rate because there's only 6 voices. In this case, as long as the slew rate is constant and linear, it's ok if it mixes.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: VRC7/YM2413/OPLL Custom Patches

Post by tepples »

Sony Super Audio CD (SACD) runs a 1-bit DAC using delta sigma, also called pulse density modulation (PDM) or Direct Stream Digital (DSD), at 2.8224 MHz, which is 64 times the CD-DA sample rate. The rate of M2 on a Famicom is almost as high as that: 1.790 MHz. So a 1-bit DAC could be a very good strategy for pushing the dither noise above (say) 24 kHz so that the low pass filters in the modulator and the TV's audio input can reject it.
lidnariq
Posts: 11430
Joined: Sun Apr 13, 2008 11:12 am

Re: VRC7/YM2413/OPLL Custom Patches

Post by lidnariq »

tepples wrote: Sat Sep 19, 2020 4:25 pm pulse density modulation (PDM)
My understanding is that PDM is specifically only equivalent to a 1st order delta-sigma DAC. It's also the same idea as Bresenham's line algorithm: you accumulate error and you toggle between the two extremes according to whatever minimizes that error.

I believe actual SACDs use a higher-order ΔΣ, encoded at mastering time: perhaps the same 5th order that more expensive ΣΔ DACs use. Unfortunately, as I stated earlier, anything higher than a 2nd order filter requires active design, and I haven't found any publicly-disclosed filter coefficients.
Post Reply