how can i do music on megadrive?

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

Moderator: BigEvilCorporation

Eke
Very interested
Posts: 884
Joined: Wed Feb 28, 2007 2:57 pm
Contact:

Post by Eke » Thu Aug 23, 2007 9:21 am

Hi, I'm currently looking into the MAME YM2612's core and have a little question about the YM2612 chip:

according to Sega documentation, both Channels 3 and 6 have the capability to have full separated frequencies for each 4 operators, by setting bit6 in register 27h (Part 1). Although this bit is named 'CH3 MODE' , this seems logic to me as registers A8h-ACh (used to set the extra frequencies for CH3 ops) also exist on Part2 side, which control Channels 4 to 6

however, in the Mame FM core, this feature is only emulated for Channel 3 (writing registers A8h-ACh in Part 2 do nothing and Channel 6 is always refreshed like any other channel)

So, which is right ?

I didn't have modified the Fm core yet to support channel 6 "special mode" but I was wondering if current sound weirdness in some games (some percussion sounds for example) might come from this eventual missing feature ?

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

Post by TmEE co.(TM) » Thu Aug 23, 2007 11:53 am

Samples are usually played form ROM (through z80 bank), but I'm pretty sure there's games that have some in z80 RAM... you can't fit much in there, 8KB is not much...
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

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Thu Aug 23, 2007 8:38 pm

TmEE co.(TM) wrote:Samples are usually played form ROM (through z80 bank), but I'm pretty sure there's games that have some in z80 RAM... you can't fit much in there, 8KB is not much...
Yeah, I would say most digital samples are played from ROM - to play from RAM, you'd have to copy the data to the RAM first, and as TmEE remarks, there's not much of that. Setting the ROM bank the Z80 reads is quick compared to the sample period of the audio, so even when you run out of space in the bank you use to read the ROM, you just quickly switch the bank to continue reading more, so samples are now limited by the total size of the ROM, not the space in the Z80 memory.

Eke
Very interested
Posts: 884
Joined: Wed Feb 28, 2007 2:57 pm
Contact:

Post by Eke » Fri Aug 24, 2007 7:56 am

Maybe it's also possible to access the 68K RAM through the bank ? So you would have even more space to store your samples :?:

from gen-hw.txt:
2.3) Banking
...
In my own tests, I've been unable to do the following:

- Read banked 68000 RAM. (returns FFh)
- Find result of partial writes to the bank address register.
- Have the Z80 read A00000-A0FFFF through the banked memory area.
(locks up the machine)

Steve Snake informed me that reading 68000 RAM is possible, but is not a recommended practice by Sega. Perhaps only some models of the Genesis allow for it.

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

Post by TmEE co.(TM) » Fri Aug 24, 2007 9:09 am

