VST using Gens ym2612 emulation

For anything related to sound (YM2612, PSG, Z80, PCM...)

Moderator: BigEvilCorporation

superjoebob
Very interested
Posts: 66
Joined: Fri Oct 15, 2010 7:06 am
Location: Vancouver, Canada
Contact:

VST using Gens ym2612 emulation

Post by superjoebob » Fri Oct 15, 2010 7:38 am

Hi everybody!
I've been to hell and back over the last year trying to find something that accurately emulates the YM2612 for my music, but after trying VOPM, Various other FM Synths, some sound fonts, and even TFM Music Maker I've come to the conclusion that there is simply no good way emulate the YM2612 for music composition purposes right now.

What I want to do is create a VST using Stéphane Dallongville's YM2612 emulation code (from Gens, ym2612.h/.c ). I have a good deal of programming experience and a little VST/Digital Audio knowledge so it's not general programming help I'm looking for, but instead I was hoping someone could help me with the basics of how to use the code. I've spent hours going through it and going through how it works with gens, but I just cant seem to make any progress. I'm not familiar with electronics, i.e. with how something like the YM2612 works. I understand the idea behind FM Synthesis, and I've read various sites/documents on the 2612 so I know what sort of things I want to get the chip to do, but I have no idea how to do anything useful with the software emulation of the chip.

So pretty much what I'm curious about, is how to initialize the chip, how to set up a basic instrument, and how to get wave information from all its channels. Even just an explanation on how to make the thing simply make a noise( return simple wave output ) would be greatly appreciated :D.

Also, Stef, if you're still around on these forums I would be endlessly appreciative if you could help me out on this one, since you probably know best how it works. Whether or not you are still on the forums, thank you for creating my favorite ym2612 emulation.

Thanks in advance, I would kill for a proper ym2612 VST, so making one seems like all there is to do :P.
Last edited by superjoebob on Fri Nov 12, 2010 1:45 am, edited 1 time in total.

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Re: VST using Gens ym2612 emulation

Post by Shiru » Fri Oct 15, 2010 10:50 am

superjoebob wrote:find something that accurately emulates the YM2612
...
What I want to do is create a VST using Stéphane Dallongville's YM2612 emulation code (from Gens, ym2612.h/.c ).
Do you aware that this code is not accurate, probably less accurate than in VOPM etc?

TmEE co.(TM)
Very interested
Posts: 2442
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Fri Oct 15, 2010 2:21 pm

I've got quite some experience with FM, especially in MD context (both HW and software side) and I'm even going to say that TFM has more accurate FM emulation than Gens does. Cannot comment about VOPM but it should be rather good aswell, though not for same family chip.
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Fri Oct 15, 2010 3:34 pm

As mentionned just above Gens YM2612 core is definitly not the most accurate one, today you have a lot of better FM cores.
Did you checked this topic :
viewtopic.php?t=386
It's *the place* where you can find all technicals stuff about YM2612.
YM2612 uses FM synthesis, you have to really know how FM synthesis work before doing anything with YM2612. To be honest the YM2612 was the last thing i wrote in Gens, it just tough me many many time before understanding and writing a working YM2612 core (i learnt a lot from the MAME FM core).

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Fri Oct 15, 2010 3:46 pm

I think, it would be good idea to put YM2612 emulation code into some DLL, not hardcode it into VSTi. This way you can use any emulation code for start, and when some better emulation core arrive, you or someone else can easily add it. Two good cores aren't open source (Kega and Regen), but with external interface their authors could provide you with the DLL without giving the source code.

You'll need just few external calls for such a DLL: render function (pointer to a buffer, number of samples), register read, register write.

superjoebob
Very interested
Posts: 66
Joined: Fri Oct 15, 2010 7:06 am
Location: Vancouver, Canada
Contact:

Post by superjoebob » Fri Oct 15, 2010 5:41 pm

TmEE co.(TM) wrote:I'm even going to say that TFM has more accurate FM emulation than Gens does. Cannot comment about VOPM but it should be rather good aswell, though not for same family chip.
Shiru wrote: Do you aware that this code is not accurate, probably less accurate than in VOPM etc?
VOPM's similarity to the YM2612 is disappointing, it cannot faithfully reproduce most of my favorite 2612 instruments. Maybe I'm just nit picking, but it does emulate a different chip than the 2612 and although they are similar they have differences that I simply can't ignore. As for TFM, I agree that it's got much better emulation, but I pretty much dropped it when I realized it had no panning capability. I always listened to the Genesis through headphones, and in my opinion playing with the left and right channels is a staple of good Genesis music. That, and the fact that it's not a VST so it requires me to track everything instead of writing music the way I'm accustomed.
Stef wrote:As mentionned just above Gens YM2612 core is definitly not the most accurate one, today you have a lot of better FM cores.
Did you checked this topic :
viewtopic.php?t=386
It's *the place* where you can find all technicals stuff about YM2612.
YM2612 uses FM synthesis, you have to really know how FM synthesis work before doing anything with YM2612. To be honest the YM2612 was the last thing i wrote in Gens, it just tough me many many time before understanding and writing a working YM2612 core (i learnt a lot from the MAME FM core).
The reason I chose this core is because I've been listening to a lot of VGM's in Win-Amp using inVGM, and they sound great. 100 times more ym2612 than any VSTI I've been able to get my hands on. I have seen that post you provided, although my ability to comprehend the documents is limited :P. To my understanding I have to write bytes to the register, then read what it has to say about what I wrote. The reason I asked for a simple explanation of how to make the chip make a simple noise, is because I learn by example. I believe that if I saw the outcome of simple interaction with the chip, it would allow me to put together all the pieces and figure out how it works entirely.
Shiru wrote:I think, it would be good idea to put YM2612 emulation code into some DLL, not hardcode it into VSTi. This way you can use any emulation code for start, and when some better emulation core arrive, you or someone else can easily add it. Two good cores aren't open source (Kega and Regen), but with external interface their authors could provide you with the DLL without giving the source code.

