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
40 stars 8 forks source link

Check out the OPNA chip #46

Closed Wohlstand closed 3 years ago

Wohlstand commented 5 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.

nukeykt commented 5 years ago

YM2612 is basically YM2608's FM block with a cheap YM2413's DAC and very hacky PCM mode, presumably created for Sega MegaDrive. So i think it's pretty easy to use any YM2612 core as YM2608's FM block. Also it's safe to set OPN2 clock rate to 7.9 MHz(for reference nominal rate for YM2612/YM3438 is actually 8MHz, Yamaha/Sega used 7,67MHz for Mega Drive as it was close enough).

freq-mod commented 5 years ago

So this documentation of YM2612 SSG-EG can be used to describe and debug YM2608 SSG-EG? http://gendev.spritesmind.net/forum/viewtopic.php?p=5716#5716

Wohlstand commented 5 years ago

So, the question that is still be here: is it's fault of NP2's OPNA emulator reguard to SSG-EG implementation, or is real OPNA has the same? But okay, I guess it's the fault of NP2 emulator, and we would to try to fix it.

nukeykt commented 5 years ago

I really doubt that Yamaha would spend time(money) to somehow alter SSG-EG behavior(especially for cheaply developed YM2612). SSG-EG is technically part of FM block and not related to real SSG implementation in YM2608.

freq-mod commented 5 years ago

it's fault of NP2's OPNA emulator reguard to SSG-EG implementation, or is real OPNA has the same?