Thing is, that it won't work... and I think there is no reason to waste RAM on samples because you use banking anyway and it works on ROM and with good code like I've written, you can have up to 110KHz sampling rate (which is little too much, real HW can handle only 70KHz for a short period of time, and I'm pretty sure that everything after 33KHz(if you wait before chip is ready, busy flag... this might interest Eke) won't make any difference (samples get missed I supose). I need to learn to write shorter sentences :wink:
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

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

Post by Shiru » Sat Aug 25, 2007 5:47 pm

TmEE co.(TM) wrote:real HW can handle only 70KHz for a short period of time, and I'm pretty sure that everything after 33KHz(if you wait before chip is ready, busy flag... this might interest Eke) won't make any difference (samples get missed I supose)
Maybe, I said somethere on this forum already. I assume that it can depends from YM2612 output DAC frequency itself. Some of YM2xxx chips has no internal DAC, and send output data to external DAC with fixed samplerate (YM3812 uses 49KHz, for example). I think, YM2xxx with built-in DAC, like YM2612, works same way, and DAC mode of channel 6 just replaces output from channel operators with value from #2A register, so it's not possible to get samplerate higher than built-in DAC has.

Eke
Very interested
Posts: 884
Joined: Wed Feb 28, 2007 2:57 pm
Contact:

Post by Eke » Sun Aug 26, 2007 8:39 am

Shiru, as you seem to know YMxxx chips pretty well, do you know if CH3 special mode (where each four operator can have a separate frequencie), also apply to CH6 (DAC disabled) when setting bit6 in register 27h ?

Sega's devellopper manual tell so and this seems logic as "Part II" is only a duplication of 30H - B4H, where channels 1-3 are replaced by 4-6 but emulators out there only seem to support this feature for Ch3 :?:

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

Post by Shiru » Sun Aug 26, 2007 9:04 am

Eke wrote:Shiru, as you seem to know YMxxx chips pretty well, do you know if CH3 special mode (where each four operator can have a separate frequencie), also apply to CH6 (DAC disabled) when setting bit6 in register 27h ?

Sega's devellopper manual tell so and this seems logic as "Part II" is only a duplication of 30H - B4H, where channels 1-3 are replaced by 4-6 but emulators out there only seem to support this feature for Ch3 :?:
I don't know, but if somebody with real hardware can help (run 1-2 test programs), it's easy to test.

However, I think, Ch6 has special mode too. We already know that MAME emulation of OPN chips is not perfect.

Eke
Very interested
Posts: 884
Joined: Wed Feb 28, 2007 2:57 pm
Contact:

Post by Eke » Sun Aug 26, 2007 10:43 am

Yes, even if this seem correct enough for most games. But there are also some game musics that sound completely wrong, something like high-frequency blip sounds covering the original music. Try for example Flashback bgm3 in sound test, actually only Kega with HQ mode activated could handle this correctly... even Gens with FM Interpolation ON sound weird on this one.

Do you know what might cause such harsh blips ? bad frequency calculations, unacurrate sampling ... ?


I also wonder about bit7 in the same register (27h), undocumented in sega's doc but refered as CSM Key control in MAME. This switch all operators in Channel 3 to Key OFF when TimerA expires (i wonder why) but this behaviour is documented as being "wrong at the moment" in the sourcecode.

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

Post by Shiru » Sun Aug 26, 2007 11:45 am

Eke wrote:Try for example Flashback bgm3 in sound test, actually only Kega with HQ mode activated could handle this correctly... even Gens with FM Interpolation ON sound weird on this one.

Do you know what might cause such harsh blips ? bad frequency calculations, unacurrate sampling ... ?
I don't know exactly. Something strange, seems this instrument does not use anything special, just usual melodic instrument. So possibly it because unaccuracy sampling, and combination of parameters of this instrument with given frequency can produce such distorted sound.

Interesting thing, according to GensKMod, Flashback sometimes uses separate keyons for operators.
Eke wrote:I also wonder about bit7 in the same register (27h), undocumented in sega's doc but refered as CSM Key control in MAME. This switch all operators in Channel 3 to Key OFF when TimerA expires (i wonder why) but this behaviour is documented as being "wrong at the moment" in the sourcecode.
I think, that is because lack of real documentation, and coders assume that all chips in OPNx family has mostly same features. 'CSM' feature is present in YM2151, but as far as I know, it must key ON for all operators by timer A overflow. There is also some mess with name of feature, on YM3812 (OPL2) soundchip CSM is a something like 'Composite Sinusoidal Modeling' or 'Composite Sine-wave Speech Synthesis Mode' (enabled by bit 7 in register 08h).

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

Post by Stef » Sun Aug 26, 2007 12:01 pm

Shiru wrote:
Eke wrote:Try for example Flashback bgm3 in sound test, actually only Kega with HQ mode activated could handle this correctly... even Gens with FM Interpolation ON sound weird on this one.

Do you know what might cause such harsh blips ? bad frequency calculations, unacurrate sampling ... ?
I don't know exactly. Something strange, seems this instrument does not use anything special, just usual melodic instrument. So possibly it because unaccuracy sampling, and combination of parameters of this instrument with given frequency can produce such distorted sound.

Interesting thing, according to GensKMod, Flashback sometimes uses separate keyons for operators.
I searched a long time to understand what was wrong with my YM2612 core about this instrument. I tested it with Shaq Fu as this game uses in intensively. I still don't know how to fix the problem but i'm pretty sure it's a sort of "bug" from the real YM2612 with certains settings...

Eke
Very interested
Posts: 884
Joined: Wed Feb 28, 2007 2:57 pm
Contact:

Post by Eke » Tue Aug 28, 2007 1:57 pm

Stef wrote:I still don't know how to fix the problem but i'm pretty sure it's a sort of "bug" from the real YM2612 with certains settings...
well, I owned Flashback when I had my MegaDrive and the incriminated soundtrack (BGM3 in soundtest) never sounded like that. :wink:

The fact is that if listening this track in Kega, turning "YM2612 HQ" option ON definitively makes all these noisy "blips" disappear, where as they are still present when this option is disactivated.

I don't know what "YM2612 HQ" does exactly but it maybe something similar to what you did in Gens (emulating the soundchip at the original rate, i.e VCLK/144, approx. 53270Hz) except that it also applies some kind of additional resampling (using appropriate FIR interpolation + decimation filters) to output at the given soundrate (44100 hz) ?

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

Post by Stef » Tue Aug 28, 2007 4:32 pm

Eke wrote:
Stef wrote:I still don't know how to fix the problem but i'm pretty sure it's a sort of "bug" from the real YM2612 with certains settings...
well, I owned Flashback when I had my MegaDrive and the incriminated soundtrack (BGM3 in soundtest) never sounded like that. :wink:

The fact is that if listening this track in Kega, turning "YM2612 HQ" option ON definitively makes all these noisy "blips" disappear, where as they are still present when this option is disactivated.

I don't know what "YM2612 HQ" does exactly but it maybe something similar to what you did in Gens (emulating the soundchip at the original rate, i.e VCLK/144, approx. 53270Hz) except that it also applies some kind of additional resampling (using appropriate FIR interpolation + decimation filters) to output at the given soundrate (44100 hz) ?
Yes, HQ does calculation at the YM2612 rate then extrapolate to the output rate (44100 Hz).
But there is something more needed to reproduce correctly this sound...

Eke
Very interested
Posts: 884
Joined: Wed Feb 28, 2007 2:57 pm
Contact:

Post by Eke » Tue Oct 09, 2007 4:44 pm

I recently made some testing about this YM2612 "bug" and discovered the following (I'm probably not the first one discovering this but I hope we could finally managed to understand how the "bug" really work):

1/ every game producing this noisy sound on emulators seem to use the same sound engine: GEMS . I suppose they all use the same preprogrammed instrument (don't found anything in GEMS documenation about these). So, this instrument probably use some kind of particular configuration which make use of a bug in real YM2612 to sound correctly on real hardware only.

2/ to my surprise, on real Hardware (megadrive 2 PAL), the same "blip" sound is present, the only difference being it is a lot more attenuated, compared with emulators. I tested both Shaq Fu (quite every music use this instrument) and Flashback (BGM #3 in sound test) and could hear it if I set the TV volume high enough.

This makes me think that the "bug" has something to do with TL values not being handled properly in certain condition (emulators handle this as the chip should normally do, which make this "blip" sounds a lot too loud)

I wonder what else could affect the output amplitude ? according to GensKMod, LFO AM seems not to be activated .

3/ then , I tested the Flashback VGM's track with in_vgm plugin to isolate the incriminated channel (hehe, that could be a nice addition to GensKMod) and found that the noisy blip sound was comming from Channel 3.

4/ Finally I run the above games under KgensMod and Genesis Plus, looking into Channel 3 configuration for some similarities when hearing the infamous "blip sound". Here are the most noticable coincidences between games:

- there are no LFO effects used (AMS nor FMS)
- Channel 3 is always configured to "special" mode
- Channel 3 algorithm is always algorithm #4 (feedback value = 4)
- Channel 3 operator 2 (which is used as output in this algorithm) has TL value always set to 0, which is the max amplitude.

I also noticed that the soundtracks that don't produce this bad sound never use a "zero" value in the operator 2 TL register so maybe the bug has something to do when using this value in this special channel ?

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

Post by TmEE co.(TM) » Wed Oct 10, 2007 5:21 am

My MD2 doesn't do this "blip" sound...
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

Post Reply