Wohlstand / OPN2BankEditor

A small cross-platform editor of the OPN2 FM banks of different formats (Downloads in README below)
GNU General Public License v3.0
42 stars 8 forks source link

Check out the OPNA chip #46

Closed Wohlstand closed 3 years ago

Wohlstand commented 6 years ago

https://www.vogons.org/viewtopic.php?p=704730#p704730

SLON: What about the possibility of using the YM2608 core? It was distinguished by the presence of additional SSG and ADPCM (and RHY-channels), and also, as far as I know, a higher-quality DAC. True, I do not know how useful this will be for MIDI.

Wohlstand: It's dependent on the availability of necessary emulator and the chip specification I can use to provide an interface. For now, libOPNMIDI doesn't use DAC, but its support is WIP. On side of libOPNMIDI are three emulators: Nuked OPN2 is implemented YM3438 chip, but it's very powerful and won't work on slow hardware in real-time if you running more than 3 chips; MAME OPN2 is implemented YM2612, doesn't using much power, but is a most balanced emulator that gives well-accurate and doesn't eat too much CPU; And the GENS 2.10, the old and inaccurate emulator, but, the fastest emulator I have at me.

If the OPNA chip has compatible ABI, we can try to use it as an alternative chip together with existing OPN2 chips. For the case of DAC-equipped chips, they are all will have the sample-streamer on the side of ChipSet base backend, and necessary to do that from outside. The only exception would be for OPNA that does support of ADPCM.

freq-mod commented 6 years ago

Regarding YM2608, one thing to remember: there were two versions/revisions of it.

There were rhythm channels derived from YM3301 drum machine. 6 samples, somewhat terrible quality, stored in built-in ROM. YM2608 relied on external DAC, so there were no distortions. Also, sampling freq. was higher at 55466 Hz (hi-hats sound much more convincing on 2608 IMO 😉 ) As for emulators, there is PMDWin core, MAME YM2608, Neko-project FMGEN core... all of them should be accurate enough.

jpcima commented 6 years ago

There is now a WIP for OPNA on my work branch. This adds "Neko Project II Kai OPNA". https://github.com/jpcima/libOPNMIDI/tree/neko-opna

It plays with some glitches. This is what I know so far.

Other than this, I cleaned up warnings, I've marked code by // libOPNMIDI comments where are made more significant changes. At first look this seemed like a light emulator on the CPU, and also nice when it comes to license (MIT).

Wohlstand commented 6 years ago

I have tried to play random music on a quick hand, and I can say next:

Wohlstand commented 6 years ago

P.S. Please also convert all Shift_JIS files into UTF8 to avoid future crap and let read Japaneese comments in a quite :fox_face: (UTF8 with no conversion) _2018-11-16_07-25-40

(Shift_JIS with no conversion, need to save as UTF8 later) _2018-11-16_07-25-53

Wohlstand commented 6 years ago

As a minor workaround, I have forced MIDI synthesizer to skip 3 last channels while range scan for goodness check, so, 3 first channels are in use: default And music playing fine with no missing channels! So, I ague, it's the OPN2 and OPNA difference of post-3 channels alignment or way to call of them.

EDIT: This is safer, otherwise, the check is skipped, and previous will lead a crash... _2018-11-16_07-38-43

Wohlstand commented 6 years ago

I have found something related, will research the stuff after sleep: https://wiki.neogeodev.org/index.php?title=YM2610

YM2608J Translated.PDF

jpcima commented 6 years ago

I converted the shift-jis encoding. Also I agree that some chip-related information be abstracted through chip-base's interface, taking precaution of avoiding virtual calls at the audio rate.

I'm interested to see your handling of channels which improves playback situation, and also I forgot how is computed the frequency coefficient formula. I will look again after some rest.

jpcima commented 6 years ago

I scaled the pitch coefficient, and this fixed the frequency. Next is to manage the channels correctly.

jpcima commented 6 years ago

Found ! It needs to set bit SCH "six channels" of register 0x29. Then it has all the FM channels working.

Wohlstand commented 6 years ago

Oh, neat! :fox_face: :+1:

Wohlstand commented 6 years ago

So, there is only some questions about ABI difference: which features are different between OPN2 and OPNA related to FM synth

Wohlstand commented 6 years ago

One thing I forgot, OPNA has some sort of PSG in place as I know...

Wohlstand commented 6 years ago

And, which sense of SSG-channels?

freq-mod commented 6 years ago

One thing I forgot, OPNA has some sort of PSG in place as I know...

It does. It's built-in YM2419 core, the same that was in ZX spectrum, Amstrad CPC, Atari ST... It has 3 channels - each of them can produce either 50% square wave, noise or combined square wave & noise (at the same time, occupying one channel!) It also has ADSR envelope generator, like FM synth or SID chip - common for every channel

Wohlstand commented 6 years ago

It also has ADSR envelope generator, like FM synth or SID chip

Looks like an easy solution of this: https://github.com/Wohlstand/libOPNMIDI/issues/6