You'll need just few external calls for such a DLL: render function (pointer to a buffer, number of samples), register read, register write.
This would also make the VST code much cleaner, and I think it's definitely a good path to take on this one. Good call :wink:.

Like you said, with the DLL I could easily change what emulation code it's using, so I guess it's not too terribly important anymore which emulation I use. Another reason I want to stick with the Gens core, though, is because I actually have a place to ask specific questions about it to it's creator. On the other hand, Shiru, I don't suppose the ym2612 code in your TFM Maker is open source:D?

superjoebob
Very interested
Posts: 66
Joined: Fri Oct 15, 2010 7:06 am
Location: Vancouver, Canada
Contact:

Post by superjoebob » Fri Oct 15, 2010 5:42 pm

Whoops, double posted and quoted what I said previously some how. Sorry about that.
Last edited by superjoebob on Fri Oct 15, 2010 6:33 pm, edited 1 time in total.

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Fri Oct 15, 2010 5:54 pm

YM2203 emulation code in TFM MM is from MAME, which is open-source, and it is also available in /replayers/pc/mame in the TFM MM package.

You should think about channels management in VSTi - will you have six channels and some way to select one of them, or just one, and will have multiple instances of the VSTi (I use VOPM this way, actually, because this way it is easier to apply different sound processing to different instruments), and how you will manage polyphony.

Btw, TFM MM actually supports the YM2612 panning, it is just not audible in the editor. You have to export the song as VGM, and then you'll hear the panning using any VGM player/plug-in (there were some with Gens sound core, as far as I remember), or real hardware.

superjoebob
Very interested
Posts: 66
Joined: Fri Oct 15, 2010 7:06 am
Location: Vancouver, Canada
Contact:

Post by superjoebob » Fri Oct 15, 2010 6:29 pm

Shiru wrote: Btw, TFM MM actually supports the YM2612 panning, it is just not audible in the editor. You have to export the song as VGM, and then you'll hear the panning using any VGM player/plug-in (there were some with Gens sound core, as far as I remember), or real hardware.
Good to know, although it doesn't help much while composing music :wink: . Suppose it just requires a lot of trial and error.
Shiru wrote: You should think about channels management in VSTi - will you have six channels and some way to select one of them, or just one, and will have multiple instances of the VSTi (I use VOPM this way, actually, because this way it is easier to apply different sound processing to different instruments), and how you will manage polyphony.
I'm going to be going down the same path as VOPM for this one, with 1 channel and multiple VST's. Haven't really thought about polyphony management, I guess I'll tackle that problem as it arises.

For the purpose of figuring out whether or not I have the knowledge to create a VST for something like this, I'm going to stick to the Gens core since I've been messing around with it the most and it's the one I'm most comfortable with right now. I assume any other core would operate in the same way, but why mess with what I'm used to, right? I may end up changing cores when I'm finished.

I took a look at some ASM using the 2612 hardware in that topic that you pointed me to, Stef, and I actually ended up learning quite a bit by cross referencing what Nemesis was doing with the chart posted on page 1.

I brought over most of what the ASM was doing and this is what I came up with:

Code: Select all

int Sound_Rate = 22050;
int Clock_NTSC = 53693175;
//0 for standard eulation, 1 for high quality//
YM2612_Improv = 0;
///////////////////////////////////////////////

ym2612__ ym2612;
YM2612_Init( Clock_NTSC / 7, Sound_Rate, YM2612_Improv );

int* buf[2];
int SegL[882];
int SegR[882];

buf[0] = SegL;
buf[1] = SegR;

int SegLength = 882;

YM2612_Write(0xB2, 0x07);//Set algorithm to 7 ( 4 channel parallel )
YM2612_Write(0xB6, 0xC0);//Set L/R, AMS/PMS

//Initialize channel 3 op 4 with an instant on/instant off envelope
YM2612_Write(0x4E, 0x00);//Set TL
YM2612_Write(0x5E, 0x1F);//Set KS/AR
YM2612_Write(0x6E, 0x00);//Set AM/DR
YM2612_Write(0x7E, 0x00);//Set SR
YM2612_Write(0x8E, 0x0F);//Set SL/RR
YM2612_Write(0x9E, 0x00);//Set SSG-EG