Nice way to check it would be by adding this emulator in the future - (https://github.com/pbarfuss/PMDWinS036); it appears to be newer but more resource hungry

SSG-EG is technically part of FM block and not related to real SSG implementation in YM2608.

I once heard that YM2612's SSG-EG is just a leftover from YM2608 SSG block, thanks for clarifying

Wohlstand commented 5 years ago

Also, looks like we can add the another OPN2 chip which will use same NP2 emulator, but, as separated slot: https://github.com/Wohlstand/OPN2BankEditor/blob/master/src/opl/chips/np2/fmgen_opna.h#L474

At the same time, MAME also supports OPNA: https://github.com/mamedev/mame/tree/master/src/devices/sound However, that was made as a mess of parts, however, it's easy to split up and get the united OPNA stuff.

jpcima commented 5 years ago

@Wohlstand OPN2 is present in header but not implemented. OPNB crashed, so I don't know if works. However, it has the other chip family OPM, whose files I removed from this fmgen as they didn't serve. All are built on the shared FM core.

Wohlstand commented 5 years ago

@papiezak , looks like this PMDWins036 has pre-filled Rhythm-ROM that can be also used for https://github.com/Wohlstand/libOPNMIDI/issues/5 as simplest OPNA-native alternative to custom samples for our MiniWT synth (those are not fit into OPNA, will be played through ADPCM stream or as Pseudo-DAC will be mixed with output out of chip) that we'll use to stream drums and some simple melodic instruments through YM2612's DAC (However, for case of OPNA it's need to correctly ADPCM-compress the stream). The NP2 gives functions to load custom PCM chunks as Rhythm instruments (They are can be found with set of BIOS files of NP2Kai zip for Windows I have found at some place).

Wohlstand commented 5 years ago

P.S. OPNA's SSG also can be used in instruments in three modes: as solo, as dual (like pseudo-4op at ADLMIDI), or in parallel with FM voice. For OPN2 chips the PSG can be placed, for example, equivalent Yamaha's PSG to OPNA's part with envelope support rather to use a shitty SN chip.

freq-mod commented 5 years ago

The NP2 gives functions to load custom PCM chunks as Rhythm instruments (They are can be found with set of BIOS files of NP2Kai zip for Windows I have found at some place).

Shouldn't it be impossible and emulation-wise, fundamentally wrong? YM2608 Rhythm Sound Source is just a six samples (2608_samples.zip) that are hardcoded into it's built in ROM. You can't alter it or add any more new samples onto it. Simply impossible, like writing to the fully filled non-rewritable CD-ROM. Only control you have with them is volume control and panning. You can't even re-pitch them! It's bilion times worse than even OPL drum mode.

Wohlstand commented 5 years ago

Shouldn't it be impossible and emulation-wise, fundamentally wrong?

That's very possible, anyway, the thing looks like I need to allow emulator (NP2 only can from files) to load those PCM chunks from memory rather from files (to allow passing of those chunks from WOPN file directly).

freq-mod commented 5 years ago

To complement #1, it would be great to have ability to extract instruments from YM2608 VGMs/VGZs Some samples: TsunyanJaayao(NEC_PC-9801).zip

Wohlstand commented 5 years ago

YM2608 VGMs/VGZs

I think, it's super-easy to allow OPNA-related stuff be interpreted, let's check that in spec...

VGZ

Looks like I need to begin use zlib for VGZs are not supported yet now...

freq-mod commented 5 years ago

I think SSG-EG is now broken on OPNA because emulator used now (NP2 Kai) seems to be as old and obsolete as Gens 2.10: // FM Sound Generator - Core Unit // Copyright (C) cisc 1998, 2003.

I discovered there is a YM2608 tracker in early development called Bamboo Tracker. It relies on MAME OPNA emulator and SSG-EG sounds rather close to what is on OPN2 emulators like MAME or Nuked. The only real difference is that frequency is lower as heard in comparison recordings: ssgeg comparison.zip

Wohlstand commented 5 years ago

Yeah, the MAME OPNA is also choice as I said, so, I'll try to implement it also.

freq-mod commented 5 years ago

Now that MAME is added, SSG-EG works much better. It's still different from YM2612, kinda "slower", but that may be the intended behaviour of a real YM2608. Still, SSG-EG instruments in YM2612 banks must be corrected to sound fine in YM2608. Just raise Decay 1 rates by 2 or 3.

About square wave channels, I think you need emu2149.c and emu2149.h as well. Don't know what about rhythm samples, though.

freq-mod commented 5 years ago

Now that MAME SSG and rhythm portions of YM2608 are added, I looked at that UI sketch and envelope parameter options look weird... env

@rerrahkr - you seem to be knowledgeable about SSG capabilities, does its envelope rely on these CONT/ATT/ALT/HOLD values like in SSG-EG or just 16-step volume level (and 8 "hard" steps)?

rerrahkr commented 5 years ago

In BambooTracker, 8 "hard" steps means using hardware envelope which is controlled by EG frequency, C, ATT, ALT and HLD. The other 16 steps use software envelope controlled by writing volume to its level register for each tick.

The volume resolution of hardware envelope is 32, finer than software envelope that it is 16. But hardware envelope cannot change envelope shape more flexible and volume scale (volume level operation is not reflected during hardware envelope execution). Therefore some OPNA sound drivers like PMD control SSG envelope by software envelope and don't use hardware envelope.

Wohlstand commented 5 years ago

So, looks like I need to make that SW envelope for here also, like for SN which is totally lacks any envelope support. Also, @rerrahkr , can you better explain how to convert MIDI tone into SSG's tone frequency? Code I have made in my sketch branch is crap and makes completely wrong tone for now. I have the valid stuff for FM.

freq-mod commented 5 years ago

Thanks for the info @rerrahkr!

Looking at sketch I think there should be also an option for noise or combined noise/square wave output; that's going to be crucial for many instruments. Also, Bamboo Tracker supports arbitrary waveforms for SSG produced by hardware envelope manipulation (sawtooth, triangle), it would also be neat if possible

rerrahkr commented 5 years ago

SSG tone is defined as: hertz = master_clock / (64 * TP) TP is 12-bit register value, high 4 bits are "coarse tune" set to register $01, $03, $04, and low 8 bits are "fine tune" set to $00, $02, $04. So I think:

uint32_t tp = static_cast<uint32_t>(clock / 64.0 / hertz);
WriteReg(0, 0x00 + cc * 2, static_cast<uint8_t>(0x0ff & tp));
WriteReg(0, 0x01 + cc * 2, static_cast<uint8_t>(tp >> 8));
jpcima commented 5 years ago

Implemented the tuning. Thanks for the information. Have we any existing files which describe SSG-based instruments?

Wohlstand commented 5 years ago

SSG tone is defined as: hertz = master_clock / (64 * TP)

Implemented the tuning. Thanks for the information.

@rerrahkr , @jpcima , thanks you both for correction of the tone formula! Just now tested the thing, and it works! :fox_face: :smiley:

I have made few tweaks on that branch, and will continue the work that needs a deep refactoring, otherwise, current code is a mess... I have some idea to make, will try this possibly tomorrow or later...

jpcima commented 5 years ago

These are some findings about the PMD envelope generator.

  1. https://pigu-a.github.io/pmddocs/pmdmml.htm#8-1
  2. http://battleofthebits.org/lyceum/HistoryView/1175/#SSG%20Commands

It describes a variation of level over time for 2 envelope kinds, where length of steps are allowed to be controlled by a clock setting defined by user.

A fitting description may be as such:

Other:

freq-mod commented 5 years ago

I noticed that chipset wasn't updated with a Neko Project 2 SSG-EG fix (Wohlstand/libOPNMIDI#81), would it be possible to backport these changes into editor? I want to investigate as some of my SSG-EG based instuments sound bad on YM2608 emus including MAME...

Wohlstand commented 5 years ago

@papiezak , oh, forgot, gonna to sync that change now!

jpcima commented 5 years ago

Please note, I took Nuked OPN2 as basis for comparison as I made this; and I'm not sure at all what this comparison is worth, these being different chips.

This was a full rewrite of this broken part of Neko OPN, based on black-box comparison of emulator's respective curves, measured in a few different cases.

Wohlstand commented 5 years ago

@papiezak , Took those changes just now

freq-mod commented 5 years ago

I've taken a listen. Now, at some cases (depending on AR value being 31 or not I guess) NP2's SSG-EG sounds either similarly to MAME's ssgeg (but not identical) or exactly like Nuked YM2612 🤔

Please note, I took Nuked OPN2 as basis for comparison as I made this; and I'm not sure at all what this comparison is worth, these being different chips.

So could it be that these changes are wrong in context of YM2608 and resulted in "hybrid OPNA-OPN2 chip"? Maybe closer analysis of PMDWinS036 emu would tell more as it seems to be the most accurate of all 2608 emulators...

nukeykt commented 5 years ago

I'm pretty much sure that SSG-EG behaves same at least within YM2608, YM2610 and YM2612(and possibly YM3438)

Wohlstand commented 5 years ago

Anyway, when I compared SSG-EG on all emulators, in my xg.wopn, the telephone is acting slower on OPNA chips than on OPN2

freq-mod commented 5 years ago

It's not only just slower, take the "Car Engine SFX" instument from my GS bank. On Nuked (and now, Neko Project) it sounds much more aggressive and louder than on MAME YM2608 where it's like muffled: https://instaud.io/3mAr - nuked https://instaud.io/3mAs - mame OPNA I haven't tested PMDWin yet, but it doesn't have SSG-EG implemented anyway 🤷‍♂️

@nukeykt is most likely right, but if to examine SSG-EG capabilities completely, best way would be to compare emulation to real chip. _@rerrahkr'sBamboo Tracker supports hardware passthrough to real YM2608 (and soundcards that use it) via SCCI. When possible, if someone would provide recordings of SSG-EG instruments behaviour on real 2608, would be extremely grateful ❤️

freq-mod commented 5 years ago

There is a glitch on PMDWin emulator.

  1. Open the bank editor without any bank loaded.
  2. Set an emulator to PMDWin.
  3. Play a note.

Even when instrument is blank/null (AR=0) loud noise will be heard that will last forever. Hitting "Shut up" button helps only a bit, you can still hear the crap, it's only much more quiet.

Wohlstand commented 5 years ago

Even when instrument is blank/null (AR=0) loud noise will be heard that will last forever. Hitting "Shut up" button helps only a bit, you can still hear the crap, it's only much more quiet.

I had same while experimented with Rhythm, when I forgot to click the "Rhythm" and tried to play blank note...

Also, about Rhythm, PMDWin is totally not responds on volume levels and panning bits, and plays all instruments quite about silent, but hearable. Good that NP2 has good Rhythm implementation, so, I have completed my test :fox_face:

jpcima commented 5 years ago

It's the same envelope problem as always, which makes it stuck forever at the current level. Possibly related to rate table computations, or the conditions of phase transitions.

freq-mod commented 5 years ago

It also likes to cut short decay and release phases too... https://instaud.io/3nXA - open hi-hat played on Neko Project 2 emu https://instaud.io/3nXC - the same hi-hat played on pmdwin

freq-mod commented 4 years ago

Hello. New version of PMDWin is released, with greatly improved SSG-EG emulation and few other fixes: pbarfuss/PMDWinS036#1

Wohlstand commented 4 years ago

@freq-mod , uh ty, klawo! Muszę natychmiast sprawdzić, co tam jest... :eyes: [Oh, wow, I should check out, what is now at that...] P.S. because of some my friend in Telegram, I trying to learn jazyk polski, it's not hard for me :fox_face:

Wohlstand commented 4 years ago

@jpcima , can you remind me, did you some own fixes on current PMDWin thing? In my memory, you did some fixes here to make it work independently if I'm not mistaken.

jpcima commented 4 years ago

Hi, I did usual things that we apply, like custom panning, but also you can check libOPNMIDI marked comments for full detail. I don't remember the whole story of it since it was long ago. There remained an envelope-related problem I haven't managed fixing.

There is this one which is notable.

/* libOPNMIDI: prevent FM channel clipping (TODO: also adjust PSG and rhythm) */