freq-mod commented 6 years ago

SN76489 doesn't have ADSR, just a simple 4-bit volume control. YM2419 SSG chip sounds slightly different as it's noise generator is much more sophisticated than SN crap.

2419 also has 4-bit volume control but it's just an addition to envelope generator.

Wohlstand commented 6 years ago

Neat! Also, it's would be cool then add it into OPN-BE to benchmark it, I'm curious how much it loads the CPU, and, how accurate it emulates the sound in comparison to others include MAME.

Wohlstand commented 6 years ago

Anyway, I have checked out the CPU load by opnmidiplay, and loos NP2's OPNA is a bit faster than MAME :fox_face:

jpcima commented 6 years ago

Yeah but it's a bit like Gens also. It's not faster in full use, but it's good at saving CPU usage from the inactive parts. MAME is a stabler CPU usage.

Wohlstand commented 6 years ago

I also hearing that percussions are sounding differently than on OPN2 chips, due different clock and oscilators. But also means, need to tune a bit the frequency coefficient...

freq-mod commented 6 years ago

Yeah, that is because sampling frequency is different, 55466 rather than 53267 hertz. That's the reason percussion used to sound different on Gens core compared to Nuked.

freq-mod commented 6 years ago

Hmmm... i checked out OPNA emulation, SSG-EG based instruments sound completely off Did YM2608 not have SSG-EG and this is normal?

jpcima commented 6 years ago

Yeah it has the SSG and I reproduce the problem. Gotta debug into this.

freq-mod commented 6 years ago

I'm not certain but there can be a problem with detune values... I tried porting hi-hat from some PC-9801 game and it sounded off until i (blindly) played around with detune parameters... weird.

jpcima commented 6 years ago

I took a plot of SSG-EG based off the patch SFX Laughing from @Wohlstand's bank, it's based on /\/\ shape. Let's try extracting same infos off Nuked or MAME...

capture du 2018-11-16 22-40-12

jpcima commented 6 years ago

This was MAME SSG-EG.

capture du 2018-11-16 22-53-55

freq-mod commented 6 years ago

For temporary, I have made a separated bend coefficient for percussions, as because of chip clock difference (between OPN2 and OPNA), percussions are too sensitive and needs a different pitch to sound correctly.

https://github.com/Wohlstand/libOPNMIDI/commit/7076de broke the percussion such as hi-hats, they sound completely wrong now, at least compared to Hoot player, meanwhile they had the same timbre before hihat before (note only the timbre, accidentally record two of them my bad): https://instaud.io/2W91 hihat after: https://instaud.io/2W92

Wohlstand commented 6 years ago

That I did, is really mess, as it was my ugly attempt to polish OPN2-ish drums over OPNA, but this breaks native OPNA instruments, so, yeah. The true solution is adding of per-chip per-instrument fine (like not offset, but as micro offset unit) tune into WOPNv3, and this I'll nuke down.

jpcima commented 6 years ago

but this breaks native OPNA instruments

Exactly, why not let chip sound native like it should be ? Let chip use own instruments for it, or you can clock down chip's sampling rate for identical effect. You're free to invent a tool which patches OPNx instruments of one chip for another.

The true solution is adding of per-chip per-instrument fine (like not offset, but as micro offset unit) tune

NO it's not the tune, it's operating sample rate. To detune is not a mathematically correct solution. You can set operating rate of this emulator at anything you want. Did you try using OPN2's ratings?

Wohlstand commented 6 years ago

NO it's not the tune, it's operating sample rate.

I mean, keep the chip native rate, but polish the instrument to fit into multiple different chips with keeping native rates of all of them.

You can set operating rate of this emulator at anything you want. Did you try using OPN2's ratings?

That yeah, but I didn't tried that, but, let's try... I'm interesting which result will happen...

jpcima commented 6 years ago

opn_chip_family.h change:

template <>
struct OPNFamilyTraits<OPNChip_OPNA>
{
    enum {
        // nativeRate = 55466,
        // nativeClockRate = 7987200,
        nativeRate = 53267,
        nativeClockRate = 7670454,
    };
};
Wohlstand commented 6 years ago

Done just now, and yeah, the sound of percussions is now same as on OPN2 chips, that yeah, however, percussions made for OPNA directly, will be broken as I said, and there are needs to be polished...

jpcima commented 6 years ago

What do you think to be a solution? it's not satisfactory to use a solution based on detuning. As I understand, this gets you 1. broken OPNA and 2. not-very-good compatibility of OPN2, like a worst of both worlds compromise. In this situation, you can't play in fidelity instrument from both of chips.

I'm just saying to let chip act like they want. At least then it can be a good OPNA. OPN2 instruments run the best on OPN2, and OPNA same. If you'd like compatibility, drop sample rate.

Wohlstand commented 6 years ago

Anyway, what about the bank-wide flag "force OPN2 clock on OPNA"? (it can be added into WOPN2 without of damage) So, the bank intended to work on OPNA will work fine, but OPN2-bank will force OPNA chip to work in OPN2's frequency.