//Set DT/MULTI with no detune
YM2612_Write(0x3E, 0x00);//No detune

//Set channel 3 frequency
YM2612_Write(0xA2, 0x10);
YM2612_Write(0xA6, 0x10);

//Set key on
YM2612_Write(0x28, 0xF2);
YM2612_Update(buf, SegLength);
int val = YM2612_Read();
Using this and variations of this I can't seem to get a wave output from channel 3. Don't suppose one of you could point me in the right direction? :)

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Fri Oct 15, 2010 7:29 pm

superjoebob wrote:
Shiru wrote: Btw, TFM MM actually supports the YM2612 panning, it is just not audible in the editor. You have to export the song as VGM, and then you'll hear the panning using any VGM player/plug-in (there were some with Gens sound core, as far as I remember), or real hardware.
Good to know, although it doesn't help much while composing music :wink: . Suppose it just requires a lot of trial and error.
There are just three possible pan settings (left/center/right), and you don't have to change it often, so no - it is easy enough (and I've done this few times for game music, actually). Most games on SMD even aren't change the instruments or panning during single song, they set everything up at start of the song. Some do this (Konami's and Zyrinx titles, for example), but it is not too common.

I should note that a lot of people making SMD music, using either VOPM, TFM MM (+VGM plug-ins, +real hardware, +actual cartridge releases), or some other solutions (MML, MIDI), and no one really complain about authenticy of the sound of emulated solutions, or panning control - it is good enough, so it is just you, being too picky, create problems for yourself. Not a bad thing, though, because if you'll make another one VSTi, everyone only wins from that.

superjoebob
Very interested
Posts: 66
Joined: Fri Oct 15, 2010 7:06 am
Location: Vancouver, Canada
Contact:

Post by superjoebob » Sat Oct 16, 2010 9:53 pm

Shiru wrote: I should note that a lot of people making SMD music, using either VOPM, TFM MM (+VGM plug-ins, +real hardware, +actual cartridge releases), or some other solutions (MML, MIDI), and no one really complain about authenticy of the sound of emulated solutions, or panning control - it is good enough, so it is just you, being too picky, create problems for yourself. Not a bad thing, though, because if you'll make another one VSTi, everyone only wins from that.
Call me a purist but I wont be happy until I'm using an instrument that's actually emulating what I want to be emulating :D . I'd build a hardware synthesizer myself without any second thoughts if I had any electronics knowledge, but unfortunately I don't.

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Sat Oct 16, 2010 10:05 pm

You don't need to build anything to get the real sound. Make a song using any software for SMD music (TFM MM, MVST, MML), get a VGM file, play it using Flash cart on the real console. Also, I've seen songs marked with SMD MIDI interface at 8bc and ChipMusic, so seems there is another option for real sound.

If you can hold a soldering iron, there are few simple schematics how to connect YM2612 to PC through LPT, i.e. you don't need to design hardware, only build it.

superjoebob
Very interested
Posts: 66
Joined: Fri Oct 15, 2010 7:06 am
Location: Vancouver, Canada
Contact:

Post by superjoebob » Sat Oct 16, 2010 11:50 pm

Shiru wrote: If you can hold a soldering iron, there are few simple schematics how to connect YM2612 to PC through LPT, i.e. you don't need to design hardware, only build it.
Do you know where these are? I've looked around a lot but can't seem to find anything like this. I would probably die from joy if I could compose music using the real hardware :P.

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Sun Oct 17, 2010 12:32 am

One schematics, YM2612 to LPT, is in NedoPC #4 magazine, page 14. There was software for playing GYM/VGM, don't know where it is now. There is a problem with such devices under Windows - if you access them from app, Windows can introduce delay between two writes, and you'll get sound glitch (first write applied, unexpected sound generated when the delay lasts, second write applied, expected sound generated). So you need to make and run a player under MS-DOS (not in Windows), or make a driver.

Other thing I can found now is not for LPT, it is USB adapter for a lot of chips. Here is the website, the problem it is in Japanese. As I've understood, it uses some ready-made kit 'MINI EZ-USB', an bus adapter (two 74HCT245), and plug-in boards with different chips. Can't tell where is the software for this thing, probably it somewhere at the website. This is the bus adapter, and this is YM2612 board.

superjoebob
Very interested
Posts: 66
Joined: Fri Oct 15, 2010 7:06 am
Location: Vancouver, Canada
Contact:

Post by superjoebob » Tue Oct 19, 2010 8:19 pm

That's some pretty cool stuff, I've already some chips coming in the mail to try it out :D. To get a quick fix though, I bought a flash cart and I'm going to try and port one of my songs over to TFM so I can play the song on real hardware.

Just a few questions about TFM, how do I set the notes to left and right panning, and is it possible to use sampled instruments like drums in TFM? If not, how can I get drums into my VGM files?

Post Reply