Wohlstand commented 6 years ago

Also, having this flag, OPNA-intended banks would say to synthesizer to automatically choose OPNA chip than OPN2 that is in use by default.

jpcima commented 6 years ago

This, I think it would be ideal.

However it's a possible problem in case of mixing OPN2 and OPNA instruments, so I want to let know what is the enabled mode of operation in my programs. In chip setup, I would like to access the mode in read and write, so I can show it and control from a menu.

jpcima commented 6 years ago

Note: you can also do the reverse, clock OPN2 as OPNA, for an emulator which has this support

Wohlstand commented 6 years ago

Note: you can also do the reverse, clock OPN2 as OPNA, for an emulator which has this support

Yeah ;3 This will be not possible with Nuked OPN2 as it's the simulator of real chip, and that will be same with potential Nuked OPNA when @nukeykt will introduce it (if is a plan for it?), so, the porting of instruments between OPN2 and OPNA will need the tuning to "align" the instrument into necessary chip.

jpcima commented 6 years ago

This will be not possible with Nuked OPN2 as it's the simulator of real chip

Why not? it has the controls of rate and clock.

Wohlstand commented 6 years ago

Why not? it has the controls of rate and clock.

Trying to change clock you'll also change the rate of LFO (example of result of my early mistake: http://wohlsoft.ru/docs/_files_for_posts/Misc/NukedOPN2/Suzanna-Nuked.flac) You'll hear that LFO's frequency is too fast here

Wohlstand commented 6 years ago

@papiezak , okay, the frequency crap has been resolved with adding chip category which will say in which frequency all emulators are must work to match OPN2 or OPNA in dependency which instruments you want to create. At OPN2-BE I have added the chip type flag: _2018-11-18_15-43-01 you can use to tell for which chip you creating the bank, and by this flag, bank will set necessary frequency of the chip emulator (even OPN2 chips will work in OPNA's frequency when you wanna use OPNA-ish drums without distortion). And @jpcima has implemented this on libOPNMIDI side: https://github.com/Wohlstand/libOPNMIDI/pull/74 Anyway, the thing is left on OPN2-BE to port the updated chipset to introduce OPNA emulator at the here.

jpcima commented 6 years ago

Anyway, the thing is left on OPN2-BE to port the updated chipset to introduce OPNA emulator at the here.

I let you have this task if you want, as currently I'm doing the implementation work in the plugin and testing.

Wohlstand commented 6 years ago

I let you have this task if you want, as currently I'm doing the implementation work in the plugin and testing.

Anyway, the question: will you change chipset API again in nearest time? If no, I gonna to backport it into OPN2BE now

jpcima commented 6 years ago

Current libOPNMIDI has been sufficient for my needs, so it would be fine.

Wohlstand commented 6 years ago

Okay, I'll work on this now. :wink:

Wohlstand commented 6 years ago

Just now I have made OPNA support on Bank Editor side! :fox_face: :wink: default

freq-mod commented 6 years ago

Hmmm, testing native OPNA instruments I can hear there is a difference in timbre between instruments played in bank editor and OPNMIDIplay... hihat banked.zip - there is a zip file with comparision between these two and instrument file in question

EDIT: bank editor's output matches Hoot player, which is what should it be

jpcima commented 6 years ago

Having latest libOPNMIDI and wopn bank saved with OPNA flag, I had identical timbres between bank editor and VST. opnmidiplay is to retry but I gave it some light testing with different banks as I implemented in libOPNMIDI, and it showed to work correctly during these tests.

freq-mod commented 6 years ago

Damn, flase flag. Looks like weird timbre is only the case of some .mids, like MIDI_sample.mid from http://wohlsoft.ru/docs/Music/MIDI/ I didn't test it thoroughly enough my bad 🤦‍♂️

Still, SSG-EG should be looked at

Wohlstand commented 6 years ago

I have found what's the sense of channels of OPNA: https://www.youtube.com/watch?v=bFphJBs6PSk

The rhythm sound source part is a digital rhythm tone that uses ADPCM voice synthesis.
ADPCM rhythm tone can pronounce tones of the rhythm musical instruments that the sound
making is difficult with easy software in the FM sound source. Moreover, the rhythm tone
can comparatively sample easily because of the attenuation sound by a little memory, and
secure the envelope from the generation of the sound to the disappearance naturally.
The tone is composed of six kinds of drums of a basic tone, and can be pronounced by six
sounds simultaneously. Because each tone can individually set the level, the accent
processing to say nothing of the balance adjustments of each musical instrument can be
freely done.
The control register of the rhythm sound source part is composed of $10-$1D. Moreover,
when bus control signal A1 is“0”, the data access to this register is possible.
(Refer to seven pages to the bus control)

And the full doc is here: https://github.com/Wohlstand/OPN2BankEditor/files/2588007/YM2608J.Translated.PDF