######## POST p5485 | Nemesis | 2008-06-06 | t386-000.html As anyone who's tried to emulate it will know, there's a significant lack of solid information on the YM2612. The only official reference we have comes from 14 pages in the Genesis Sound Software Manual ( http://nemesis.hacking-cult.org/MegaDri ... Manual.pdf ), and they're a little light on the details. There are some manuals out there for other Yamaha FM chipsets, but the problem is there are a LOT of different "lines" of FM chips that Yamaha released, such as the OPL, OPN, OPM, OPZ, etc. The YM2612 is an OPN chip, and all the documents which are publicly available are for chips from entirely different lines. Thanks to Malfunction from http://www.soundshock.se , we've now got something which could fill this gap. Here's a link to an official document from Yamaha describing the YM2608: http://nemesis.hacking-cult.org/MegaDri ... M2608J.PDF This is the first time this document has been publicly posted on the internet. This isn't just a datasheet, it's a complete Programming/Technical Reference Manual, weighing in at 67 pages. It's full of hard numbers, tables, and equations. There is a catch however: The manual is in Japanese. I wouldn't hold out for an official version in English. There's a good chance this document was never fully translated from Japanese, even by Yamaha. We've got the information now though. The language barrier can be solved with time and the help of the right people. The language issue aside, as you'll note, this document is for the YM2608 not the YM2612. This leads to the question, what are the differences between the YM2608 and the YM2612? I've been doing a fair bit of research on this, and the news is good. Here's a list of the all the known Yamaha OPN chips: -YM2203 (OPN) -YM2608 (OPNA) -YM2610 (OPNB) -YM2612 (OPN2) -YM3438 (OPN2C) (CMOS implementation of the YM2612. Functionally identical) -YMF288 (OPN3) As you can see, both the YM2612 (OPN2) and YM2608 (OPNA) are part of this line. More significantly, after comparing information about all these OPN chips, and particularly after looking through this new manual, it seems that the YM2608 is the direct and immediate ancestor of the YM2612. More than that, the YM2612 seems to just be a "stripped down" version of the YM2608. The documentation for the YM2608 may in fact be better than an official YM2612 reference, as it contains a description of all the features they removed, while still containing all the information on the features provided by the YM2612. The YM2608 came in a 64-pin package, and required a separate DAC (YM3016) in order to actually produce an analog sound output. The goal of the YM2612 seems to have been to provide a lower cost single-chip solution for systems which didn't require all the features of the YM2608. It seems the parts to get the chop were external I/O Ports, a Rhythm generator with internal ROM samples, a full ADPCM module, and the SSG module (well, most of it anyway [IMG ./images/smilies/icon_smile.gif]). Apart from the addition of DAC registers at 0x2A/0x2B to provide some basic PCM without the ADPCM module, everything in the YM2612 seems to be unchanged from the YM2608 implementation, meaning the YM2608 manual above should be extremely relevant. I was sent a number of other documents along with this one. There's a datasheet and some info on the YM3016 DAC, the ADPCM module in the YM2608, a short document on the YMF288, and a full manual on the "86 Sound Board" for the PC-9801-86, which uses a YM2608. One tidbit the 86 Sound Board manual seems to have which I didn't see in the doc from Yamaha is timing information on the busy flag in the status register. Here's the full archive I got sent: http://nemesis.hacking-cult.org/MegaDri ... YM2608.ZIP Hopefully some of you will find this info useful. I know I will. ...So, anyone read Japanese? [IMG ./images/smilies/icon_biggrin.gif] EDIT: Here's a transcribed and translated version using an online translator: http://nemesis.hacking-cult.org/MegaDri ... slated.PDF ######## POST p5486 | TmEE co.(TM) | 2008-06-06 | t386-000.html This is incredible [IMG ./images/smilies/icon_biggrin.gif] And now I've got another reason to learn Japanese [IMG ./images/smilies/icon_smile.gif] I hope this gets translated someday, I somehow feel it contains all the answers to the issues I've encountered while writing my sound engine (and I think Steve Snake knows a lot, since he's emulator does emulate ALL the quirks I've encountered 1:1 to real HW). ######## POST p5488 | Oerg866 | 2008-06-06 | t386-000.html I think that's not quite correct, if you check out the ending sound of MicroMachine96's SuperSonic intro screen, that is totally messed. ######## POST p5490 | TmEE co.(TM) | 2008-06-06 | t386-000.html Gimme a link... so far, all has been 1:1 to my audio-modded MD2 sound. ######## POST p5495 | Nemesis | 2008-06-07 | t386-000.html One interesting thing to note about this document is the numbering of the operators. In the Genesis document, we know they've got operators 2 and 3 switched somewhere, either in the register map or in the operator connection charts. Generally, we switch operators 2 and 3 in the connection charts to fix the problem. It's interesting to note from this document however, that the operator numbering in the chart is correct. According to this document, it's the register order numbers which are switched. [IMG http://nemesis.hacking-cult.org/MegaDrive/Documentation/operators.png] [IMG http://nemesis.hacking-cult.org/MegaDrive/Documentation/operator%20registers.png] Notice that the register order is S1, S3, S2, S4. Of course, the two numbering systems are functionally equivalent, it's just interesting to note the "official" order numbers they use. ######## POST p5496 | 1magus | 2008-06-07 | t386-000.html People have problems emulating this or writing games while using it? ######## POST p5497 | AamirM | 2008-06-07 | t386-000.html Hi, Thanks a lot Nemesis! You just made my day. I can try to get some of my japanese friends to translate it. I've been trying to get some sound problems in my core fixed without any success but I guess this will help me. This is a huge find. Thanks again. stay safe, AamirM ######## POST p5498 | Stef | 2008-06-07 | t386-000.html Of course i don't read japanese but from schems i don't see anything news compared to the sega manual. Maybe japanese comments are importants though [IMG ./images/smilies/icon_wink.gif] ######## POST p5499 | Nemesis | 2008-06-07 | t386-000.html There's quite a bit of stuff in there which isn't covered in the Sega documentation, like self-feedback, conversion to real frequencies, the actual way sounds are generated and operators are combined, etc. And of course there's lots of misc stuff like SSG-EG and the test register which aren't included in the Sega documentation. Just have a close look at pages 15 and 16. I really wish I could read those pages. ######## POST p5500 | Eke | 2008-06-07 | t386-000.html yes, but doesn't every chip differ in term of frequencies value, internal conversion tables, etc... I think I've seen the YM2413 and YM2149 programmer manuals somewhere with lot of value tables but they can not be used for the YM2612 for example About the SSG, the interesting part is that it uses the same register location and envellope shape is pretty well explained, but this does not mean that YM2612 has SSG working the same way, same thing about CHM mode, why didn't they even mentionned these features in the YM2612 "short" manual if it was working ? probably because it was only partially working and "broken" in some way... anyway, this is really exciting news, big thanks to everyone who participated in releasing it, I'm definitely waiting for a translation PS: about operator combination, I don't think there is something new or different from the way it is actually emulated, we already discussed about that somewhere on this board and this is only a matter of naming convention (M1,C1,M2,C2 or OP1, OP3, OP2, Op4 or S1, S2, S3, S4) ######## POST p5504 | Nemesis | 2008-06-07 | t386-000.html [QUOTE] yes, but doesn't every chip differ in term of frequencies value, internal conversion tables, etc... I think I've seen the YM2413 and YM2149 programmer manuals somewhere with lot of value tables but they can not be used for the YM2612 for example [/QUOTE] That's the reason this manual is so significant: The FM process seems to be identical between the two chips. As I said, the YM2612 is a "stripped down" version of the YM2608. They cut out extra self-contained modules like ADPCM and simplified its external connections, but it seems they left the FM module untouched. The YM2612 is little more than the YM2608 FM module in a different box. By all means, prove me wrong, but I've looked into this enough now to be convinced of this point, and nothing I've seen in the documentation so far suggests otherwise. [QUOTE] About the SSG, the interesting part is that it uses the same register location and envellope shape is pretty well explained, but this does not mean that YM2612 has SSG working the same way, same thing about CHM mode, why didn't they even mentionned these features in the YM2612 "short" manual if it was working ? probably because it was only partially working and "broken" in some way... [/QUOTE] There could be a number of reasons for this. The Genesis sound manual is written by Sega, not Yamaha. The Genesis sound manual is based on the Japanese "Mega Drive" sound manual. The Japanese sound manual was written based on the information Yamaha provided to Sega. You've got three organizations involved there, plus the language barrier, plus the fact that we know that Sega of America and Sega of Japan had very poor communication with each other. All we know is what is written in the Genesis sound manual, which is this: [QUOTE] SSG-EG - A proprietary register whose usage is unknown. It should be set to zero. [/QUOTE] That seems to say to me quite clearly that the people writing this manual simply didn't know what it was for. I'd say that information either wasn't passed on from SOJ to SOA, or it wasn't passed on from Yamaha to SOJ in the first place. This idea of SSG-EG being "buggy" in the YM2612 seems unfounded to me. I don't know where that rumor came from, but I've certainly never seen a case presented, or even a case mentioned, where SSG-EG has been seen to play up. It's quite possible they were officially "unsupported" features of the chip (IE, they were only included because it wasn't worth removing them), but in terms of being buggy, I'm not convinced of that at all. [QUOTE] PS: about operator combination, I don't think there is something new or different from the way it is actually emulated, we already discussed about that somewhere on this board and this is only a matter of naming convention (M1,C1,M2,C2 or OP1, OP3, OP2, Op4 or S1, S2, S3, S4) [/QUOTE] Yes, it really doesn't make a difference what they're called or how they're numbered. I just find it interesting to know how they designated them. I like to use the "official" names and designations for things where possible. ######## POST p5505 | Shiru | 2008-06-07 | t386-000.html [QUOTE] Eke wrote:I think I've seen the YM2413 and YM2149 programmer manuals somewhere with lot of value tables but they can not be used for the YM2612 for example [/QUOTE] YM2413 is a OPLL, cut-down and very limited version of OPL1. It's different family, so of course information about this chip can't be used for YM2612. YM2149 is a slightly enhanced clone of AY-3-8910, it's not FM synth. It's quite simple and very well documented PSG chip. YM2203 has it as addition to FM part. FM part of OPN family chips is compatible in general (at least between YM2203, YM2610, YM2612), so documentation for any of chips of this family can be useful. ######## POST p5509 | AamirM | 2008-06-07 | t386-000.html Hi, Shiru is right. You can't use YM2413 info for YM2612 as it is different. I hope this manual contains those little details that I am looking for. First of all SSG-EG sounds different on all emulators so there is something that needs to be corrected here. Secondly there is the CSM key control which nobody seems to have a clue about. Thirdly I recently discovered (by listening to real hardware recordings and emulated sound) that in 3 slot mode, channel 6's envelope generator seems to speed up. I maybe wrong but this fixes sound in some games. BTW, I was told that Dune's soundtrack called 'Ammons Advice' doesn't sound correct in Kega either. Can't confirm it though. stay safe, AamirM ######## POST p5511 | Nemesis | 2008-06-08 | t386-000.html Well, there's a section in this manual about CSM on page 36. Here's what OCR + web-based Japanese to English translator has to say: [CODE] 2-8-4 Setting of mode of CH3 Channel 3 can set the mode by $27 “D7,D6". Table 2-1C CH3 mode ------------------------------------------------------------------------ |D7|D6|Mode | Ki E | |--|--|------------|---------------------------------------------------| | 0| 0|Normality |It pronounces normally as well as other CH. | |--|--|------------|---------------------------------------------------| | 0| 1|CSM |It becomes CSM voice synthesis mode, and F-Number | | | | |can be set each every of the four slots. Key-on/off| | | | |at the CSM mode is done with timer A. | |--|--|------------|---------------------------------------------------| | 1| 0|Effect sound|Separate F-Number can be set to each slot as well | | 1| 0| |as CSM. | ------------------------------------------------------------------------ [/CODE] That last row is probably suppost to be for bit patterns 10 and 11, but I've written it exactly as it appears in the document. ######## POST p5512 | Nemesis | 2008-06-08 | t386-000.html Hah, here's something I didn't know about the envelope generator: [QUOTE] *The shape of waves of the envelope changes in exponential when attacking it, and it changes in the straight line at other rates. [/QUOTE] Does anyone emulate this correctly? ######## POST p5516 | AamirM | 2008-06-08 | t386-015.html Hi, No. At least not in Regen. But I think the current linear approximation is good enough. stay safe, AamirM ######## POST p5524 | Stef | 2008-06-08 | t386-015.html [QUOTE] AamirM wrote:Hi, No. At least not in Regen. But I think the current linear approximation is good enough. stay safe, AamirM [/QUOTE] Correctly emulated in Gens as far i remember. ######## POST p5527 | AamirM | 2008-06-09 | t386-015.html Hi, Nice. I'll have a look at that. With what exponential relation does it rise? Do you have a formula? stay safe, AamirM ######## POST p5532 | Eke | 2008-06-09 | t386-015.html I'm curious, what is the SSG part mapped in registers 00-0Fh (which does not exist on YM2612). Otherwise, for keeping some record of it, I tried to list some of the new informations that we don't have in the first doc and that might applied to Ym2612 also: .Key OFF/ON register and operator assignation: [IMG http://gxdev.wordpress.com/files/2008/06/fm_1.gif] .Feedback values: [IMG http://gxdev.wordpress.com/files/2008/06/fm_5.gif] .SSG-EG register: [IMG http://gxdev.wordpress.com/files/2008/06/fm_2.gif] I imagine this could be quickly tested in a modified emu ? .Timer exact periods: [IMG http://gxdev.wordpress.com/files/2008/06/fm_3.gif] This confirms what we were initially thinking, internal clock is VCLK/144 and timerA period is half the internal period. We retrieve this value in FNUM calculation: [IMG http://gxdev.wordpress.com/files/2008/06/fm_6.gif] . CH3 special mode and "illegal" CSM mode: [IMG http://gxdev.wordpress.com/files/2008/06/fm_4.gif] we need some translation for this one [IMG ./images/smilies/icon_wink.gif] ######## POST p5534 | Stef | 2008-06-09 | t386-015.html [QUOTE] AamirM wrote:Hi, Nice. I'll have a look at that. With what exponential relation does it rise? Do you have a formula? stay safe, AamirM [/QUOTE] Enveloppe is defined in the "ENV_TAB", first part is for attack and i defined it as follow : [CODE BLOCK WITHHELD: 370 chars] As you can see i used x^8, i guess level 2 in vectorman was very sensitive to that (see the comment i left) [IMG ./images/smilies/icon_wink.gif] ######## POST p5535 | Shiru | 2008-06-09 | t386-015.html [QUOTE] Eke wrote:I'm curious, what is the SSG part mapped in registers 00-0Fh (which does not exist on YM2612). [/QUOTE] It is not related to FM synth or SSG-EG register. It's AY-3-8910/YM2149 part, same as in YM2203. I think, SSG-EG register named so just because it controls envelope in similar way like AY-3-8910 does. ######## POST p5536 | TmEE co.(TM) | 2008-06-09 | t386-015.html YM2612 timers in MD manual are all wrong. They're based on 8MHz not 7.6MHz and the Freq numbers for one octave's notes they had are all whipped off form this datasheet it seems, all wrong for MD. I had so much trouble getting the the value of the timer when I tried to have MD tracker and TMSE running at same speed... according to PC's PIT, the speed I got would be 49.4Hz, but the correct YM2612 calculation says its 49.9Hz... the PC runs faster with its 49.4 than MD with its 49.9 which makes no sense... ######## POST p5537 | Nemesis | 2008-06-10 | t386-015.html Fortunately, they do provide clock-independent formulas for calculating frequency values and timer intervals in this manual: [CODE] F-Number = (144 * fnote * 2^20 / M) / 2^(B-1) fnote: Frequency Data M: Master clock (Hz) B: Octave Data tA = 72 * (1024 - NA) / M NA: 0~1023 M: Master clock (MHz) tB = 1152 * (256 - NA) / M NB: 0~255 M: Master clock (MHz) [/CODE] EDIT: Note that the frequency calculation uses the clock frequency in Hz, while the timer calculations use the clock frequency in MHz. Also note the timer calculations are returning the timer interval in microseconds. You can see from the formulae that timer A counts down once every 72 clock pulses, and timer B counts down once every 1152 clock pulses (72 * 16). ######## POST p5538 | Nemesis | 2008-06-10 | t386-015.html Looking again at the Sega documentation, the formulae they provide for timer calculation are very different to the numbers from the YM2608 manual. [CODE] Timer A: 18 * (1024 - TIMERA) microseconds TIMER A = all 1's -> 18usec = 0.108ms TIMER A = all 0's -> 8400usec = 18.4ms Timer B: 288 * (256 - TIMERB) microseconds TIMER B = all 1's -> 0.288ms TIMER B = all 0's -> 73.44ms [/CODE] Comparing those simplified formulae to the ones in the YM2608 manual, Sega have either calculated these assuming a clock speed of 4MHz, or the dividers for the timers are different. It's quite possible the YM2612 has timers which have half the rate (144 clock pulses for Timer A, 144*16=2304 clock pulses for Timer B), and they've calculated for 8MHz. Can anyone confirm this? ######## POST p5539 | Eke | 2008-06-10 | t386-015.html here's the calculation I once made to find the exact timer period, however this is purely theorical: http://www.spritesmind.net/_GenDev//for ... .php?t=228 YM2612 is probably dividing input clock by 2: [QUOTE] 72/(VCLK/2/1000000) = 18.77 microseconds 1152/(VCLK/2/1000000) = 300.37 microseconds [/QUOTE] ######## POST p5540 | AamirM | 2008-06-10 | t386-015.html Hi, @ Stef Thanks a lot. @ Eke Nemesis has given a translation of CSM mode on the previous page. @ TmEE Could you please tell what quirks are you talking about besides the DAC? stay safe, AamirM ######## POST p5541 | TmEE co.(TM) | 2008-06-10 | t386-015.html Quirks are setting the "ganged" together registers backwards, previous instruments' settings affecting next instrument to some extent... It is very possible that YM2612 divides input clock by 2, as when I calculated the timer period, I got double result, ~100Hz instead of ~50Hz. ######## POST p5542 | AamirM | 2008-06-10 | t386-015.html Hi, Do you have some examples (audible) containing those quirks? I only have your DAC test program. stay safe, AamirM ######## POST p5544 | TmEE co.(TM) | 2008-06-10 | t386-015.html just make a small test proggy for MD, and listen in Fusion, it does ALL sound as real HW, all the various noises and such. ######## POST p5568 | Nemesis | 2008-06-15 | t386-015.html Ok, I've just completed a translation of this document, using the OCR function in Adobe Acrobat Professional, and a web-based Japanese translator at http://www.excite.co.jp/world/english which was recommended to me. I've been manually correcting OCR errors along the way, which in some cases meant looking through tables of several thousand Kanji, and bashing away at problem portions of the text until they made sense. I've preserved the page numbers of the original document, and largely preserved the original formatting. Yes, it took a lot of work. Here's the translated PDF: http://nemesis.hacking-cult.org/MegaDri ... slated.PDF The results are surprisingly good. The scans are clear enough and high resolution enough for the OCR to clean up. There was probably around a 99% success rate for the OCR, with most of the errors being simple accent problems. The web-based translator is also probably the best one I've seen. It's on a Japanese site, it only deals with English and Japanese, and it beats the Google translator into the ground. I haven't rewritten or restructured the output of the web translator, so some of it is a little backwards, but if you have a good grasp of English, the meaning should be clear in most cases. I'm not going to reword the output from the online translator, as I can't read Japanese, so I can't proof-check my translation against the original meaning of the text, and I don't want to risk losing any more information in the translation process. Note that pages 57-67 are not included in this translation. These pages aren't actually part of the main document, they're part of a separate document which is all about the physical properties of the chip, and the bus timings. Unfortunately, the quality of the scan is worse than the main document, and the font is different. The OCR doesn't cope nearly as well with it, so it would be slow and painful to translate, and I don't feel the urge to do it. These are probably different for the YM2612 anyway. You won't find anything important in this section though if you're just trying to emulate or use the YM2612. Anyway, hopefully this will open the document up for some more people to make use of. ######## POST p5569 | Eke | 2008-06-15 | t386-030.html thanks for the hard work [IMG ./images/smilies/icon_exclaim.gif] PS: just finished reading it, this is quite understandable or explain some nice stuff about FM synthethis, definitely what the official YM2612 manual should have been [IMG ./images/smilies/icon_wink.gif] I notice there was a register to disable CH4-CH6 and only process 3 channels, maybe someone could test it to see how the YM2612 behaves ######## POST p5592 | Nemesis | 2008-06-18 | t386-030.html Yeah, I noticed that. I have a feeling that register may not exist on the YM2612, as according to this documentation, the register defaults to 0, which would mean the chip would power up in 3 channel mode. It's definitely worth testing though. They might have just changed the default. There's also the interrupt control bits in that same register which I'd be interested in testing, even though the interrupt line of the YM2612 isn't connected in the Mega Drive. Another thing which is very interesting is the "Priscarar function" (phonetic for something?). It appears that writing to registers 0x2D, 0x2E, and 0x2F in the YM2608 adjusts the clock divider for the FM and SSG sound generation units. I'd be interested in testing whethter these registers have any effect on the YM2612. The thing I'm most interesting in solving once and for all with this new documentation is the cause of the unusual sound in Flashback, and several other Mega Drive games. There's some discussion about it in the following thread on this forum: http://www.spritesmind.net/_GenDev/foru ... =2699#2699 What we know is that this problematic instrument uses the channel 3 "special" mode, where a separate frequency is specified for each operator in the channel. I've been going through the documentation trying to get my head around all the implications of this mode, and here's what I've got so far. Here's what the new YM2608 manual says about this mode: [CODE] 2-8-4 Setting of mode of CH3 Channel 3 can set the mode by $27 “D7,D6". Table 2-1C CH3 mode ------------------------------------------------------------------------ |D7|D6|Mode | Function | |--|--|------------|---------------------------------------------------| | 0| 0|Normality |It pronounces normally as well as other CH. | |--|--|------------|---------------------------------------------------| | 0| 1|CSM |It becomes CSM voice synthesis mode, and F-Number | | | | |can be set each every of the four slots. Key-on/off| | | | |at the CSM mode is done with timer A. | |--|--|------------|---------------------------------------------------| | 1| 0|Effect sound|Separate F-Number can be set to each slot as well | | 1| 0| |as CSM. | ------------------------------------------------------------------------ [/CODE] Several things about this table: 1. My reading is that the last entry should apply to bit patterns 10 and 11. I think the fact they list 10 twice for the last entry is an obvious typo. 2. My understanding of the description is that the CSM and "Effect Sound" modes both enable the use of the extra channel 3 registers to specify the frequency/block data for each operator separately. The difference between the two seems to be that in the CSM mode, Timer A is somehow used to automatically toggle key on/off. The text seems to suggest that this does not happen in "Effect sound" mode, it simply activates the separate frequency numbers for each operator. What I don't know from reading this documentation is how exactly this "key on/off" on Timer A works. Obviously something happens when Timer A expires, but there's a few different ways I could imagine this being implemented. Does it always simply set key on for each Timer A, and never send a key-off? Does it alternate between key on/key off as the timer expires? I'd want to confirm exactly what the behaviour is. Comparing the table in the YM2608 manual with the one in the Genesis Software Sound Manual, here's what Sega says about this mode: [CODE] ------------------------------------------------------------- |CH 3 Mode |D7|D6| | |----------|--|--|------------------------------------------| |NORMAL | 0| 0|Channel 3 is the same as the others. | |----------|--|--|------------------------------------------| |SPECIAL | 0| 1|Channel 3 has four separate frequencies. | |----------|--|--|------------------------------------------| |ILLEGAL | 1| X| | ------------------------------------------------------------- [/CODE] This would suggest that what we currently call channel 3 "special" mode is in fact CSM mode, and that in order to emulate it, we should be doing the key on/off on Timer A. Perhaps the sound error is due to this feature not being emulated? Another thing of note, is that the Sega documentation and the YM2608 documentation disagree about which frequency values affect which operators. Here's what it says in the Genesis Software Sound Manual, page 12: [QUOTE] "Channel 3 operator 1's frequency is in Registers A2 and A6. Operators 2 and 4 are in Registers A8 and AC, A9 and AE, and AA and AE, respectively." [/QUOTE] Well, for one thing, I assume they meant to say "Operators 2, 3, and 4", and there's the glaring error that they listed register AE twice. The third pair should have been A9, AD. Even if you account for those errors though, that doesn't match up with the register assignments given in the YM2608 manual. The table on page 20 of the YM2608 Application Manual gives the following register allocation: [CODE] ------------------ |Operator 1|A9,AD| |Operator 2|AA,AE| |Operator 3|A8,AC| |Operator 4|A2,A6| ------------------ [/CODE] Compared with the numbers they were trying to give in Sega's documentation: [CODE] ------------------ |Operator 1|A2,A6| |Operator 2|A8,AC| |Operator 3|A9,AD| |Operator 4|AA,AE| ------------------ [/CODE] We know that the registers for operators 2 and 3 are switched in the Sega documentation, so if you use the same operator numbers as are given in the register list in the Sega documentation, you should reverse operators 2 and 3 in that table. Even if you do that however, the Sega documentation clearly says that the frequency for operator 1 is in A2,A6, while the YM2608 manual says that's the frequency for operator 4. Can anyone who's worked with the YM2612 in hardware, or written a working YM2612 core, confirm which register numbers match up to which operators? ######## POST p5593 | TascoDLX | 2008-06-18 | t386-030.html [QUOTE] Nemesis wrote:"Priscarar function" (phonetic for something?) [/QUOTE] Prescaler. ######## POST p5594 | Nemesis | 2008-06-18 | t386-030.html Yeah, that's probably it. I found another phonetic entry in the ADPCM section of "Priscal" which is known to definitely mean prescale. It's the part at the end which is throwing me a bit. It almost seems like it's another word tacked on. I was thinking "priscarar" might mean something along the lines of "Prescale rate", but that doesn't match "Sastenrat" which means "Sustain rate". Maybe it is just supposed to be "prescaler". ######## POST p5596 | Shiru | 2008-06-18 | t386-030.html [QUOTE] Nemesis wrote:Another thing which is very interesting is the "Priscarar function" (phonetic for something?). It appears that writing to registers 0x2D, 0x2E, and 0x2F in the YM2608 adjusts the clock divider for the FM and SSG sound generation units. [/QUOTE] Prescaler, also works on YM2203. Don't know about YM2612. [QUOTE] Nemesis wrote:Well, for one thing, I assume they meant to say "Operators 2, 3, and 4", and there's the glaring error that they listed register AE twice. The third pair should have been A9, AD. Even if you account for those errors though, that doesn't match up with the register assignments given in the YM2608 manual. [/QUOTE] In MAME OPN emulation code register pairs for multi-frequency mode are A6A2, ACA8, AEAA, ADA9. When I did test of that mode, it worked same in all emulators and on real hardware. ######## POST p5597 | Nemesis | 2008-06-18 | t386-030.html Ok, so those register pairs are different again. If that's the correct allocation, that would mean both the documents are wrong. In your testing on the hardware, did you specifically test and confirm the register allocation, or were you just listening to the sound output for the channel as a whole? It's possible swapped register pairs could have little audible effect on the sound output, depending on how the sound is being created. It seems the best way to test this would be to set algorithm 8 (each operator as a slot), and key-on each individual operator separately, with separate frequencies in each register. By stepping one operator at a time, you could tell which registers were being used for that operator by the tone it creates. I might run this test for my own piece of mind if nothing else. It would seem odd to me that neither document would have the correct info. And speaking of key on/off, I've noticed something that's either wrong in the Yamaha documentation, or a lot of emulators probably get wrong. Both the Sega and Yamaha documentation agree that when it comes to setting key on/off for individual operators in reg $28, D7=op4, D6=op3, D5=op2, and D4=op1. When it comes to all the other registers however, the Sega documentation has operators 2 and 3 switched. I'm pretty sure in the past with only the Sega document as a reference, most people have switched the operator numbers in the algorithm table, assuming that's where the error was. We can see in this document from Yamaha however that the numbers in the algorithm tables were correct, and that it was the register locations which were switched. The correct order of the operators is op1, op3, op2, op4 in the register blocks. The Yamaha docs agree that the operator numbers come sequentially in the key on/off register however. If the Yamaha docs are correct, and an emulator has been written assuming the registers came sequentially in the register block, then the bits for operator 2 and 3 would have to be switched in the key on/off register, otherwise the wrong operator would be affected. This might not be easily noticed either, as operators aren't usually controlled separately. ######## POST p5598 | Shiru | 2008-06-18 | t386-030.html [QUOTE] Nemesis wrote:Ok, so those register pairs are different again. If that's the correct allocation, that would mean both the documents are wrong. [/QUOTE] Actually, order which I said is same as in YM2608 doc, just reversed by some reason. [QUOTE] Nemesis wrote:In your testing on the hardware, did you specifically test and confirm the register allocation, or were you just listening to the sound output for the channel as a whole? [/QUOTE] Main goal of test was to check if second bank of YM2612 has multi-frequency mode (it does not). But I used algo #7 (all operators are slots) and separate Key On/Off for each operator in that test. You can check it by yourself . [QUOTE] Nemesis wrote:If the Yamaha docs are correct, and an emulator has been written assuming.. [/QUOTE] I highly doubt that any of YM2612 emulators was written with info from docs only, without very many tests on real hardware. ######## POST p5599 | Eke | 2008-06-18 | t386-030.html The emulators are correct regarding operator order and register addresses, even for CH3 special mode, it's just that the YM2612 doc is wrong... but this new doc seems correct for me, this is exactly the same order as in MAME emu (S1>S3>S2>S4 for common registers and S4>S3>S1>S2 for CH3 frequencies) the operator bits in KEYON/OFF register is also the same [QUOTE] What I don't know from reading this documentation is how exactly this "key on/off" on Timer A works. Obviously something happens when Timer A expires, but there's a few different ways I could imagine this being implemented. Does it always simply set key on for each Timer A, and never send a key-off? Does it alternate between key on/key off as the timer expires? I'd want to confirm exactly what the behaviour is. [/QUOTE] in emulators (MAME for example), it only set KEY ON for all operators while reading the new doc, it seems to me it could be that the first time it occurs, key ON is set than the next time, Key OFF is set (and so on...) still, I 'm not sure to understand the difference between the 2 special mode, is that only the Timer A behaviour ? Also note that in emulators, the TimerA Key ON (CSMKeyControll in MAME core) only happen when the last bit is set, which is in contradiction with this doc... ######## POST p5600 | AamirM | 2008-06-18 | t386-030.html Hi, [QUOTE] Nemesis wrote:The thing I'm most interesting in solving once and for all with this new documentation is the cause of the unusual sound in Flashback, and several other Mega Drive games. [/QUOTE] I have spent many tens of hours trying to figure out this one but unable to do so. I've looked into (and tried) every possible reasoning there is. I remember that I once changed operator order and it sounded very close Kega (but not exact, I don't have MD anymore to test real hardware recording) but it broke sound in Todd's Slime World. But if we have gotten the operator order wrong and Steve Snake has it right then why does it is only corrected in SuperHQ mode? I also tried various things with Key On/Off using Timer A but no success there either. Game Music Emu by Blargg has a modified Gens core in which this is fixed (possibly using FIR filtering which it has) but I haven't gotten any time to figure out how its done. If anybody else could use that core in some emu to see if it is in fact the FIR filtering or something in that pirticular version of Gens core, then that would be awesome. Also, this blip sound doesn't only happen in one pirticular setting which Eke described in another topic. This blip sound is also present in Vector Man 2 in music called 'Planet Fall Dig' using a slightly different setting. I think its the FIR filtering which will fix this. stay safe, AamirM ######## POST p5601 | Eke | 2008-06-18 | t386-030.html Also, did you notice that the Key-Code calculation is also wrong in YM2612 doc ? it said it was made from the 3 bits of BLOCK and from the 2 high frequency bits which is not what this new doc tells us: KEY CODE is made of BLOCK data 3 bits (OK) but then with N3 and N4 bits where: N4 = last bit of frequency (OK) N3 is a strange combination of the 4 last frequency bits Some other stuff different from the original doc: - DETUNE varies with KEY CODE value also - when using KEYSCALE formula (FINAL RATE = 2*RATE + KS_RATE): FINAL RATE will be 0 if RATE is 0, regardless of KS_RATE value the maximal RATE value is bounded to 63 RR is different from the others (normal, it's one bit less), RATE=2*RR+1 I didn't looked into emulator to see if they emulate this correctly (probably yes) ######## POST p5605 | Nemesis | 2008-06-19 | t386-030.html [QUOTE] Shiru wrote: [QUOTE] Nemesis wrote:Ok, so those register pairs are different again. If that's the correct allocation, that would mean both the documents are wrong. [/QUOTE] Actually, order which I said is same as in YM2608 doc, just reversed by some reason. [/QUOTE] Actually, after checking again, the order of the registers you confirmed in your hardware tests, and the order currently used in MAME, both match the YM2608 documentation. It is just the Sega documentation that's wrong. You might have read the operator bits backwards in the key on/off register. From a post of yours in the thread you linked to: [QUOTE] D7 - operator, which frequency defined by A6A2 D6 - .. ACA8 D5 - .. AEAA D4 - .. ADA9 [/QUOTE] Where D7=op4, D6=op3, D5=op2, and D4=op1. That matches the YM2608 document. At least that's confirmed then. [QUOTE] I highly doubt that any of YM2612 emulators was written with info from docs only, without very many tests on real hardware. [/QUOTE] I must say, I didn't expect to find this many errors and omissions in the Sega documentation, and there are some big ones in there. No wonder YM2612 emulation is the last thing Mega Drive emulators tend to get right, if ever. You're probably right, I don't think it would have been possible to get a YM2612 core off the ground at all without tests in hardware, and only the Sega document as a reference. [QUOTE] still, I 'm not sure to understand the difference between the 2 special mode, is that only the Timer A behaviour ? Also note that in emulators, the TimerA Key ON (CSMKeyControll in MAME core) only happen when the last bit is set, which is in contradiction with this doc... [/QUOTE] I must say, I'm a bit unclear on the distinction between the two as well. It seems to me to be saying that the "Effect Sound" mode is just the separate frequency part of the CSM mode, without key on/off on timer A. There is a bit of ambiguity in the translated text however. I might get the text in this particular section professionally translated, just to be sure of the meaning. It would have been nice to have at least a good paragraph describing the channel 3 modes though. A few sentences in a table really isn't enough to sum up all the details of these modes. It does sound a bit sus that MAME only enables CSM mode when D7 is set. The Sega documentation certainly doesn't mention anything about key on/off on timer A, they simply describe the separate frequency values for each slot. I would be surprised if every Mega Drive game has been using CSM mode without having the information about the timer A key on/off control. It's possible the Yamaha documentation has these bits switched. This definitely needs to be tested in hardware. [QUOTE] Game Music Emu by Blargg has a modified Gens core in which this is fixed (possibly using FIR filtering which it has) but I haven't gotten any time to figure out how its done. If anybody else could use that core in some emu to see if it is in fact the FIR filtering or something in that pirticular version of Gens core, then that would be awesome. [/QUOTE] I might look into that. I'm at the stage of planning the YM2612 core for my emulator, and it would be good to know the answer to this mystery before I repeat the same mistakes. [QUOTE] Also, did you notice that the Key-Code calculation is also wrong in YM2612 doc ? [/QUOTE] I actually hadn't spotted that. It's a subtle difference, which means it's probably wrong in a few different emulators. [QUOTE] Some other stuff different from the original doc: - DETUNE varies with KEY CODE value also - when using KEYSCALE formula (FINAL RATE = 2*RATE + KS_RATE): FINAL RATE will be 0 if RATE is 0, regardless of KS_RATE value the maximal RATE value is bounded to 63 RR is different from the others (normal, it's one bit less), RATE=2*RR+1 [/QUOTE] Good finds. I'd noticed all those special case rules for the keyscale formula, but I hadn't compared to the Sega documentation to see if it covered them. Seems it doesn't. I actually thought the Sega documentation had mentioned detune being affected by rate scaling, but looking back over it, it seems I was wrong about that. ######## POST p5607 | bobthebuilder | 2008-06-19 | t386-030.html I think it would be a great idea if the manual was submitted to romhacking.net. Nemesis, you can have the guys at romhacking.net help translate any parts that need clarification (several of them are professionals). Here is a link to the forum that can help: http://www.romhacking.net/forum/index.p ... d,9.0.html ######## POST p5608 | Nemesis | 2008-06-19 | t386-030.html Am I the only one who finds the formula for the N3 bit of the keycode confusing? Here's how the YM2608 manual says the N3 bit is calculated, on page 25: N3=F11・( F10+F9+F8 ) + !F11・F10・F9・F8 This is a boolean calculation, so their operator symbols are confusing me a bit. I don't see how addition has any place in this operation, and I haven't seen that dot symbol used in this context before. I somehow doubt they're talking about vector dot product. Fortunately they've given us some sample data above. [CODE] ------------------ |F11|F10|F9|F8|N3| |----------------| | 0 | 1 | 0| 1| 0| | 0 | 1 | 1| 0| 0| | 0 | 1 | 1| 1| 1| | 1 | 0 | 0| 0| 0| | 1 | 0 | 0| 1| 1| ------------------ [/CODE] So given those combinations of F11, F10, F9, and F8, that's the resulting N3 bit they're somehow getting using that above equation. Can anyone figure out how to actually interpret that formula to get these results? ######## POST p5609 | Nemesis | 2008-06-19 | t386-030.html [QUOTE] bobthebuilder wrote:I think it would be a great idea if the manual was submitted to romhacking.net. Nemesis, you can have the guys at romhacking.net help translate any parts that need clarification (several of them are professionals). Here is a link to the forum that can help: http://www.romhacking.net/forum/index.p ... d,9.0.html [/QUOTE] Looks good to me. I might submit the original. I won't enter my transcription just yet though. Now that I've finished the transcription and I actually have time to read the document, I've found a number of errors in the transcription and the OCR that I missed in my initial checks. I've also been translating phonetic words into their proper English equivalents as I confirm them. In a week or so once the corrections settle down, I'll release an updated document and submit it to romhacking.net. ######## POST p5610 | TascoDLX | 2008-06-19 | t386-030.html [QUOTE] Nemesis wrote:Am I the only one who finds the formula for the N3 bit of the keycode confusing? Here's how the YM2608 manual says the N3 bit is calculated, on page 25: N3=F11・( F10+F9+F8 ) + !F11・F10・F9・F8 This is a boolean calculation, so their operator symbols are confusing me a bit. I don't see how addition has any place in this operation, and I haven't seen that dot symbol used in this context before. I somehow doubt they're talking about vector dot product. Fortunately they've given us some sample data above. [/QUOTE] It's boolean algebra: + is OR, ・ is AND, ! is NOT. Order of operations (ignoring parentheses) is NOT then AND then OR. This formula can be split into two cases: * If F11 is set (1), then only one of the other three ( F10, F9, F8 ) need be set (1). [1001, 1010, 1011, 1100, 1101, 1110, 1111] * If F11 is not set (0), then the other three ( F10, F9, F8 ) must all be set (1). [0111] The formula can be rewritten thusly: N3 = F11・( F10+F9+F8 ) + !F11・( F10・F9・F8 ) ######## POST p5611 | Nemesis | 2008-06-19 | t386-045.html Thanks, that makes sense now. I've never seen those symbols for boolean operators before. I think I must have tried every combination of operators except the right one. ######## POST p5614 | AamirM | 2008-06-19 | t386-045.html Hi, [QUOTE] I might look into that. I'm at the stage of planning the YM2612 core for my emulator, and it would be good to know the answer to this mystery before I repeat the same mistakes. [/QUOTE] It is also interesting to note that the blip sound only disappears when you use the Gens' core with game music emu. Game Music emu also has the option to use MAME FM core in which case the blip sound is present (which gives the indication that it might not be the FIR filtering). I tried exchanging the operator 2 & 3 order (which is incorrect) in that pirticular Gens' FM core and the blip sound came again. I wasn't able to find any differences between that Gens FM core (which is a modified from Gens 2.10) and the current one (in Gens 2.14) although blargg has modified it very much (mostly for optimization and simplification). I would recommend others to look there for answer to this mystery. I don't have any time right now otherwise I would've looked at that myself in detail. stay safe, AamirM ######## POST p5615 | Eke | 2008-06-19 | t386-045.html [QUOTE] It does sound a bit sus that MAME only enables CSM mode when D7 is set. The Sega documentation certainly doesn't mention anything about key on/off on timer A, they simply describe the separate frequency values for each slot. I would be surprised if every Mega Drive game has been using CSM mode without having the information about the timer A key on/off control. It's possible the Yamaha documentation has these bits switched. This definitely needs to be tested in hardware. [/QUOTE] look at ym2151docs.pdf here:http://msx.retro8bits.com/msxdocs.html I know it is not the same chip family but there is a lot of similarities in hardware design and technical concepts, this is a good complement to this doc too, just to doublecheck some calculations also, see that bit D7 is defined as CSM mode activation, where Timer A generate a Key-ON on all CH3 operators, this is probably where the MAME code is coming from (btw, this is commented as "actually wrong" in the code, so they probably just copy what was on similar YM chips) PS: another thing I noticed in those two docs in that SL (substain level, T1L in YM2612 doc) will have a max attenuation of 93dB when all bits are set, even if it would seem more logical to just add the value of each bit : 24+12+6+3 = 45dB max, I still need to check in emulator codes how they handle this one (I'm first trying to make a synthethis of all new or corrected features that are specified in this doc, comparing to original ym2612 doc) finally, what we are still missing and are probably the most important stuff are the AR/DR& RR timings, according to the register values. There are fully described at the end of the YM2151 doc but they are probably not compatible... EDIT: I just looked into the MAME ym2612 core source and it appears that every ambiguous things I mentionned is handled as described in the doc (excepting the auto key feature which is still not clearly understood), even the SSG-EG shapes (there are even devs comment about that ones suggesting they had access to a similar documentation [IMG ./images/smilies/icon_wink.gif] ) that's why I fear that this doc, even if still being a great reference , will not be any help to fix the remaining inaccuracies in current ym2612 implementations, which are SSG-EG handling and the special instrument that produce the so called "blip-blip" sound about SSG-EG, could it be possible that it is somehow relying on the SSG part of this chip, which would result in a broken or only partially working feature on ym2612 ? ######## POST p5618 | Nemesis | 2008-06-21 | t386-045.html I've cracked it. I know the cause of the mysterious blip sound in Flashback. I had a thorough play with Gens and the "Game Music Emu" thingamajigy, and based on the modifications made to the Gens core, I was able to trace back the differences between the two, and figure out the cause. The sound created by this instrument is the result of a bug in the YM2612 hardware, as some people had suspected. Based on the specs, it shouldn't happen, but it does. The culprit is the detune setting. Specifically, the case arises when you have: 1. A negative detune value 2. A frequency value for an operator very close to or equal to 0 The offender in the case of Flashback is Channel 3, operator 2. It has a detune value of -3, and a frequency value of 0. The negative detune attempts to subtract a small frequency value from the specified frequency. When the frequency value is smaller than the value being subtracted, the result overflows, producing a very large (high) frequency number instead. I've tested and confirmed this on the real hardware. Here's a simple test ROM: http://nemesis.hacking-cult.org/MegaDri ... detune.bin And here's the source: http://nemesis.hacking-cult.org/MegaDri ... detune.asm This ROM generates a continuous tone on the real system (and Kega), even though all slots in all operators have a frequency number of 0. Emulating this is possible. By using the same number system and register sizes during the frequency calculation, this overflow case can be accurately emulated. This requires information on the register sizes used within the Phase Generator, and the numbers which are used to represent frequency values internally. It's possible to determine this information by measuring the frequency of the waves produced by this overflow bug on the real hardware, and varying the octave and detune parameters as required. The Gens core does in fact already cause an overflow with detune values. It just so happens that because of the numbers Gens uses to represent intermediate frequency values, and because of the size of the datatypes used, Gens outputs a much higher frequency than the real system would in the case of an overflow, which is beyond the range of human hearing. The modified core in the "Game Music Emu" program uses a different scheme which results in a wave which is closer, but not the same, as the one produced by the real system. I don't believe this bug was deliberately emulated in this "Game Music Emu" player. Rather, it's an accidental side-effect of some changes in the way frequency values are dealt with, which differs from the stock Gens core. The result is close to correct in the case of the Flashback ROM, but not quite right. The same may be true of Kega, but it seems to be a lot more accurate, if not exactly the same as the real system. It's quite possible Steve figured out this bug a long time ago. ######## POST p5620 | Stef | 2008-06-21 | t386-045.html Kudos for your discover ! I searched about this "bug" for a long time, i guess now we just need to figure internal table/reg size for accurate emulation [IMG ./images/smilies/icon_smile.gif] ######## POST p5621 | Nemesis | 2008-06-22 | t386-045.html I just encountered another quirk with the YM2612 which I wasn't fully aware of. This may be common knowledge for people who've worked with the hardware, but I noticed this isn't emulated in Gens, and I wasn't aware of it until I was running these tests either, so I think it should be mentioned. There's repeated warnings in numerous places throughout both the Sega documentation and the documentation from Yamaha, regarding how the registers which set the frequency and octave for a channel should be written to. What they say is that you should always write the Block/Fnum ($A4-$A6) byte first, then write the Fnum ($A0-$A2) byte second. What they don't say is what happens when you ignore this advice. [IMG ./images/smilies/icon_biggrin.gif] It appears that the YM2612 doesn't commit a write to the block/fnum register until the fnum register is written to. If you were for example to perform the following writes: -Set 0xA6 to 0x1E -Set 0xA2 to 0xFF -Set 0xA6 to 0x24 The effective settings for the channel will remain as 0xA6 = 0x1E, 0xA2 = 0xFF. The second write to register 0xA6 will not be seen until 0xA2 is written to again. Here's a test ROM which demonstrates this behaviour: http://nemesis.hacking-cult.org/MegaDri ... eOrder.bin And here's the source: http://nemesis.hacking-cult.org/MegaDri ... eOrder.asm If register changes were applied immediately, the result would be an A4 (440Hz). Instead, this ROM will play an A6 in the actual hardware. For the sake of completeness, it's also worth noting that writing an fnum byte for one channel doesn't commit fnum/block writes which have been made to other channels. If you write a block/fnum byte to channel 2, then write an fnum byte to channel 3, the block/fnum byte for channel 2 will not be applied. The update will remain in limbo until the fnum register for channel 2 is written to, regardless of how many writes are made to the registers for other channels. Once again, this behaviour is emulated correctly in Kega. Does anyone know of something Kega doesn't get right? ######## POST p5622 | HardWareMan | 2008-06-22 | t386-045.html So, you trying to say what whole block&fnum register triggers by write low fnum byte? I always thought that warning is for write rough tune first, then write fine tune, so less error will notice between writes. But now all different. For 8-bit systems it is helpfull for change 16-bit register. ######## POST p5623 | Eke | 2008-06-22 | t386-045.html great found, finally the big secret has been revealed [IMG ./images/smilies/icon_wink.gif] thank for taking the time to do test on real HW and for sharing ! btw, is this a bug with ch3 only or did you reproduce it on other channels ? ######## POST p5624 | TmEE co.(TM) | 2008-06-22 | t386-045.html [QUOTE] Nemesis wrote:Once again, this behaviour is emulated correctly in Kega. Does anyone know of something Kega doesn't get right? [/QUOTE] In Kega you are able to play samples in Stereo, but you can't do it in other emulators and real hardware... Kega won't play the currently played sample on the channel in next one when you change Left/Right reg so you can get nice and clean stereo sample playback. I made a demo which is on my OUTDATED site's MD section : http://www.hot.ee/tmeeco/MD.HTM Great work on figuring out what the writing of freq to YM2612 in a wrong way causes. I had all kinds of trouble with it when writing my sound engine, as it didn't work on MD and Kega but worked on all other emulators... now I know that you must write high part first. I wonder if Timer A behaves in a same manner if writes are done backwards ? ######## POST p5625 | Eke | 2008-06-22 | t386-045.html [QUOTE] TmEE co.(TM) wrote: Great work on figuring out what the writing of freq to YM2612 in a wrong way causes. I had all kinds of trouble with it when writing my sound engine, as it didn't work on MD and Kega but worked on all other emulators... now I know that you must write high part first. I wonder if Timer A behaves in a same manner if writes are done backwards ? [/QUOTE] well, this is handled correctly by the MAME emu (frequencies are updated only when A0-A2, A8-AA are written) but not by GENS (frequencies are updated every time you modify any registers) none of them care about Timer A write order: counter are reinitialized each time the Timers values are changed (this is needed to fix Outrun music I think) but Timer writes behaviour when Timer is started is not really known... I also wonder how they really work: is the order important ? does the counter reset when the START bit flag is changed ? ######## POST p5626 | Chilly Willy | 2008-06-22 | t386-045.html If you've never set a timer before, the proper way to do so (assuming you have to do two writes to a hi and lo reg without latching) is to write the largest possible value (usually 0xff) to the low reg first, then write the hi value, then finally the correct lo value. The idea is that by writing the largest possible value allowed to lo reg first, you have time to set hi and then the proper lo without the register underflowing. If the timer latches the values, then of course none of that matters. [IMG ./images/smilies/icon_biggrin.gif] ######## POST p5628 | notaz | 2008-06-23 | t386-045.html I just want to add my thanks for your work, Nem! ######## POST p5629 | Nemesis | 2008-06-23 | t386-045.html [QUOTE] Stef wrote:Kudos for your discover ! I searched about this "bug" for a long time, i guess now we just need to figure internal table/reg size for accurate emulation [/QUOTE] I can tell you right now from initial tests, that the value it overflows to is very close to the maximum frequency value you can set normally (block = 0x7, fnum = 0x7FF). I've got a whole series of tests planned to narrow down the exact numbers though. [QUOTE] HardWareMan wrote:So, you trying to say what whole block&fnum register triggers by write low fnum byte? I always thought that warning is for write rough tune first, then write fine tune, so less error will notice between writes. But now all different. For 8-bit systems it is helpfull for change 16-bit register. [/QUOTE] Yeah, I'd assumed the same thing. I only found out about this behaviour because I was setting the registers the wrong way around for some of my tests, and was a little puzzled when all I got was silence. [QUOTE] Eke wrote:btw, is this a bug with ch3 only or did you reproduce it on other channels ? [/QUOTE] I'm pretty sure I tested on other channels, but now that you've asked, I can't remember for sure. I'll repeat the tests on a few other channels just to be certain. [QUOTE] TmEE co.(TM) wrote:Great work on figuring out what the writing of freq to YM2612 in a wrong way causes. I had all kinds of trouble with it when writing my sound engine, as it didn't work on MD and Kega but worked on all other emulators... now I know that you must write high part first. I wonder if Timer A behaves in a same manner if writes are done backwards ? [/QUOTE] That's a good question. I'll add that to my list of things to test about the timers. [QUOTE] notaz wrote:I just want to add my thanks for your work, Nem! [/QUOTE] Thanks [IMG ./images/smilies/icon_biggrin.gif]. It's nice to be able to share this information with other people who can make use of it. There's a lot more tests I'm going to be running on the YM2612 in the next little while. I don't have much time free right now, but I've got 2 weeks holidays starting at the end of this week, and I plan to spend a fair portion of that tinkering with the YM2612, and maybe even get my own FM core off the ground. I'll make sure to post my findings here. I've already got a list of things to test, but are there any special requests? I'm going to be running a whole battery of tests on the hardware, so if there's some point of behaviour for the YM2612 that you've always wanted to get an answer on, let me know and I'll check it out. ######## POST p5630 | Eke | 2008-06-23 | t386-045.html [QUOTE] I can tell you right now from initial tests, that the value it overflows to is very close to the maximum frequency value you can set normally (block = 0x7, fnum = 0x7FF). I've got a whole series of tests planned to narrow down the exact numbers though. [/QUOTE] do you mean that the maximal frequency the ym2612 can achieve is given by these max values ? or is the max frequency the max NUM value multiplied by the max FNUM/BLOCK value which have been added to the MAX Detune value ? this would be a little like enveloppe rates, they can be increased with the key scale but the maximal values is still limited to the maximal rate value well, I have some thought for a quick fix in the Gens core but didn't have the mean to test it for now: in Gens (Stef, please correct me if I'm wrong), phase increment are used, and phase is updated like this for example: [QUOTE] (1) CH->SLOT[S0].Fcnt += CH->SLOT[S0].Finc; [/QUOTE] the incremented value is calculated each time that parameters are changed by this formula: [QUOTE] (2) SL->Finc = (finc + SL->DT[kc]) * SL->MUL; [/QUOTE] where finc is derivated from FNUM and BLOCK values: [QUOTE] (3) finc = FINC_TAB[CH->FNUM[0]] >> (7 - CH->FOCT[0]); [/QUOTE] as you can see, in formula (2), if finc < -DT , the Phase Increment will become negative, which is no good (SL->Finc is indeed declared as signed int so it does not underflow, the only time it is negative should be when it need to be recalculated, i.e forced to -1) so the idea would be to calculate the maximal increment value and to add this test after (2): [QUOTE] if (SL->Finc < 0) SL->Finc += FInc_MAX + 1; [/QUOTE] ######## POST p5631 | Stef | 2008-06-23 | t386-045.html Yep, that should do it in theory. As you said the YM2612 is probably using internally a non signed fixed size register and in some case it underflows. Your fix should emulate it correctly =) ######## POST p5632 | notaz | 2008-06-23 | t386-060.html Tried to add handling for this into MAME core. It took a while to figure out that the behavior Nemesis described is not what actually causes the 'blip' sound, the blip comes from operator1, and the described operator2 behavior eliminates the 'blip' [IMG ./images/smilies/icon_smile.gif] For some reason I'm getting the best results when I use fnum=7ff and blk=5 settings as a maximum. I've checked as many games as I could: [CODE BLOCK WITHHELD: 312 chars] They sound fine, but they all seem to use the same settings (blk=4, mul=12, ...), probably because they all use GEMS. ######## POST p5633 | Nemesis | 2008-06-24 | t386-060.html I've confirmed the presence of the CSM mode in the YM2612, and whatsmore, Kega doesn't emulate it. Hooray, I've found something new! [IMG ./images/smilies/icon_lol.gif] I've still got more tests to run before I can post a full description of how the CSM mode works, and I'm not going to have time to complete them all tonight, but I'll post the details as soon as I've confirmed the behaviour. [QUOTE] Eke wrote:btw, is this a bug with ch3 only or did you reproduce it on other channels ? [/QUOTE] I've now confirmed that the detune overflow bug occurs on all channels. ######## POST p5634 | Eke | 2008-06-24 | t386-060.html cool, did you found any games using this ? Btw, you already made a great discovery by explaining the Detune bug, I still can not understand how this could have remained like a dirty secret so long [IMG ./images/smilies/icon_rolleyes.gif] sharing informations is the way to move on, especially when some people don't have a way or enough knowledge to make test on real hardware themselves... thanks a lot Nemesis ######## POST p5635 | Nemesis | 2008-06-24 | t386-060.html I haven't looked for games that use this feature, I've just been experimenting with my own code. If anybody wants to hunt for games which might make use of it, CSM mode is active when the channel 3 mode bits are set to "10", or in other words, when register $27 is set to 10******. CSM mode is not active when the upper bits are set to 11. ######## POST p5636 | notaz | 2008-06-24 | t386-060.html Looking forward to "Undocumented YM2612 features" doc [IMG ./images/smilies/icon_smile.gif] ######## POST p5637 | Eke | 2008-06-26 | t386-060.html [QUOTE] Stef wrote:Yep, that should do it in theory. As you said the YM2612 is probably using internally a non signed fixed size register and in some case it underflows. Your fix should emulate it correctly =) [/QUOTE] well, it doesn't [IMG ./images/smilies/icon_sad.gif] I'm probably missing something with this phase increment stuff (this is definitely one of the thing I'm still not sure to understand in the emulator code) notaz: what did you do exactly to fix the MAME core ? ######## POST p5638 | TmEE co.(TM) | 2008-06-26 | t386-060.html What is this CSM mode ? ######## POST p5639 | Nemesis | 2008-06-26 | t386-060.html [QUOTE] Eke wrote: [QUOTE] Stef wrote:Yep, that should do it in theory. As you said the YM2612 is probably using internally a non signed fixed size register and in some case it underflows. Your fix should emulate it correctly =) [/QUOTE] well, it doesn't [IMG ./images/smilies/icon_sad.gif] I'm probably missing something with this phase increment stuff (this is definitely one of the thing I'm still not sure to understand in the emulator code) [/QUOTE] I added the following lines to CALC_FINC_SL in Gens to approximate the effect when I was doing testing: [QUOTE] if(SL->Finc < 0) { finc = FINC_TAB[0x7FF] >> (7 - 0x7); SL->Finc = (finc + SL->DT[kc]) * SL->MUL; } [/QUOTE] Based on what notaz said, you might find the result sounds closer if you set block to 5 instead of 7. [QUOTE] TmEE co.(TM) wrote:What is this CSM mode ? [/QUOTE] CSM mode is another special mode for channel 3, where Timer A automatically does key on/off for the channel. ######## POST p5640 | TmEE co.(TM) | 2008-06-26 | t386-060.html I can't make use of CSM mode in my sound engine then... Timer A is used for SFX, Timer B for BGM, VBLs are not touched. ######## POST p5641 | Chilly Willy | 2008-06-26 | t386-060.html [QUOTE] TmEE co.(TM) wrote:What is this CSM mode ? [/QUOTE] It's a mode meant for formant speech synthesis. One of the better methods of synthesizing speech is to break it into the addition of resonant frequencies that last a specific time. These are called formants and if you add the correct ones, you get a phoneme. You might want to check the proper wiki pages for more info. http://en.wikipedia.org/wiki/Speech_syn ... _synthesis http://en.wikipedia.org/wiki/Formant ######## POST p5642 | TmEE co.(TM) | 2008-06-26 | t386-060.html For speech synthesis I use samples... 50K of samples are enough for well understandable text [IMG ./images/smilies/icon_smile.gif] only limitation of my synth : you need to be Estonian to make it talk (all languages that have "say what you read" and no pronounciation stuff will do. in Estonian "a" is spelled exactly the same in any word you encounter not like in English where the pronounciation depends on word). ######## POST p5643 | TulioAdriano | 2008-06-26 | t386-060.html It would work well for Portuguese, though, and most romance languages, except for French which has lots of irregularities... interesting, very nice. Btw, I haven't seen any concrete report on the famous channel 3 special mode which would allow individual operators to be set on different frequencies. As far as I know most tests on that feature failed to succeed, maybe wrong documentation again? ######## POST p5644 | notaz | 2008-06-26 | t386-060.html [QUOTE] Eke wrote:what did you do exactly to fix the MAME core ? [/QUOTE] I changed the start of refresh_fc_eg_slot() to this: [CODE BLOCK WITHHELD: 298 chars] Note that this only works when sampling @ 44.1hHz, so it's probably wrong. Multiplier may have something to do with all this too. ######## POST p5645 | Shiru | 2008-06-26 | t386-060.html [QUOTE] TulioAdriano wrote:Btw, I haven't seen any concrete report on the famous channel 3 special mode which would allow individual operators to be set on different frequencies. As far as I know most tests on that feature failed to succeed, maybe wrong documentation again? [/QUOTE] What you mean 'failed'? This mode works well both in emulators and on real hardware, some games use it. I even added basic support for this mode in TFM MM long ago. ######## POST p5646 | Mask of Destiny | 2008-06-26 | t386-060.html [QUOTE] Shiru wrote: [QUOTE] TulioAdriano wrote:Btw, I haven't seen any concrete report on the famous channel 3 special mode which would allow individual operators to be set on different frequencies. As far as I know most tests on that feature failed to succeed, maybe wrong documentation again? [/QUOTE] What you mean 'failed'? This mode works well both in emulators and on real hardware, some games use it. I even added basic support for this mode in TFM MM long ago. [/QUOTE] My guess is he's thinking of the tests as to whether or not Channel 3 special mode also worked on Channel 6. ######## POST p5647 | TulioAdriano | 2008-06-26 | t386-075.html [QUOTE] Shiru wrote: [QUOTE] TulioAdriano wrote:Btw, I haven't seen any concrete report on the famous channel 3 special mode which would allow individual operators to be set on different frequencies. As far as I know most tests on that feature failed to succeed, maybe wrong documentation again? [/QUOTE] What you mean 'failed'? This mode works well both in emulators and on real hardware, some games use it. I even added basic support for this mode in TFM MM long ago. [/QUOTE] Ok dude, it was just a question. You don't need to get angry... [IMG ./images/smilies/icon_eek.gif] ######## POST p5648 | Shiru | 2008-06-26 | t386-075.html [QUOTE] Mask of Destiny wrote:My guess is he's thinking of the tests as to whether or not Channel 3 special mode also worked on Channel 6. [/QUOTE] Documentation has no mentions that second bank has any registers below #30. My test, which tried to use special mode on second bank by setting corresponding bit in register #27 of second bank, confirmed it (both for hardware and emulators). We also know that register #27 of first bank has two bits for special mode and CSM control and no free bits. So, I think, this information enough for 'concrete report'. ######## POST p5650 | Nemesis | 2008-06-29 | t386-075.html Ok, here's everything I know about CSM mode. The operation is quite simple in the end, but I did a lot of tests searching for unusual behaviour along the way. All this information is based entirely on tests performed on the YM2612 hardware. Enabling CSM mode: CSM mode is a special mode of operation for channel 3 only. First of all, here's a complete description of the effects of the channel 3 mode flags in register $27: [CODE] ---------------------- |Mode| Behaviour | |----|---------------| | 00 | Normal | | 01 | Special | | 10 | Special + CSM | | 11 | Special | ---------------------- [/CODE] Normal mode is of course when no special mode is in effect for channel 3, and it behaves like any other channel. Special mode is when a separate frequency/octave can be assigned to each operator within the channel, which we already have documentation on. CSM mode is where Timer A performs automatic key on/off for channel 3. As you can see from the table above, Special mode is always active when CSM mode is active. CSM mode is only active when the mode bits are set to 10, NOT when they are set to 11. In order for CSM mode to have any effect, Timer A must be loaded. In other words, bit 0 of reg $27 must be set to 1. None of the other timer-related flags, including the reset and enable bits, nor the state of Timer B, have any impact on CSM mode whatsoever, and the act of changing the state of these settings at any time have no impact on the operation of the CSM mode, as long as the channel 3 mode, and Timer A load flag remain unchanged. The effects of CSM mode: When CSM mode is correctly enabled, each time Timer A expires, the following two steps occur, in the specified order: 1. Key-on is sent to all operators in channel 3 2. Key-off is sent to all operators in channel 3 In other words, key on occurs, immediately followed by key-off, at the instant Timer A expires. CSM mode is only evaluated when Timer A expires. The YM2612 does not evaluate the CSM mode when Timer A is loaded, only when it expires, and any changes to the CSM mode while Timer A is running will take effect immediately. If Timer A is currently running and CSM mode is enabled, key on/off will occur when the timer next expires. If Timer A is currently running and CSM mode is disabled, key on/off will not occur when the timer next expires. There is a big implication related to the instant key on/off behaviour of CSM mode. As described in the documentation on the envelope generator, there are several phases the envelope passes through once key-on is triggered, which determine the overall volume of the operator over time. The first phase is the Attack Phase, where the volume of the operator rises from 0 towards TL, the Total Level, at a rate governed by AR, the Attack Rate. When key off occurs, the volume of the operator immediately starts to drop at a rate governed by RR, the Release Rate. If an operator is keyed off during the attack phase and it has not reached TL yet, the volume of the operator will stop rising, and will immedaitely start to fall according to the release rate. Since the key-on and key-off occur at the same time in CSM mode, the only way a sound can be produced is if the volume level starts at something greater than 0. This means the only supported value for the Attack Rate in CSM mode is $1F, which is described as "infinity" in the documentation, meaning the volume of the channel starts at the level specified by TL. Testing has shown that a setting of $1E also works, and produces an identical output as $1F for this purpose (and possibly is identical under all circumstances. Would need further testing). All other settings for AR fail to produce any waveform, since they start with a volume level of 0. Since you can only use an AR value of infinity, and key-off occurs instantly, TL and RR are the two parameters which govern the envelope under CSM mode. DR, SR, and SL will have no impact. The interaction of CSM and manual key on/off: One subtle point about CSM mode is how it interacts with manual key on/off events triggered through register $28. CSM mode doesn't trigger a "real" key-on or key-off event. Timer A expiring will NOT key-off an operator which was manually keyed on by a write to register $28. CSM mode cannot trigger a key-on or key-off for any operator which has been manually sent a key-on event to register $28, until that operator is keyed off manually by a write to register $28. In other words, CSM mode only affects operators which are currently keyed off. If you were to manually key-on all operators in channel 3, then enable CSM mode, the CSM mode would have no effect until you sent a manual key-off event. If you never send a manual key-off, CSM mode will never take effect, even when the output of the operators decay to 0. ######## POST p5651 | Nemesis | 2008-06-29 | t386-075.html Here's a test ROM which uses CSM to generate a fading, repeating A6 tone: http://nemesis.hacking-cult.org/MegaDri ... smmode.bin Here's the source: http://nemesis.hacking-cult.org/MegaDri ... smmode.asm And here's a sample of the output you get on a PAL MD1600 MegaDrive, recorded at 96KHz: http://nemesis.hacking-cult.org/MegaDri ... smmode.wav In an emulator that doesn't support CSM, you'll only get silence if you run this ROM. I haven't come across any Mega Drive emulator which emulates CSM mode as of yet. ######## POST p5652 | notaz | 2008-06-29 | t386-075.html [QUOTE] Nemesis wrote:I haven't come across any Mega Drive emulator which emulates CSM mode as of yet. [/QUOTE] It works in MESS, as MAME YM2612 core supports CSM mode. ######## POST p5653 | Nemesis | 2008-06-29 | t386-075.html Ok then, no emulator that emulates it correctly. [IMG ./images/smilies/icon_smile.gif] MAME has an attempt at CSM support implemented, but it doesn't work properly, as is noted in the sourcecode. I've just tried the CSM test ROM in HazeMD, and it just plays a solid tone, which isn't silence, but it isn't correct. I haven't tried MESS, but it's based on the MAME core as I understand it, so it's probably in the same boat. EDIT: Yep, tried in MESS. Same as MAME. ######## POST p5654 | Chilly Willy | 2008-06-29 | t386-075.html Does changing the frequency during the release period take affect, or does it wait for the next KEY_ON? If the frequency only changes when you KEY_ON, it makes sense why they made CSM work this way. CSM is meant for speech synthesis, so here's what you'd do: Set frequency of all ch3 ops for your formants. Set TIMERA and enable CSM. loop: Wait for TIMERA overflow. Set TIMERA for the period of the phoneme. Set ops for the next phoneme's formants. goto loop This would give you properly timed phonemes while allowing you to set up for the next one ahead of time. Many phonemes are sensitive to how long they last. This form of speech synthesis usually has a table with the formant center frequencies, and the length of the phoneme. ######## POST p5655 | Nemesis | 2008-06-30 | t386-075.html I've just tested, and frequency changes take effect immediately. If you change the frequency for an operator, the new frequency is used for the very next sample, regardless of the current position in the output wave, or the state of the envelope generator. This is consistent with how frequency changes occur without CSM mode active. Even without the ability to setup the freqencies ahead of time, it wouldn't change the length of time each frequency is active for, it would just introduce some minor latency after each Timer A overflow before the frequencies are updated, and create a slight offset between the frequency changes of each operator. This would occur both leading into and out of each Timer A period, so the length wouldn't be affected, merely the timing of the changes. It would be most noticeable if the decay phase of the envelope was extreme, as the initial "attack" for each new key-on would be using the frequency of the previous phoneme. If there was virtually no decay for each key-on, which it sounds like is probably how it's intended to be used, there would be no noticeable effect whatsoever, apart from the minor offset between each operator receiving frequency changes. In a way it could be a good thing. If you set a very short Timer A period, there might not be time to update all 4 frequency values before the timer overflows. If you were leading into a very long Timer A period, and the frequency was latched at key-on only, it could result in a very long phoneme being played with one or more operators set to the wrong frequency, as the new frequency values couldn't be written in time. ######## POST p5656 | Chilly Willy | 2008-06-30 | t386-075.html Well, in the terms of the YM2612 clock or the Z80, phonemes are LONG. I don't think there would be one so short that you couldn't set the operators before the timer overflowed. Perhaps in SEGA's arcade systems where they used this for speech synthesis, they actually had the int line tied to the processor so that TIMERA actually generated an int. Then the behavior would work even with the frequency changing immediately. You'd just change three or four operators during the int handler. I would guess the point of the CSM mode is to eliminate the envelop almost completely. If you set the decay to be long, you have virtually no attack, just a waveform that starts at max and stays very close. The only thing that would change is the frequencies. ######## POST p5660 | TmEE co.(TM) | 2008-06-30 | t386-075.html CSM mode works on MD2 (PAL VA1 board). There is tonal difference, but that is because you used too low TL value (values below 8 should not be used). ######## POST p5676 | Nemesis | 2008-07-01 | t386-075.html I've just uploaded a new version of the YM2608 manual translation. It includes too many fixes to detail. Suffice to say, it corrects numerous transcription errors in the previous document (eg, the write wait times on page 14), a bucketload of OCR corrections I missed the first time around which greatly improves the translation in several sections, adds some entire sentences I somehow skipped when I was doing the initial translation, includes proper equivalents for words that were spelt phonetically, lots of improvements to the overall formatting, etc etc. If you downloaded the first translation, you should update it with the new version. I don't expect to change this document again in the near future, unless I find some whopping big error, or I get someone who actually reads Japanese to check the translation. You can download the latest version from the following link: http://nemesis.hacking-cult.org/MegaDri ... slated.PDF ######## POST p5680 | Nemesis | 2008-07-01 | t386-075.html Here are a few more things I've found out about the YM2612 over the last few days: 1. Status registers The YM2608 manual describes 3 separate status registers that can be read. Significantly, one of them reportedly returns an ID number for the chip, when the status register is read while register location $FF is latched. After testing, I can confirm that this does not apply to the YM2612. The normal status register appears to be returned from the YM2612 under all circumstances, regardless of the address the YM2612 is being read from (part 1 address/data or part 2 address/data), or the register that is latched at the time the status register is read. 2. Prescaler registers The YM2608 manual describes registers $2D, $2E, and $2F as prescaler register addresses, which reportedly simply latching will adjust the multipliers used to calculate the internal clock for the FM generator. This does not seem to exist in the YM2612. Latching or writing to these registers had no noticeable effect. 3. Interrupts I've conducted a full set of tests on the behaviour of the interrupt (INT) line of the YM2612. Even though it's not connected in the Mega Drive, it's still a functional part of the YM2612, and for the sake of completeness if nothing else, I wanted to confirm how it operated. Emulators like MAME could make use of this info too. First and foremost, I've confirmed that interrupt control flags for the YM2608 in register $29 do not exist on the YM2608. The interrupt line can be triggered by either Timer A or Timer B. Using the terms applied in the YM2608 manual, when a timer is "loaded" (bits 0 and 1 of reg $27), it starts with a number loaded into it as specified in the counter registers for each timer, and will count down at a regular rate, until it tries to count down from 0 and overflows. At this time, it will re-load the counter. What else happens as a result of a timer overflowing depends on the setting of the "enable" flag (bits 2 and 3 of reg $27). As described in the documentation, when the enable bit is set and the timer overflows, it will set the overflow flag for that timer in the status register, and trigger an interrupt. And now for the new stuff. Although not mentioned in the documentation, the reset flag directly affects interrupt generation. When a timer overflows, the YM2612 checks the current state of the timer overflow bit for that timer in the status register. The YM2612 will only generate an interrupt for that timer if the overflow bit is currently unset. If the overflow bit is unset, and the enable flag is set in the timer control register, the INT line will be asserted. The INT line will remain asserted, until the reset bit for that timer is set to 1 in the timer control register, or until the timer overflows again. If the reset bit for the timer is cleared at any time, the interrupt line will immediately be negated. If the timer overflows while INT is still asserted, that is, without reset being written to, the interrupt line will immediately be negated. From this point on, no interrupts will be generated for that timer until the reset bit is set. Once the reset bit has been set when an interrupt has been missed, the INT line will not immediately be asserted. The INT line will remain negated until the timer overflows again. This means in order to use the YM2612 interrupt line, the interrupt handler must always write the reset bit for that timer before exiting the interrupt handler. This tells the YM2612 to stop asserting the INT line for that timer, and prepares the YM2612 to trigger another interrupt when the timer overflows again. Additionally, in periods where the YM2612 interrupt is masked, it may be possible for a YM2612 interrupt to be missed, requiring the reset bit to be written in order to resume interrupt generation. The overflow bit in the status register would allow missed interrupts to be detected. The overflow bit should only be asserted in the interrupt handler where YM2612 interrupts are being used, as the overflow bit is set at the same time as the interrupt is generated, and the reset operation when leaving the interrupt handler clears this flag. Sorry if that's confusing. It's easier to understand when you're just looking at the oscilloscope. I might put some pictures up for this later on. I'm not sure that I explained this very well. 4. Timers Two things here. First of all, I've tested the timer A registers, and confirmed that they are NOT "ganged together" like the frequency registers are. Changes to either register $24 or $25 affect Timer A the next time it overflows or is loaded, regardless of the order the registers are written to. Secondly, I've confirmed the timer periods in the YM2612 are half the rate of the timers described in the YM2608 documentation, or in other words, the YM2612 timers take twice as long to count down as the timers in the YM2608. Here are the formulae to calculate the correct timer periods for the YM2612: [CODE] To calculate Timer A period in microseconds: TimerA = 144 * (1024 - NA) / M NA: 0~1023 M: Master clock (MHz) Eg, where clock = 7.61Mhz TimerA(MAX) = 144 * (1024 - 0) / 7.61 = 19376.61 microseconds TimerA(MIN) = 144 * (1024 - 1023) / 7.61 = 18.92 microseconds To calculate Timer B period in microseconds: TimerB = (144*16) * (256 - NA) / M NB: 0~255 M: Master clock (MHz) Eg, where clock = 7.61Mhz TimerB(MAX) = (144*16) * (256 - 0) / 7.61 = 77506.44 microseconds TimerB(MIN) = (144*16) * (256 - 255) / 7.61 = 302.76 microseconds [/CODE] I think that's about it so far. I'm finding so many bits out about this chip that I probably will end up compiling it all into a "YM2612 Undocumented" reference of some kind, at some point in the future. As for what's still to come, I'm making very significant progress on SSG-EG. I hope to have a full description of SSG-EG completed within the next few days, so that should be of interest to some people. I also plan to revisit the detune overflow bug as well, as I haven't got all the needed info in order to emulate that correctly yet. ######## POST p5684 | Eke | 2008-07-01 | t386-075.html very nice... about the timers, could you precise in which condition a timer counter is reloaded: what has been verified: 1/ when the counter underflows what's still unsure: 2/ each time the LOAD bit is set (unlikely) 3/ each time the LOAD bit switch from 1 to 0 or from 0 to 1 (or does the counter restart from the last point where it was stopped ?) 4/ when the timer base value is modified ######## POST p5687 | Nemesis | 2008-07-02 | t386-075.html After some testing, it appears that the timer counter is only reloaded at the following times: 1. When the counter underflows 2. When the load bit is switched from 0 to 1 (IE, the counter is changed from the stopped state to the running state). The counter does not restart from the last point it was up to when it is re-enabled. The timer counter is NOT reloaded when: 1. The load bit is already 1, and reg $27 is written to setting the load bit as 1 again 2. The reset or enable bits are changed 3. The timer counter registers are modified ######## POST p5690 | Eke | 2008-07-02 | t386-075.html Thanks for the clarification again [IMG ./images/smilies/icon_smile.gif] at least , this was not correctly emulated in emulators (counter was reloaded every time the timer load value was changed), this should not affect any games but it's still better to know ######## POST p5691 | TulioAdriano | 2008-07-02 | t386-090.html [QUOTE] Nemesis wrote:4. Timers Two things here. First of all, I've tested the timer A registers, and confirmed that they are NOT "ganged together" like the frequency registers are. Changes to either register $24 or $25 affect Timer A the next time it overflows or is loaded, regardless of the order the registers are written to. Secondly, I've confirmed the timer periods in the YM2612 are half the rate of the timers described in the YM2608 documentation, or in other words, the YM2612 timers take twice as long to count down as the timers in the YM2608. Here are the formulae to calculate the correct timer periods for the YM2612: [CODE BLOCK WITHHELD: 578 chars] [/QUOTE] So, based on the formula above is it correct to state that NTSC MD would have slightly faster timers? For a 7.67 MHz Clock we'd have the Min values for TimerA = 18.77 ms and for TimerB = 300.39 ms. I'd like very much to confirm the precision of this information to update my SFX Editor for Pier Solar. ######## POST p5692 | Nemesis | 2008-07-02 | t386-090.html There would definitely be a slight difference in the timing between an NTSC and PAL system, as the master clock for the system as a whole is slightly different (53.203MHz for PAL, 53.6931 for NTSC), and every operation any of these chips perform, including tracking the YM2612 timers, is ultimately based on the timing pulse. This will also be affecting the frequency of the tones produced by the YM2612, as well as the PSG. A given note will actually produce a very slightly different frequency between an NTSC and PAL system, although the variation would be undetetable to the human ear. You've got to remember though that the difference in the timer periods are still "in time" with the rest of the system. Every device in the system runs slightly faster in the NTSC system, and slightly slower in the PAL system. Code running on the system won't perceive any difference in timer periods between PAL and NTSC units, as while the timers do run a bit faster, the Z80 and M68000 also run faster, in the same proportions. As a result, the code running on the system won't notice these variations. Only the user can percieve them by comparing the output with an independent timing source. ######## POST p5693 | AamirM | 2008-07-02 | t386-090.html Hi, I see the ch3 instrument mystery is solved. Nemesis, your a genius [IMG ./images/smilies/icon_smile.gif] . I have something for you to test out. Ghostbuster track 10 is not emulated correctly by any other emulator except Kega and it would be nice to find out what is it doing too. stay safe, AamirM ######## POST p5695 | Nemesis | 2008-07-02 | t386-090.html Hmmm. On first impressions it could be something to do with the LFO, but I'll need to do a lot more testing to narrow it down. I'll definitely look into it. ######## POST p5696 | TmEE co.(TM) | 2008-07-03 | t386-090.html One interesting thing : Hellfire, on MD2s (and other systems with Sega implementation of YM2612 in the ASIC) the music plays half as slow as it would on Yamaha discrete YM2612 chip (MD1, certain MD2 model). This behaviour is not evident in any emulators I've tried. ######## POST p5697 | Nemesis | 2008-07-03 | t386-090.html Don't tell me that. =P I was hoping to get away with a single standard core for either the Sega integrated or Yamaha discrete YM2612. I've had a brief look, and you're right of course, the music is clearly running at half the rate on the MD2. Personally, I doubt it will turn out to be a difference in the YM2612 that's responsible for this. It's probably a variation in the timing for the integrated Z80 vs the discrete Z80 in the Model 1. I've done a quick check of the YM2612 timers, and they seem to be running at the same rate on the MD1 and MD2. The only other way the YM2612 could affect the speed at which the music progresses would be differences in the delay times between writes on the integrated vs the discrete chip, but my money is on the Z80. It's highly likely there are differences in instruction execution times between the integrated Z80 in the MD2, and the discrete chip in the MD1. Ok, so far there are two remaining sound emulation mysteries: -Ghostbusters track 10 lead sounds wrong -Hellfire music runs twice as slow on MD2 vs MD1 Any other unemulated/only emulated by Kega sound quirks that anyone knows of? ######## POST p5698 | Eke | 2008-07-03 | t386-090.html the SSG-EG part ? The MAME core is emulating it like described in the YM2618 manual, but still get it wrong for some games (try BGM and SFX in Asterix, Bubba 'n Stix... ) according to Steve Snake, SSG-EG is patially broken in YM2612, maybe it is related to the missing SSG part ######## POST p5699 | Nemesis | 2008-07-03 | t386-090.html I'm a fair way along in my testing of SSG-EG mode. Gens, Kega Fusion, and MAME all have attempted support for SSG-EG, but all of the implementations are broken in different ways. I know Steve Snake mentioned once that SSG-EG "doesn't always behave like it should" in the YM2612, but I haven't found any indication of that so far. It's always behaved in a consistent fashion for me, and everything it does matches with the documentation I've seen, once I understood what the documentation was saying. The problem is making sense of what little documentation there is, and figuring out how that relates to what it actually does. The SSG-EG mode wouldn't have been impacted in any way by the removal of the SSG module, as they're logically separate, discrete units, with no direct connection between each other. The SSG-EG envelope generation is handled by the FM module, it just happens to be an implementation of the envelope generator that is used in the SSG module, but it is a separate implementation. Where I'm currently up to with SSG-EG is that it's become clear from analysing the SSG-EG mode that it would be impossible to accurately emulate without first having accurate information on how to calculate the rates of each part of the ASDR envelope, and apply them to calculate the actual attenuation value over time. Minor inaccuracies in this area would be unnoticeable in normal use, but it's critical to get this right in order to emulate the SSG-EG. I'm currently focusing on calculating this information. Hopefully I'll be able to post some comprehesive information on SSG-EG, and the envelope generator as a whole, sometime in the very near future. ######## POST p5700 | AamirM | 2008-07-03 | t386-090.html [QUOTE] Nemesis wrote:Hmmm. On first impressions it could be something to do with the LFO, but I'll need to do a lot more testing to narrow it down. I'll definitely look into it. [/QUOTE] Hi, Last time when looked into it, I found if I ran envelope generator at twice the speed then the sound would get correct (to some extent, since it uses SSG-EG I think that made a bit of difference). One thing to note is that Ghostbusters tries to use channel 6 in special mode. stay safe, AamirM ######## POST p5701 | Nemesis | 2008-07-03 | t386-090.html [QUOTE] ....since it uses SSG-EG I think that made a bit of difference.... [/QUOTE] Doh! That was the first thing I looked for, but it turns out the SSG-EG registers weren't being displayed correctly in my emulator's debugger, so I thought SSG-EG wasn't being used. Yes, it is just bad SSG-EG support which is responsible for the incorrect sound in Gens. I've extracted the culprit instrument (channel 6) and run it through by itself, and Gens is definitely calculating the SSG-EG envelope incorrectly for this channel. Kega gets this particular case correct. There are other cases Kega gets wrong which Gens gets right. ######## POST p5702 | Shiru | 2008-07-03 | t386-090.html About SSG-EG. MAME emulates it incorrectly too. Alone Coder did some fixes which I use in TFM MM. They not fix emulation completely, but makes sound more closer to real chip (YM2203) in some cases. His version of MAME code is included into TFM MM package, replayers/pc/mame/ folder. All changes in code can be found by search for 'Alone Coder' string. ######## POST p5703 | Eke | 2008-07-03 | t386-090.html thanks for the tip and apparently, kode54 (foogep developper) also have made some modifications to the MAME core regarding SSG-EG, someone shoudl ask him about that too ######## POST p5704 | TmEE co.(TM) | 2008-07-03 | t386-090.html [QUOTE] Nemesis wrote:I've had a brief look, and you're right of course, the music is clearly running at half the rate on the MD2. Personally, I doubt it will turn out to be a difference in the YM2612 that's responsible for this. It's probably a variation in the timing for the integrated Z80 vs the discrete Z80 in the Model 1. I've done a quick check of the YM2612 timers, and they seem to be running at the same rate on the MD1 and MD2. The only other way the YM2612 could affect the speed at which the music progresses would be differences in the delay times between writes on the integrated vs the discrete chip, but my money is on the Z80. It's highly likely there are differences in instruction execution times between the integrated Z80 in the MD2, and the discrete chip in the MD1. [/QUOTE] If Z80 would the the trouble maker, then overclocking should help... and I just tried and it did help, but very little. I used 4.5MHz. Also, my MD2 has a discrete Z80, a clone by Toshiba, but this should not cause the slowdown as then my sound engine must sound wrong (slower for example, the poor Z80 is moving incredible amounts of data constantly). The game uses Timers, and the Timers run at same speed, and if there would be a Timer bug, overclocking would not have helped. So only possible cause would be the Busy bit of Sega YM2612 lasting longer... my sound engine completely ignores that bit, and so do many others. One thing I know is that the Busy bit doesn't last same time for all operations. Setting TL values seems to require more time than say writing to DAC. If it helps, on MD2, if you have a PCM playback loop and you wait for the Busy bit, then maximum sampling rate you get is somewhere near 33KHz. I have not done any tests on MD1 as I got my hands on some MD1s only recently. ######## POST p5706 | AamirM | 2008-07-04 | t386-090.html [QUOTE] Shiru wrote:About SSG-EG. MAME emulates it incorrectly too. Alone Coder did some fixes which I use in TFM MM. They not fix emulation completely, but makes sound more closer to real chip (YM2203) in some cases. His version of MAME code is included into TFM MM package, replayers/pc/mame/ folder. All changes in code can be found by search for 'Alone Coder' string. [/QUOTE] Hi, Thanks Shiru. I took some time to make some of those changes in my core and they seem to work pretty well. Didn't tested it heavily though. I'll be doing some more testing (means comparing to Kega [IMG ./images/smilies/icon_smile.gif] ) on this. BTW Nemesis, someone told me that the track 'Ammune Advice' in Dune is not emulated correctly by any emu (including Kega). Although I can't confirm this. Another thing to test out would be whether the behaviour of SSG-EG changes in ch3 special mode. I am thinking of putting up a new 'private' build of Regen with updates to FM core. stay safe, AamirM ######## POST p5707 | King Of Chaos | 2008-07-04 | t386-090.html Wow, glad to see all the progress so far. [IMG ./images/smilies/icon_smile.gif] Aamir, if you need a tester with good ears, I'm your man. [IMG ./images/smilies/icon_wink.gif] Good work Nemesis. [IMG ./images/smilies/icon_smile.gif] ######## POST p5711 | AamirM | 2008-07-05 | t386-105.html Hi, I was doing some SSG-EG stuff in Regen and just noted another thing that only Kega emulates. The sound test number 0xA in Asterix will sound different every time you play it. The difference is in the speed and amplitude of it. It seems these two factors depend on something. [QUOTE] King Of Chaos wrote:Aamir, if you need a tester with good ears, I'm your man. [IMG ./images/smilies/icon_wink.gif] [/QUOTE] Sure, I am still testing a few thing to make sure nothing is broken. I will put it up when I am done. stay safe, AamirM ######## POST p5716 | Nemesis | 2008-07-09 | t386-105.html Several things first up: 1. This is going to be a VERY long post 2. All this information relates specifically to tests I have performed on the YM2612. Although I may not always name the YM2612 specifically, it is implied that all this information has only been tested and verified on the YM2612. I'm going to make a number of references to the way things are implemented in MAME along the way, and specifically, some areas where the behaviour of MAME differs to the way the YM2612 behaves. The implementation in MAME is based on tests done on the YM2203 and YM2151. Note that where I point out that MAME emulates something incorrectly, that simply means the emulation in MAME doesn't match the behaviour of the YM2612. Someone with access to the YM2203 or YM2151 hardware would need to cross-check my findings with those chips to determine whether the MAME implementation is incorrect for all these chips, or whether the YM2612 differs from these chips on these points of behaviour. 3. I'm going to make a LOT of assertions in the following article about how the YM2612 carries out certain operations. I'm not always going to explain how I know these assertions to be true, or the tests I carried out to gather this information. In most cases, it is the combined result of a lot of tests, analysis of sampled results, and a lot of math. Providing a full description of all the tests I carried out would detract from the purpose of this article. Suffice to say, if I make an assertion, it is only because I have specifically tested and proven this aspect to be correct to my satisfaction, even if the information is available in the official documentation, or has been implemented a certain way by another emulator. If there is something I haven't tested and verified for myself, I will note it along the way. If you want to query a specific assertion I make, or you want more info about how I obtained certain results, just ask. 4. I'm going to be pointing out flaws in other people's emulators in this document. Please don't take it personally. Existing emulators are a reference for behaviour on the YM2612 as much as a document is, and I think it's important to be clear what is emulated accurately, and what is not. 5. Credit to Jarek Burczynski for his work on the MAME core. His implementation of the update process for the envelope generator in MAME is extremely accurate, and in the end my testing confirmed much of his implementation as being correct. And now without further ado, here's the result of the last 2 weeks of my life. What you're about to see is a full breakdown of how the YM2612 envelope generator works, including a comprehensive look at the SSG-EG mode. There is not a single emulator in existence at this point in time that implements everything from the following article correctly, so emulator authors should find it informative. YM2612: Clock sources First of all, an overview of the clock. The YM2612 is fed by an external clock source. The clock governs the speed at which the YM2612 performs all of its operations. In order to correctly emulate the YM2612, all aspects of its emulation must ultimately be tied back to the external clock. In the PAL Mega Drive, the external clock is 7610000Hz. Documentation tells us that Yamaha FM chips divide the external clock by the FM prescaler, to get the FM clock. In the case of the YM2612, the FM prescaler appears to be fixed at 6. Here's how you calculate the FM clock: FM Clock = External Clock / FM Prescaler FM Clock = External Clock / 6 FM Clock = 7610000 / 6 = 1268333.33r The FM Clock ultimately determines the sample rate of the YM2612 output, or in other words, the number of actual changes to the output that occur in a given period of time. Here's how you calculate the output frequency of the YM2612: Output Frequency = FM Clock / 24 Output Frequency = 1268333.33r / 24 = 52847.22Hz Interestingly, that divider of 24 is 6*4, or 6 channels times 4 operators. Maybe that's significant, maybe it isn't. All I've done at this stage is to verify the output frequency. This is where things get a little more interesting. The Envelope Generator does NOT update once for each sample the YM2612 produces, as you might initially expect it would. More than that, the envelope generator isn't even tied to the FM clock source. Testing has shown that the clock for the envelope generator is independent of the FM clock. Here is the formula for the rate at which the envelope generator updates: EG Clock = External Clock / 351 This may seem a little odd. I agree. I have tested and re-tested my results however, and the numbers come back the same. The ratio of the frequency output to the envelope generator clock is 1:2.4375. This directly contradicts MAME, which has the output cycle at a ratio of 1:3, or in other words, the envelope generator updates once for every 3 FM clock pulses. Comparing the output from MAME with the output from the YM2612 shows that MAME is incorrect however. Getting this update cycle for the envelope generator correct is important, and SSG-EG mode in particular is very sensitive to this. YM2612: Overview of the Envelope Generator The only purpose of the envelope generator is to generate a single number for each operator. That number is the attenuation value, or in simple terms, the amount to reduce the volume of an operator by. As an attenuation value, a high number produces a low volume, and a low number produces a high volume. The envelope generator outputs its attenuation value as a 10-bit number, giving a range of 0x000-0x3FF/0-1024. This output number is a simple linear progression from 0db to 96db. Here is the weighting for each bit in the 10-bit output of the envelope generator: [CODE] EG attenuation output bit weighting = 96 / 2^10 --------------------------------------------------------------------------------- | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |-------------------------------------------------------------------------------| | 48 | 24 | 12 | 6 | 3 | 1.5 | 0.75 | 0.375 | 0.1875|0.09375| --------------------------------------------------------------------------------- [/CODE] IE, a value of 0x20 is 3db, a value of 0x40 is 6db. Ultimately, the value of the envelope generator comes in its ability to automatically adjust this 10-bit attenuation value over time, based on a set of parameters. Under normal operation (no SSG-EG), the envelope generator creates a basic ADSR envelope. For the sake of brevity, I'm going to assume everyone reading this knows the basics of how the ADSR envelope in the YM2612 works, as it's sufficiently explained in the available documentation. YM2612: Decibels to samples The 10-bit attenuation output of the envelope generator is a linear scale in decibels. The decibel scale itself is logarithmic. If the envelope generator produces a linear increase in values, IE, incrementing the 10-bit output value by 1 for each clock pulse, the final curve that is produced by the YM2612 would be an exponential curve, not a straight line. This conversion from db to sample values is handled by the DAC for the FM module, not the envelope generator. Don't confuse the FM module DAC with the DAC registers at 0x2A/0x2B in the YM2612, that's a different thing entirely. The envelope generator doesn't know what a decibel is, or how it relates to the final samples the YM2612 produces. The only job of the envelope generator is to produce this 10-bit attenuation output. After all calculations have been performed by the envelope generator, and the final attenuation value is handed off to the DAC, it is only then that the conversion from decibels to actual sample values is performed, and it is at this point an otherwise linear progression becomes an exponential progression. This means when you're looking at sampled data and comparing it to the output of the envelope generator, you must always be comparing on the basis of decibels. This is probably obvious to anyone who has a bit of a background in audio, but I'm mentioning this because this confused me initially when I started looking at sampled output. YM2612: Inputs and internal data The envelope generator receives the following register data: [CODE] TL Total Level 7 bits SL Sustain Level 4 bits AR Attack Rate 5 bits DR Decay Rate 5 bits SR Sustain Rate 5 bits RR Release Rate 4 bits SSG-EG SSG-EG Mode 4 bits [/CODE] In addition, the YM2612 receives the following data for each operator, which will be discussed further later on: -Notification about key-on and key-off events -The current 4-bit key-scale value For each operator, the envelope generator stores the following data: -A register indicating the current phase being run in the ADSR envelope (Attack, Decay, Sustain, or Release) -A 6-bit calculated Rate value -The current 10-bit attenuation value -A flag indicating the polarity of the output. When this is set, the attenuation output is inverted. The envelope generator also keeps the following global data which is shared by all operators: -A running cycle counter of unknown size (not really important), which has enough storage for at least 14 bits of data. YM2612: Attack and Decay The ASDR envelope fundamentally only has two states: Attack and Decay. In the Attack phase, the attenuation value decreases exponentially, until it reaches 0. In the decay phase, the attenuation increases in a linear fashion until the attenuation reaches max, at which time no sound is produced for that channel. Decay, Sustain, and Release are all components of the decay phase, and for calculation purposes, they are all identical. With comparable settings, the same output will be produced from all three phases. When it comes to calculating envelopes, the only thing that makes the Decay, Sustain, and Release phases different from each other is that they calculate their decay rates using values from different registers, so the user can provide a different rate of decay for each state. When they are all set with comparable settings, the final waveform will be the same, regardless of what SL is set to or when key-off occurs. YM2612: Calculating Attenuation Values So we know the envelope generator maintains a 10-bit attenuation value for each operator. This is increased in a linear fashion during the decay phase, and decreased in an exponential fashion during the attack phase, but how and when are these adjustments made? This is the core of the envelope generator. The process occurs in several key steps. 1. The Rate Calculation The rate calculation is the first step in calculating attenuation values. The envelope generator performs the rate calculation once, as the operator enters a new phase of the ADSR envelope. It requires two pieces of data first: R: The rate value supplied in the register for the state currently running (AR,DR,SR,RR) Rks: The 4-bit Rate Key-Scaling value for the operator. Refer to page 29 in the YM2608 manual. With those two pieces of data, you then use the following formula to calculate the 6-bit internal rate number: Rate = (2*R) + Rks Special cases: -If R = 0, then Rate = 0, regardless of the value of Rks. -Rate is capped at 63. If the calculation result is greater than 63, Rate=63. -Note that the source registers for AR, DR, and SR are 5-bit, but RR is only 4-bit. In order to convert RR into a 5-bit value for use in this calculation, multiply it by 2, and add 1. In other words, you can think of RR as the upper 4 bits of a 5-bit rate value, with the LSB fixed to 1. This Rate number doesn't give you anything directly, just another number, but it is used in the following stages to adjust the attenuation. 2. The Update Cycle And here's the bit that's not documented. The rate calculation gives you a 6-bit rate value, but how is that actually applied to vary the 10-bit attenuation value over time? First of all, I'm going to throw a few tables at you: [CODE] Table 1: Counter shift values 11 11 11 11 0-3 (0x00-0x03) 10 10 10 10 4-7 (0x04-0x07) 9 9 9 9 8-11 (0x08-0x0B) 8 8 8 8 12-15 (0x0C-0x0F) 7 7 7 7 16-19 (0x10-0x13) 6 6 6 6 20-23 (0x14-0x17) 5 5 5 5 24-27 (0x18-0x1B) 4 4 4 4 28-31 (0x1C-0x1F) 3 3 3 3 32-35 (0x20-0x23) 2 2 2 2 36-39 (0x24-0x27) 1 1 1 1 40-43 (0x28-0x2B) 0 0 0 0 44-47 (0x2C-0x2F) 0 0 0 0 48-51 (0x30-0x33) 0 0 0 0 52-55 (0x34-0x37) 0 0 0 0 56-59 (0x38-0x3B) 0 0 0 0 60-63 (0x3C-0x3F) [/CODE] [CODE] Table 2: Attenuation increment values *0,0,0,0,0,0,0,0 *0,0,0,0,0,0,0,0 *0,1,0,1,0,1,0,1 *0,1,0,1,0,1,0,1 0-3 (0x00-0x03) 0,1,0,1,0,1,0,1 *0,1,0,1,0,1,0,1 0,1,1,1,0,1,1,1 *0,1,1,1,0,1,1,1 4-7 (0x04-0x07) 0,1,0,1,0,1,0,1 0,1,0,1,1,1,0,1 0,1,1,1,0,1,1,1 0,1,1,1,1,1,1,1 8-11 (0x08-0x0B) 0,1,0,1,0,1,0,1 0,1,0,1,1,1,0,1 0,1,1,1,0,1,1,1 0,1,1,1,1,1,1,1 12-15 (0x0C-0x0F) 0,1,0,1,0,1,0,1 0,1,0,1,1,1,0,1 0,1,1,1,0,1,1,1 0,1,1,1,1,1,1,1 16-19 (0x10-0x13) 0,1,0,1,0,1,0,1 0,1,0,1,1,1,0,1 0,1,1,1,0,1,1,1 0,1,1,1,1,1,1,1 20-23 (0x14-0x17) 0,1,0,1,0,1,0,1 0,1,0,1,1,1,0,1 0,1,1,1,0,1,1,1 0,1,1,1,1,1,1,1 24-27 (0x18-0x1B) 0,1,0,1,0,1,0,1 0,1,0,1,1,1,0,1 0,1,1,1,0,1,1,1 0,1,1,1,1,1,1,1 28-31 (0x1C-0x1F) 0,1,0,1,0,1,0,1 0,1,0,1,1,1,0,1 0,1,1,1,0,1,1,1 0,1,1,1,1,1,1,1 32-35 (0x20-0x23) 0,1,0,1,0,1,0,1 0,1,0,1,1,1,0,1 0,1,1,1,0,1,1,1 0,1,1,1,1,1,1,1 36-39 (0x24-0x27) 0,1,0,1,0,1,0,1 0,1,0,1,1,1,0,1 0,1,1,1,0,1,1,1 0,1,1,1,1,1,1,1 40-43 (0x28-0x2B) 0,1,0,1,0,1,0,1 0,1,0,1,1,1,0,1 0,1,1,1,0,1,1,1 0,1,1,1,1,1,1,1 44-47 (0x2C-0x2F) 1,1,1,1,1,1,1,1 1,1,1,2,1,1,1,2 1,2,1,2,1,2,1,2 1,2,2,2,1,2,2,2 48-51 (0x30-0x33) 2,2,2,2,2,2,2,2 2,2,2,4,2,2,2,4 2,4,2,4,2,4,2,4 2,4,4,4,2,4,4,4 52-55 (0x34-0x37) 4,4,4,4,4,4,4,4 4,4,4,8,4,4,4,8 4,8,4,8,4,8,4,8 4,8,8,8,4,8,8,8 56-59 (0x38-0x3B) 8,8,8,8,8,8,8,8 8,8,8,8,8,8,8,8 8,8,8,8,8,8,8,8 8,8,8,8,8,8,8,8 60-63 (0x3C-0x3F) [/CODE] Think of this as a multidimentional array of [64][8]. For each of the possible 64 rate values, there are 8 integer values. Both these tables are based on information provided in MAME, but I've independently tested most of these values against the YM2612 output. I did find a few inaccuracies in the attenuation increment values provided in MAME. The entries marked with an asterisk differ from the values provided in the MAME core (For the record, yes, rate values of 2 and 3, 4 and 5, 6 and 7 do produce an identical output. That's not an error). Ok, so what do these tables do? The following pseudo C-like algorithm describes the basic process the envelope generator carries out each cycle. [CODE] ++globalCycleCounter For each operator //Read the shift value from Table 1 counterShiftValue = counterShiftTable[operator.rate] If (globalCycleCounter % (1 << counterShiftValue)) == 0 //Check the current cycle we're up to (0-7) updateCycle = (globalCycleCounter >> counterShiftValue) & 0x07 //Read the next attenuation increment value from Table 2 attenuationIncrement = attenuationIncrementTable[operator.rate][updateCycle] //Update the attenuation //The attenuation update process happens here. More on that in the next section. Endif Next operator [/CODE] The use of the global cycle counter makes this seem a little more complex than it really is. Basically, the Rate calculation determines two things: 1. How many envelope generator cycles will pass between updates Table 1 lists "Counter shift values" for each possible rate. If the value is 0, the attenuation will be updated every cycle of the envelope generator. If the value is 1, the attenuation will be updated every second cycle. If it's 2, updates will occur every 4 cycles, if it's 3, every 8, etc. At the max value of 11, the attenuation will only be updated once every 2048 cycles of the envelope generator. This allows extremely slow attack and decay. 2. How large the adjustments to the attenuation will be at each update Table 2 gives an 8-cycle loop of adjustment values for the attenuation, for each possible rate. The YM2612 works through these 8 values in a continuous loop. Each time the attenuation value for an envelope is updated, it will use the next sequential value in that loop to adjust the attenuation. In some cases, the value is 0, meaning even though an update cycle is triggered, no adjustments are made to the envelope on that cycle. For the larger rate values, the adjustments are more extreme. The way the attenuation update cycle has been setup allows the envelope generator to create envelopes that have an extremely long decay (up to 10223616 samples, or 193.5 seconds on a PAL Mega Drive, for a rate of 2), while still allowing high-resolution updates to envelopes that have an extremely short decay (as low as 312 samples for a rate of 63). The same is of course true of the attack phase. I think it's important to show how the contents of these two internal tables can be determined by measuring the external output of the YM2612, so allow me to show you a screencap: [IMG http://nemesis.hacking-cult.org/MegaDrive/Documentation/YM2612%20Notes/internal%20tables.png] You can clearly see the steps in the attenuation here, including the pattern of cycles where the attenuation is and is not modified. This wave was created in SSG-EG mode, so the changes in amplitude are larger than normal (more on that later), but you can observe the same effect without SSG-EG active. This particular wave was produced with a calculated rate value of 7. Looking at the table above, that gives it an update cycle pattern of 0,1,1,1,0,1,1,1. You can see that pattern coming through in the output. The counter shift values increase the length between the steps. This waveform also demonstrates the fact that the update cycle is based on a global clock. You can see at the start of this wave that there is a short period where the wave is held at 0db, before the first drop occurs. This drop does not occur at the same spacing as the rest of the changes that follow it. This demonstrates that each operator doesn't have its own running cycle counter. When you key-on an operator on the real system, it's possible for it to start at any point in the 8-cycle pattern of steps, and regardless of how large the spacing between steps, the first change in attenuation may happen at any time from the moment the note is keyed on, depending on what the global counter was up to when key-on occurred. YM2612: Updating and outputting attenuation values In the previous section, some pseudocode was presented showing the update cycle for attenuation values in the envelope generator. The part on actually adjusting the attenuation was left out. The update process is different between attack and decay. The decay phase is simpler, so I'll present that one first. The decay phase: [CODE] operator.attenuation += attenuationIncrement [/CODE] The decay phase is a simple linear progression. You add the increment value to the attenuation on each update. The attack phase: [CODE] operator.attenuation += attenuationIncrement * (((1024 - operator.attenuation) / 16) + 1) [/CODE] The attack phase is a little more complex. The attack phase produces an inverted exponential curve in attenuation, from maximum to minimum. This formula was derived after a little experimentation. This formula is only half the implementation however. In an earlier section, I mentioned that the envelope generator stores a flag for each operator indicating whether the output is inverted. During the attack phase, this flag is set. This effectively does a binary not of the attenuation when it is output, so 0x000 becomes 0xFFF, 0x12F becomes 0xED0, etc. For the output of attenuation values, here's the basic process: -Take a copy of the current internal 10-bit attenuation number -If the output invert flag is set, perform a binary NOT on the number -Add TL to the number. TL is converted to a 10-bit attenuation value first. A limit is applied to prevent the result from overflowing. YM2612: The ASDR envelope This is a quick summary of how the envelope generator manages the ASDR envelope. 1. Key-on occurs. -The envelope generator sets the operator to the attack phase -The rate parameter for the attack phase is calculated -The current attenuation value is cleared -The inverted output flag is set 2. The attenuation is continually adjusted, until attenuation reaches 0 -The envelope generator switches the operator to the decay phase -The rate parameter for the decay phase is calculated 3. The attenuation is continually adjusted, until the attenuation value reaches SL -The envelope generator switches the operator to the sustain phase -The rate parameter for the sustain phase is calculated 4. The attenuation is continually adjusted until it hits max At any point, key-off may occur. If it does, the following immediately occurs. -The envelope generator sets the operator to the release phase -The rate parameter for the release phase is calculated -The inverted output flag is cleared YM2612: SSG-EG mode Ahh yes, now we've reached that part that every emulator gets wrong: SSG-EG mode. Well, right into it. The key feature SSG-EG provides is the ability to repeat the decay and sustain phases of the ASDR envelope over and over again. First of all, here's the SSG-EG register, as it's presented in the YM2608 documentation: [IMG http://nemesis.hacking-cult.org/MegaDrive/Documentation/YM2612%20Notes/ssg-eg%20register.png] You'll see there are 8 patterns presented here, but there isn't any real indication given in the documentation of what these patterns mean, or how they affect the output waveform. What these patterns actually represent is a series of repetitions of the decay and sustain phases of the ASDR envelope, like so: [IMG http://nemesis.hacking-cult.org/MegaDrive/Documentation/YM2612%20Notes/ssg-eg%20pass1.png] [IMG http://nemesis.hacking-cult.org/MegaDrive/Documentation/YM2612%20Notes/ssg-eg%20pass2.png] When the attenuation for the operator hits max, the envelope switches back to the attack phase. If you've got the attack rate set to 0x1F like the Yamaha documentation says you need to, you can effectively say the attenuation is reset to 0, and the envelope mode switches back to the decay phase. The next section will cover the interaction of SSG-EG with the attack phase. Each repetition within these patterns is selected from one of 4 basic modes. These modes affect the way the decay and sustain phases proceed. Each mode shows how the amplitude changes in the decay phase over time. Here are what each of the 4 modes do: 1. Normal [IMG http://nemesis.hacking-cult.org/MegaDrive/Documentation/YM2612%20Notes/ssg-eg%20mode1.png] This mode represents the normal progression of the decay and sustain phases. The amplitude starts at the maximum level, and proceeds to the minimum level, or in other words, the attenuation increases from 0 to max. This is the way the decay and sustain phases would proceed without SSG-EG mode active. 2. Inverted [IMG http://nemesis.hacking-cult.org/MegaDrive/Documentation/YM2612%20Notes/ssg-eg%20mode2.png] The inverted output flag is set for the operator during this repetition. The calculation remains the same, but due to the inverted output, the 10-bit attenuation value will proceed from maximum to minimum, or in other words, rather than "decaying", the output will be increasing in volume. 3. Held [IMG http://nemesis.hacking-cult.org/MegaDrive/Documentation/YM2612%20Notes/ssg-eg%20mode3.png] The output is simply held at maximum attenuation (minimum volume). 4. Inverted Held [IMG http://nemesis.hacking-cult.org/MegaDrive/Documentation/YM2612%20Notes/ssg-eg%20mode4.png] An inverted version of the above. The output is held at minimum attenuation (maximum volume). There's a better description of the 4 bits that set the SSG-EG mode than the one provided in the YM2608 manual. [CODE] SSG-EG: $90-$9E --------------------------------- | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |---------------|---|---|---|---| | / / / / | E |ATT|ALT|HLD| --------------------------------- [/CODE] E = Enable. Unless this bit is set, SSG-EG mode is inactive, and none of the other bits have any effect. ATT = Attack. When this bit is set, the inverted output flag is initially set at the start of the first decay phase. ALT = Alternate. The inverted output flag is toggled after each repetition, alternating between 1 and 0. HLD = Hold. After the decay and sustain phases have completed one full pass, the output is held at the final level. Once hold mode begins, it doesn't end until key-off. If you look at the 8 patterns shown above, you'll see how these bits combine to create the patterns. Note that when you combine the ALT bit with hold, the inverted output flag is toggled before hold mode begins. There is a second effect that SSG-EG has on all envelope generator decay phases, including the release phase. When an SSG-EG mode is applied to an operator, each time the attenuation value is being updated, the increase is multiplied by a factor of 6. Note that the envelope generator does not update any quicker in SSG-EG mode. The update cycles remain the same, but the amount that is added to the attenuation value is increased by a factor of 6 in the YM2612. So, for the sake of completeness, as per the update formulae for the attack and decay phases given above, the following is the update formula for all decay phases under SSG-EG mode. [CODE] operator.attenuation += 6 * attenuationIncrement [/CODE] Note that the rate of change for the attack phase is not affected by SSG-EG mode, so the calculation previously given for the attack phase still stands. There are however a lot of other quirks to mention regarding the attack phase and SSG-EG mode. The interaction of the attack phase and SSG-EG is the topic of the next section. YM2612: SSG-EG and the Attack Phase Officially, Yamaha say the attack rate must be set to 0x1F in order to use SSG-EG mode. You can consider all behaviour of the YM2612 to be officially undefined and unsupported when you combine SSG-EG mode with an attack rate less than 0x1F. The effect of having an attack value less than 0x1F with SSG-EG enabled is that the attack phase will also be included in each repetition of the envelope. SSG-EG does a loop of the attack, decay, and sustain phases. Although the rate of change in the decay phases are increased by a factor of 6 when SSG-EG is applied, the rate of change for the attack phase is unaffected, and is evaluated in its normal fashion. Each repetition of the envelope triggered by SSG-EG will repeat the attack, decay, and sustain modes. The reason Yamaha say not to use the attack phase when SSG-EG is enabled, is because it really does mess things up. There are two issues it creates. The first issue relates to the nature of the calculation being performed to create the attack phase. The attack phase is an inverted exponential curve. The attenuation starts at maximum, and advances very quickly at first, but gradually slows as it approaches minimum attenuation. SSG-EG allows the output to be inverted. This doesn't change the actual calculation that is being performed in order to calculate the attack curve however, it literally just inverts the bits being output. This creates an attack curve which makes several extremely large, obvious steps from 0db, which are the most audible changes, while all the slower gradual changes occur at the other end of the scale, where the change in attenuation is much less noticeable. Here's a screenshot of what you get with an inverted attack curve: [IMG http://nemesis.hacking-cult.org/MegaDrive/Documentation/YM2612%20Notes/inverted%20attack.png] The second issue with combining an attack phase with SSG-EG mode is a little more subtle, and a lot more serious. If you look in an earlier section where I present pseudocode for the update process for the attack phase, you'll see that I mention the attack phase uses the output inversion bit to invert the output. Both the decay and attack phases use an incrementing value to represent the attenuation value, but the attack phase uses this output inversion setting to negate the output, which creates a falling attenuation (rising volume), instead of a rising attenuation (falling volume). The problem is, SSG-EG mode uses the output inversion bit too, and they end up interfering with each other. Sometimes the beginning of the attack phase will override the changes made by SSG-EG mode, and sometimes it will be the other way around. The worst thing is, because the update timing of the attack cycle, like all envelope update cycles, is tied to the global cycle count for the envelope generator, the results are inconsistent. If you repeat a key-on for the operator without changing any settings, you might get quite a different result. With a real attack phase and SSG-EG mode both active, the first two SSG-EG patterns always work correctly, as they don't affect the output inversion bit. Patterns which use the ATT bit to start the output inverted sometimes have their inversion overridden by the attack phase, so they will start non-inverted. Patterns which use the ALT bit are severely affected, as at the start of each repetition, including the first, there's a chance that it could go either way, so each successive repetition may either be inverted or not inverted. There's also often a cross-over period of one update cycle for the envelope phase, where the output inversion bit is set by SSG-EG, then overridden by the attack phase, creating a loud spike between each repetition. Here's a screenshot showing the messed up stuff you can get with the ALT bit set: [IMG http://nemesis.hacking-cult.org/MegaDrive/Documentation/YM2612%20Notes/ssg-eg%20messed%20up.png] And here's a screenshot showing the noise spike you get between each cycle even when it behaves: [IMG http://nemesis.hacking-cult.org/MegaDrive/Documentation/YM2612%20Notes/ssg-eg%20spike.png] Emulating all these quirks would require exact knowledge of when these flags are set and cleared. I may do more work in this area at a later date. YM2612: Current emulator support for SSG-EG mode I haven't checked what emulators do about emulating SSG-EG mode with an attack phase, but here are some notes about current emulator support for SSG-EG mode in the YM2612. -MAME doesn't clear the inverted output flag on release, so release during an inverted output creates a constant tone. MAME also only multiplies the attenuation increase by a factor of 4 in the decay and sustain phases, not 6. Interestingly, MAME also does not adjust the rate of the release phase, which it should. -Kega doesn't do the release phase at all when SSG-EG is active, and messes up held notes. It does get the timing of the decay phase almost perfect however. -Gens doesn't clear the inverted output flag on release, so it has a constant tone problem like MAME does. Gens doesn't seem to increase the decay phase increment at all, so each repetition of the decay phase runs 6 times too slow. YM2612: SSG-EG Test ROM Finally, here's a quick test rom which uses all 8 SSG-EG patterns: http://nemesis.hacking-cult.org/MegaDri ... ssg-eg.bin Here's the source: http://nemesis.hacking-cult.org/MegaDri ... ssg-eg.asm And here's a sample of the output you get on a PAL MD1600 MegaDrive, recorded at 96KHz: http://nemesis.hacking-cult.org/MegaDri ... md1600.rar And on that note, I'm going to get some sleep. ######## POST p5717 | HardWareMan | 2008-07-10 | t386-105.html So, if we return to previous test with oscilloscope: [IMG http://img49.imageshack.us/img49/2044/ym26121mv6.jpg] we get that real single channel sample rate is: [QUOTE] Nemesis wrote:Output Frequency = FM Clock / 24 Output Frequency = 1268333.33r / 24 = 52847.22Hz [/QUOTE] And every channel have silence gap, that is mean 52847,22Hz / 2 = 26423,61Hz. That is close to measured with oscilloscope, but not equival. We need to re-measure that very carefully.... ######## POST p5718 | Nemesis | 2008-07-10 | t386-105.html I don't have access to any equipment right now, but I did my own measurements of the output with an oscilloscope during this process, and the numbers I got back matched this calculation as I recall. I didn't record any of the results though. I'll be able to test this again in a day or two, so I'll measure the output frequency again and snag some results. ######## POST p5719 | Eke | 2008-07-10 | t386-105.html wow, this is great and definitively the technical doc I was waiting for since long long time [IMG ./images/smilies/icon_eek.gif] It describes the internal mechanism pretty well ,and also help me a lot to better understand the MAME emulator implementation just to clarify something, Shiru mentionned this in another thread http://www.spritesmind.net/_GenDev/foru ... .php?t=231 [QUOTE] Shiru wrote:Alone Coder already did some tests on YM2203, which was verified on YM2612 - so we already knew about most of other registers, but not about special mode on/off. So, if we change registers after KEY ON but before KEY OFF: - TL, MULT, DET changes sound properly and immediately - AR, DR, SR, RR, Feedback changes does not affects on currently playing note, but affects properly after new KEY ON I forgot about SL, RS, but generally seems like changing of any registers, which controls amplitude and frequency is affects immediately, and changing of any registers, which controls envelope parameters and algorithm is affects after new KEY ON. Alone Coder did used fact about AR/DR/etc in his compiler of TFM music to preload some values by frame before corresponding KEY ON, that allow to reduce number of register writes per frame (by moving some of writes to prev. frames). That works fine both on TFM device and SMD. [/QUOTE] So, according to you, as the env rates are calculated at the start of each phase, would this mean that register values are also latched at the same time and not all together on Key ON as mentionned above ? btw, just a minor suggestion but, in your frequency calculation and approximations, you should use the the exact clock values:53693175/7 for NTSC and 53203424/7 for PAL [IMG ./images/smilies/icon_wink.gif] this would make 52781.17 Hz for pal ######## POST p5720 | Shiru | 2008-07-10 | t386-105.html [QUOTE] Shiru wrote:- AR, DR, SR, RR, Feedback changes does not affects on currently playing note, but affects properly after new KEY ON [/QUOTE] I was wrong about Feedback, actually it changes sound immediately too. ######## POST p5721 | Nemesis | 2008-07-10 | t386-105.html [QUOTE] So, according to you, as the env rates are calculated at the start of each phase, would this mean that register values are also latched at the same time and not all together on Key ON as mentionned above ? [/QUOTE] Hmmm. To be honest, I didn't thoroughly test this particular aspect. I meant to double-check this point before I made this post, but I ran out of time. I was going to be doing far more extensive tests on when various register changes are applied at a later date. I did get results that indicated rate values could be changed after key-on, but I can't recall if this was combined with CSM or SSG-EG mode at the time, which could potentially have affected the result. Consider this suspect until I can re-test. ######## POST p5722 | Eke | 2008-07-10 | t386-105.html For the record, the MAME core resets the shift & increment values immediately after that: 1) the register values for the according rates (AR,DR,SR,RR) are modified 2)Rks is modified (either KSR register is modified or frequency/block is modified) I think the introduction of Batman&Robin is pretty sensitive to that: I needed to modify the set_ar_ksr function to make it sound correctly PS: some other differences I notice between MAME core and your tests around enveloppe shift & increments: 1/ the MAME implementation use a dedicated enveloppe increment value when calculated Attack Rate is 62 or 63: it uses +16 instead of +8 in this special case. 2/ shift values are wrong when R = 0 (in the formula Rate = 2xR +Rks, Rate should be 0 when R=0), shift value of 0 is usead instead of 11. 3/ in the case of RR, Rate is not forced to 0 if RR = 0 4/ the current attenuation value is NOT cleared at KEY ON ######## POST p5723 | TmEE co.(TM) | 2008-07-10 | t386-105.html http://www.fileden.com/files/2008/4/21/ ... SSG-EG.rar This is the recording of the SSG-EG test ROM from my MD2. I cut out the silence to get smaller file... it seems to work exactly like real YM2612 (but cleaner signal). ######## POST p5724 | Nemesis | 2008-07-11 | t386-105.html [QUOTE] For the record, the MAME core resets the shift & increment values immediately after that: 1) the register values for the according rates (AR,DR,SR,RR) are modified 2)Rks is modified (either KSR register is modified or frequency/block is modified) I think the introduction of Batman&Robin is pretty sensitive to that: I needed to modify the set_ar_ksr function to make it sound correctly [/QUOTE] So that means rate changes are applied immediately in MAME? That could be correct. I'll run some tests on this ASAP. [QUOTE] 1/ the MAME implementation use a dedicated enveloppe increment value when calculated Attack Rate is 62 or 63: it uses +16 instead of +8 in this special case. [/QUOTE] That's their way of eliminating the attack phase. When Rate = 62 or 63 during attack, the attack phase is skipped. MAME use this calculation to immediately force the result to TL, but based on the behaviour I've observed with CSM and SSG-EG, I think it far more likely that the YM2612 doesn't even enter the attack phase, and skips straight to decay when the calculated attack rate is greater than 61. I probably should have written that in as a special case. [QUOTE] 2/ shift values are wrong when R = 0 (in the formula Rate = 2xR +Rks, Rate should be 0 when R=0), shift value of 0 is usead instead of 11. [/QUOTE] There's actually no way to know what the shift value is set to when Rate = 0, and it doesn't make a difference in the end, since no updates are made even when the counter does expire. I've got the shift value set to 11 in this case as it fits with the pattern, but it wouldn't make any difference if they set the shift counter to 0. Likewise, there's no way to know what increment values are used for a Rate of 1, since there's no way for this case to arise. [QUOTE] 3/ in the case of RR, Rate is not forced to 0 if RR = 0 [/QUOTE] That's because RR is a 4-bit value. For the rate calculation, RR is treated as a 5-bit value with the LSB set to 1, and it's after this conversion that the check is made, so Rate can never equal 0 in the release phase. [QUOTE] 4/ the current attenuation value is NOT cleared at KEY ON [/QUOTE] Yeah, I think they might be right about that actually. That calls into question my assertion that the YM2612 uses an output invert bit for the attack phase. Some behaviour in SSG-EG mode suggests it does, but this suggests it doesn't. Well, rather than resetting the contents of the attenuation register, they could be doing a binary NOT at the start of the attack phase, to adjust the attenuation into a compatible number. That sounds most likely to me at this stage. ######## POST p5728 | Stef | 2008-07-11 | t386-105.html Very interesting technicals informations ! Thanks for spending that much time in testing then writing your founds. It's exactly that type of informations we need for accurate emulation, i'm really motived to rewrite a new YM2612 core now :p ######## POST p5729 | TmEE co.(TM) | 2008-07-11 | t386-105.html Go Stef !!! I like Gens, and it desperately needs better sound (with good DAC support so my sound engine would sound NICE) [IMG ./images/smilies/icon_smile.gif] Now that I know how SSG-EG works, I could have some cool instruments [IMG ./images/smilies/icon_smile.gif] ######## POST p5730 | Eke | 2008-07-11 | t386-105.html [QUOTE] notaz wrote: [QUOTE] Eke wrote:what did you do exactly to fix the MAME core ? [/QUOTE] I changed the start of refresh_fc_eg_slot() to this: [CODE BLOCK WITHHELD: 298 chars] Note that this only works when sampling @ 44.1hHz, so it's probably wrong. Multiplier may have something to do with all this too. [/QUOTE] side note: this requires the YM2612 to be emulated at the original frequency (i.e HQ YM2612 mode) to work properly I implemented the Gens interpolation method (anyone know about other resampling algorithm ?) in MAME to get it working but doing this: [QUOTE] fc += SLOT->DT[kc]; if (fc < 0) fc = (UINT32)((double)ym2612.OPN.fn_table[0x7ff*2] / ym2612.OPN.ST.freqbase) + SLOT->DT[kc]; [/QUOTE] apparently make it work is both case (tested @48kHz) ######## POST p5765 | AamirM | 2008-07-18 | t386-105.html Hi, Great work once again Nemesis! Thanks for all the work your doing. stay safe, AamirM ######## POST p5870 | Arbee | 2008-08-02 | t386-105.html Hi. I'm looking to fold all of these fixes into official MAME. I see TFM/MM has a modified MAME core with some fixes and the Flashback fix was posted here. If anyone else has been tinkering with a MAME-derived FM core based on these findings or other tests against real h/w I'd love to see your changes. Please PM me if you'd rather not post them inline. Thanks in advance! ######## POST p5871 | Eke | 2008-08-02 | t386-120.html [QUOTE] Hi. I'm looking to fold all of these fixes into official MAME. I see TFM/MM has a modified MAME core with some fixes and the Flashback fix was posted here. If anyone else has been tinkering with a MAME-derived FM core based on these findings or other tests against real h/w I'd love to see your changes. Please PM me if you'd rather not post them inline. Thanks in advance! [/QUOTE] here is my modified MAME fm.c in genesis plus: http://code.google.com/p/genplus-gx/sou ... sound/fm.c [QUOTE] - added DAC filtering - fixed internal FM timer emulation - removed unused multichip support and YMxxx support - fixed CH3 CSM mode (credits to Nemesis) - implemented PG overflow, aka "detune bug" (Ariel, Comix Zone, Shaq Fu, Spiderman,...), credits to Nemesis - implemented sample interpolation, highly based on GENS code (HQ YM2612) - fixed SSG-EG support, credits to Nemesis and additional fixes from Alone Coder - modified EG rates and frequency, tested by Nemesis on real hardware - fixed EG attenuation level on KEY ON (Ecco 2 splash sound) - fixed LFO phase update for CH3 special mode (Warlock, Alladin), thanks to AamirM [/QUOTE] ######## POST p5873 | Arbee | 2008-08-02 | t386-120.html Thank you VERY much! I appreciate it [IMG ./images/smilies/icon_smile.gif] ######## POST p5885 | Nemesis | 2008-08-06 | t386-120.html For the record, I haven't finished working on this chip. Not by a long shot. Since I last posted I've written my own YM2612 core from scratch, and I'm using that as a testing ground to verify my model of the YM2612 internal structure, based on tests and observed behaviour on the hardware. The next info I post will be a complete description of the phase generator, operator unit, accumulator, and DAC. It might take awhile to complete however. I don't have as much spare time right now as I'd like, and I need to make sure I've got all my facts straight. ######## POST p5886 | HardWareMan | 2008-08-06 | t386-120.html I will wait for this look! ######## POST p5887 | Eke | 2008-08-08 | t386-120.html [QUOTE] Arbee wrote:Thank you VERY much! I appreciate it [IMG ./images/smilies/icon_smile.gif] [/QUOTE] I saw that you have updated fm.c in MAME, that's cool [IMG ./images/smilies/icon_smile.gif] anyway, I forgot to notify about this also [QUOTE] ** - fixed Attack rate refresh (fix Batman&Robin introduction) [/QUOTE] the change is in set_ar_ksr() function: the code assume that if the KSR value is changed, AR will be refreshed during Phase recalculation but even if it is often the case, it seems that under specific condition (if AR and KSR values are changed but kc >> KSR does not change), AR is not refreshed that's why Attack Rate should ALWAYS be refreshed in set_ar_ksr(), as soon as AR is modified. This fixes intro sound in Batman&Robin. ######## POST p5888 | Arbee | 2008-08-08 | t386-120.html Thanks for the tip, Eke. I'll pick that fix up. Incidentally, submitting those changes woke up Jarek B. I pointed him to this thread so hopefully he'll decide to work with you guys and we can get OPN totally perfect. In the meantime at least it sounds like Haze is going to work on HazeMD again now that he can do it without people whining that GEMS games sound wrong, so there's some positive results [IMG ./images/smilies/icon_smile.gif] ######## POST p5890 | Nemesis | 2008-08-09 | t386-120.html Nice! I'll have to give the new core a spin. [IMG ./images/smilies/icon_biggrin.gif] BTW, I notice that CSM support wasn't implemented in the official source, and you note in your development copy that it wasn't working correctly. Is that an implementation issue, or have you found cases where my description doesn't match the expected behaviour? Let me know if you come across any cases that call my results into question. I'm happy to be proven wrong on something, I just want to make sure the right information is out in the public domain. Feel free to ask me any questions you might have as well, either publically or via IM. The same goes for anyone else trying to apply this information. ######## POST p5891 | Eke | 2008-08-09 | t386-120.html no, it works correctly (at least, your test ROM works) initially it didn't work because setting KEY ON then key OFF without updating the enveloppe attenuation level obviously did not work I fixed that by immediately forcing attenuation level to MAX when Key ON is set and Attack rate is maximum (this was usually done on the next enveloppe update) I should fix the commentary asap ######## POST p5898 | Arbee | 2008-08-11 | t386-120.html Has anyone looked into the proper FM/DAC balance yet? In current MAME the DAC seems to be too loud (I think we just mix the written sample value directly into the chip's output) but I'd love to have a tested value to attenuate it by. ######## POST p5917 | Nemesis | 2008-08-13 | t386-120.html I'm partway through that process now. The key to getting the levels right lies in the accumulator. The accumulator takes an (almost certainly) 13-bit input from the operator unit, and definitely produces a 16-bit output for the embedded YM3015/YM3016 DAC for each channel. When the "DAC Enable" flag in register 0x2B is set, the accumulator simply drops the 13-bit operator output for channel 6, and maps the 8-bit "DAC Data" register contents in register 0x2A to that channel instead. In order to get the levels right, we simply need to know: 1. How the 13-bit operator output from one or more operators are combined into the 16-bit output for that channel. This will include any clipping operations which may or may not occur. 2. How the 8-bit DAC Data is converted into a 16-bit value. The accumulator may directly convert the 8-bit data to 16-bit (probably just by using it as the MSBs of the output), or it might convert the DAC data to a 13-bit input, and latch it several times, as if it was latching the output from several operators. I haven't done any specific tests yet to determine how the accumulator maps its inputs to the 16-bit DAC output, but I'll be doing them soon. I'm hoping I can use the test register to digitally latch the full 16-bits of data which are being sent directly to the DAC, which would allow a precise calculation to be made. The notes that are out there describing the test register indicate this should be possible, but I haven't attempted it yet. ######## POST p5919 | HardWareMan | 2008-08-13 | t386-120.html As I already said , YM2612 has time-multiplexed output: 1 DAC and each channel in turn set its current DAC code. And timeslot #6 shared between Ch6 and DAC register (0x2A). [IMG http://img367.imageshack.us/img367/5593/ym26122mg1.jpg] So, IMHO, there are no clipping may occur. ######## POST p5921 | Nemesis | 2008-08-13 | t386-120.html I'm aware of the multiplexed output for the channels themselves. The clipping I was referring to was in relation to the operators. Depending on the algorithm selected for the channel, there may be multiple operators being combined into a single channel, eg, in the case of algorithm 7, you've got 4 13-bit operator outputs being combined into a single 16-bit output. The accumulator might clip the output if you were to try and combine all 4 operators at max volume, depending on how it operates. It should be easy enough to determine how the accumulator is calculating its output, which will answer this question. ######## POST p5926 | TmEE co.(TM) | 2008-08-13 | t386-120.html The sine(s) are distorted at low TL values, but not clipped... at least that is what my recordings showed. ######## POST p5934 | Chilly Willy | 2008-08-13 | t386-120.html [QUOTE] Nemesis wrote:I'm aware of the multiplexed output for the channels themselves. The clipping I was referring to was in relation to the operators. Depending on the algorithm selected for the channel, there may be multiple operators being combined into a single channel, eg, in the case of algorithm 7, you've got 4 13-bit operator outputs being combined into a single 16-bit output. The accumulator might clip the output if you were to try and combine all 4 operators at max volume, depending on how it operates. It should be easy enough to determine how the accumulator is calculating its output, which will answer this question. [/QUOTE] Four 13 bit values cannot clip when combined into a 16 bit value. In fact, a 16 bit value can be the sum of eight 13 bit values w/o clipping. Any more than that might clip. ######## POST p5939 | Nemesis | 2008-08-13 | t386-120.html If they're simply being added, yeah. That might not be the case however. I personally suspect the 13-bit output is being shifted up by 1 to make each operator a 14-bit output (or the operator unit actually does use 14-bit resolution internally. I'll be testing for that), and then they are simply being added, which would mean there would be no clipping. I'll know for sure once I run some tests though. ######## POST p5941 | Eke | 2008-08-14 | t386-135.html If I refer to the YM2151 diagram (this is I know a whole different chip but the data bus width for EG and PG seem to be the same as in YM2612), it is indeed a 14-bit input into ACCumulator [IMG http://img372.imageshack.us/img372/7429/ym2151vj3.th.gif] PS: Arbee, if you read this, I found another little "bug" in SSG-EG implementation for MAME: in function advance_eg_channel, the variable swap_flag is used for all 4 operators but is not reseted between operators. This variable is used to swap (or not) the "invert output" flag at the end of the decay phases. the result is that if two operators use different SSG-EG settings, this will interfere between each other also, as the flag ssgn is modified several time during SSG-EG enveloppe, it should be reinitialized with the initial SSG register value when a KEY ON occurs ######## POST p5958 | Nemesis | 2008-08-15 | t386-135.html Heh, so much for assumptions. -The operator unit does output a native 14-bit value. There's no shifting or other such voodoo. The operator unit calculates a true 14-bit value internally. MAME currently calculates this as a 13-bit value, probably because the way modulation has been implemented suggests a 13-bit value, and I'd made the same assumption in the first build of my core. Turns out we're both wrong. The internal sine table should store a 14-bit value. That's the second time I've thought that YM2151 diagram was wrong about something, and the second time it's turned out to be correct. -Clipping DOES occur when operators are combined. The accumulator maps a single 14-bit operator output to the upper end of the 16-bit dynamic range of the DAC input ( operator output<<2 ). The accumulator limits the result to the 16-bit maximum, so if you were to try and combine two operators with a TL of 0, you'll get the upper half of the wave clipping. Try and combine 4 operators and you'll get the upper 3/4 of the wave clipping. You've got to have the right equipment to measure this properly. If you record from a sound card, you'll see what appears to be a "distorted" wave, as when the wave clips, the soundcard will try and balance the input back to 0, so you'll see a logarithmic decay even though the voltage is holding steady. Use an oscilloscope and the result is clear. -After the DAC data is converted from unsigned to signed (DAC Data - 0x80), the result is simply mapped to the upper end of the 16-bit DAC input ( DAC data<<8 ). Since the lower bits are set to 0, the maximum DAC output is slightly lower than that of an fm channel, due to 6 less bits of significant data. That should be everything required to get the FM and DAC levels right. ######## POST p5959 | TmEE co.(TM) | 2008-08-15 | t386-135.html Guess I have to get rid of couple of parts from my sound card then... Can you test the MD2 DAC output ? MD1 DAC output it filled with aliasing noise, whereas MD2 DAC output is much cleaner. ######## POST p5960 | Nemesis | 2008-08-15 | t386-135.html It occurred to me that the next thing someone's going to want to know is how to balance the YM2612 output against the PSG, so I did some tests on that. All 4 PSG channels at max combined is equivalent to the maximum output of a single YM2612 channel at max. Remember however that the YM2612 multiplexes the channel outputs, as shown by HardWareMan, which means the total output power at a given point in time will never exceed the maximum output of a single channel. It also means that each channel is not actually playing constantly. I'm unsure of the audible effects of multiplexing. It may create an apparent drop in volume for the YM2612, but that's not one you can measure digitally. A minor correction to what I wrote above as well. The output circuitry for the Mega Drive is responsible for the "distorted" waveform when the YM2612 clips, it wasn't my soundcard. If you sample direct from the chip (like I did with my oscilloscope) you get the proper waveform. When I repeat the same process sampling the final output, I get the same waveform on my oscilloscope as I recorded on my PC. The output circuitry has the same effect on the PSG output signal, which being a square wave generator always flatlines, so that's the primary cause of the distorted PSG waveform outlined by Maxim in SN76489.txt. The actual decay when sampling direct from the chip is barely measurable, even at the minimum frequency. ######## POST p5961 | Nemesis | 2008-08-15 | t386-135.html [QUOTE] Can you test the MD2 DAC output ? MD1 DAC output it filled with aliasing noise, whereas MD2 DAC output is much cleaner. [/QUOTE] There's a bit of noise on all the output signals, but I've taken that into account. It wouldn't affect the results of these tests. It might make the DAC sound worse, but I've got enough data to be confident in how the output is generated, before it's affected by analog interference. I probably will do some tests on a MD2 at some point in the future anyway, but right now I haven't got any "modded" MD2's to perform easy tests on. ######## POST p5964 | TmEE co.(TM) | 2008-08-15 | t386-135.html My MD2 is having its audio part completely replaced with something much much better... only noise there is, is the VDP activity noise in the PSG line. ######## POST p5969 | HardWareMan | 2008-08-16 | t386-135.html [QUOTE] Nemesis wrote:-After the DAC data is converted from unsigned to signed (DAC Data - 0x80), the result is simply mapped to the upper end of the 16-bit DAC input ( DAC data<<8 ). Since the lower bits are set to 0, the maximum DAC output is slightly lower than that of an fm channel, due to 6 less bits of significant data. [/QUOTE] I think, you mean "8 bits" not "6 bits", becouse DAC is 16 bit and DAC register is 8 bits. And to convert usigned 8 bit value to signed 8 bit value you need just do "XOR" by 0x80 (or just invert most significant bit). ######## POST p5971 | Nemesis | 2008-08-16 | t386-135.html [QUOTE] I think, you mean "8 bits" not "6 bits", becouse DAC is 16 bit and DAC register is 8 bits. [/QUOTE] No, I meant 6 bits. The output from the operator unit is a 14-bit value. This is shifted up by 2 to create the 16-bit output to the DAC. The DAC register gives an 8-bit value. This is shifted up by 8 to create the 16-bit output to the DAC. Comparing the maximum and minimum possible values from the DAC register (8-bit) with the output from the operator unit (14-bit), there's 6 less bits the DAC register is able to populate with significant data. OTOH, it might be 8-bits afterall, depending on whether the operators are summed before they're converted to 16-bit values, or after. If the operator output is converted to a 16-bit value before each operator is summed, it would be possible for the lower 2 bits to be populated with meaningful data. If the operators were summed as 14-bit values, then the final value was shifted up by 2 when it's output to the DAC, the lower two bits would always be unset. I have yet to confirm which one is correct. [QUOTE] And to convert usigned 8 bit value to signed 8 bit value you need just do "XOR" by 0x80 (or just invert most significant bit). [/QUOTE] You could, but I prefer to do the subtraction, as the processor will then perform sign extension and give a valid 2's compliment value even if you're using a datatype larger than 8-bit. ######## POST p5974 | Nemesis | 2008-08-16 | t386-135.html Wow. Jarek, if you're reading this, you're a genius. I thought the MAME implementation of the operator unit was inaccurate. I just spent the last 6 hours sampling data from the YM2612, and the end result is, I've just confirmed that your implementations of sin_tab and tl_tab really are 100% binary accurate. You've even figured out algorithms to generate the exact datasets [IMG ./images/smilies/icon_eek.gif]. I'm not sure that MAME is going to benefit much from the next batch of info I publish. Everything I've tested so far seems to be emulated perfectly, with the possible exception of the accumulator which I simply haven't checked in MAME. Still, it should be a useful resource for anyone else writing their own core, or who simply wants to better understand the MAME implementation. ######## POST p5975 | Eke | 2008-08-16 | t386-135.html I'm sure he is, just look how his enveloppe generator implementation quite exactly matches your results However, the work you are doing here and the way you document it is still priceless for me, at least to finally understand the MAME implementation ######## POST p6021 | Arbee | 2008-08-19 | t386-135.html Honestly, one of the big problems with MAME's FM has been that it's not well documented. If you'd like to add comments explaining how it works we'd be more than happy to include them. ######## POST p6040 | Nemesis | 2008-08-20 | t386-135.html I might take you up on that. Once I've finished running tests and I've got everything documented, I'll consider going through the MAME core and commenting the implementation. The operator unit in particular needs a lot more info given. I'll get in touch with you when I'm thinking about starting. ######## POST p6089 | Eke | 2008-08-23 | t386-135.html Nemesis, I have a question for you: the MAME core implement some kind of delayed sample operator (MEM) for some algorithms, did you verify this happen on a real YM2612 ? ######## POST p6090 | Nemesis | 2008-08-23 | t386-135.html It's clear that the operator unit does have an internal temporary storage location which can hold the output of at least one operator. There's actually no way to verify what the operator unit stores from any tests on the system, but you can determine a lot from just looking at the way the algorithms are arranged. If you look at all of the algorithms, it seems clear that the YM2612 always calculates operators 1-4 sequentially for each algorithm. You'll notice if you look at each arrangement that in every case, operators are only modulated by operators with a lower number. This is the reason operator 4 never modulates another operator for example. Also, in cases where an operator is only being modulated by a single operator, that operator is always the operator immediately before it in the sequence. We know carriers have their output sent directly to the accumulator and that's the end of it. Operators which directly modulate another operator can simply have their output fed directly into the input for the next operator and they never need to be stored. Some of the algorithms in the YM2612 however involve the output from multiple operators being summed together to modulate another. The only way the operator unit can achieve this is if it has a temporary storage location where it can save the output from one of these operators into, so that it is then free to evaluate the other operator, then sum the result of the two. There's also algorithm 5, which involves the output of operator 1 being fed into all 3 other operators, which again requires the result to be stored. Looking at the algorithms, none of the patterns would ever require more than one result to be stored when the operators are evalulated sequentially. It makes sense that there's a single "mem" slot inside the operator unit which can buffer a single result, which is used as this storage location. The only other option would be that the output of all 4 operators are saved along the way, but seeing as Yamaha designed their algorithms to allow them to get away with only one, and storing the output makes the device more complex, it's almost a given that there is simply a single cached storage location where an operator output can be stored. ######## POST p6092 | Eke | 2008-08-23 | t386-135.html [QUOTE] Operators which directly modulate another operator can simply have their output fed directly into the input for the next operator and they never need to be stored. [/QUOTE] So, with this in mind, would you think Algorithm #0 (all operators chained) would require MEM ? I'm asking this because I got some musics in Mega Turrican (track 3,6,9...) playing wrong with the MAME core: for each of this track, the channel that is wrong always use algorithm #0 with the same configuration (feedback =7,... see attached picture here: http://gxdev.files.wordpress.com/2008/0 ... rrican.jpg ) If I switch to the GENS core, musics are fine If I modify the MAME core to make C1 outputs directly to M2 without using MEM, it seems to fix also the problem You can easily listen the difference using the current in_vgm for winamp which can switch between the two cores http://www.smspower.org/maxim/forumstuf ... in_vgm.zip . vgm files are here: http://project2612.org/details.php?id=140 . incriminated tracks are "Stage 1-2" & "Stage 1 Boss" tracks GENS does not use delayed sample operator btw ######## POST p6093 | Nemesis | 2008-08-24 | t386-150.html Ahh, I hadn't looked into the algorithm implementation in MAME. The MEM storage in MAME has nothing to do with what I was just talking about. They've implemented this MEM storage as something which actually holds over the output of a particular operator for each channel between samples. In MAME, portions of most of the algorithms are actually fed with the calculated MEM value from the previous sample. I'm definitely suspicious about that. I see no reason for this to occur, especially as the operator unit still has to calculate all 4 operators each sample anyway. It's making the device more complicated and less accurate for no good reason as far as I can see. I can't confirm or deny this behaviour until I test for it. I was going to be doing smiliar tests on channel 1 self-feedback. I'll make sure I expand those tests to look for any "delayed sample" behviour from any of the operators. If you modified MAME to remove the MEM storage and it fixed the problem though, that's pretty strong evidence this delayed sample storage doesn't exist for algorithm 0 at least. ######## POST p6094 | Eke | 2008-08-24 | t386-150.html well, I should modify my statement: removing the MEM in algorithm #0 does not solve the problem, I had to modify the self-feedback too so maybe this is more something wrong with self-feedback implementation ######## POST p6095 | AamirM | 2008-08-24 | t386-150.html Hi, I think the delayed sample actually does exists (and its emulated in Regen). The reason? Well it will sound fine in Gens but if you listen very closely to the track 3 of Mega Turrican in Gens some instruments will come a bit early then they should be. Again, you should listen very carefully other wise you won't notice the difference.Here is a recording from the real hardware for the relevant part. I've only seen Regen and Kega that emulate it perfectly. I think its not related to delayed sample. I think it some kind of inaccuracy in envelope generator. stay safe, AamirM ######## POST p6096 | Eke | 2008-08-24 | t386-150.html The problem in MAME core with those tracks seems to be more related to feedback implementation, especially when the feedback value is 7... I re-tested and the MEM delayed sample has nothing to do with that, my bad... About self-feedback, here is how I understand how it works according to the documentation: for slot 1 only, the phase input of the sin tab can be added by a factor of the slot ouput : S1(t) = E1(t) x sin (w1.t + B.S1(t)) The factor B is given by the following table, depending of the feedback register value: [QUOTE] v=0 -> B = 0 v=1 -> B = PI/16 v=2 -> B = PI/8 v=3 -> B = PI/4 v=4 -> B = PI/2 v=5 -> B = PI v=6 -> B = 2.PI v=7 -> B = 4.PI [/QUOTE] In an emulator, I initially thought a straight implementation was doing something like that, for each sample: [QUOTE] PHASE += OUT x feedback_factor OUT = SIN_TABLE[PHASE][ENV] [/QUOTE] but both MAME and GENS implementation use something more like : [QUOTE] PHASE + (OLD_OUT + OUT) x feedfack_factor OUT = OLD_OUT OLD_OUT = SIN_TABLE[PHASE][ENV] [/QUOTE] probably it is more correct, I'm still not sure why About the feedback factor (or shift value), here is how I understand it: the relation between frequency and phase is: w =2xPIxfreq this would mean the B factors (shifts) would be, in term of frequency (calculations in emulators are based on frequencies increment): 0, 1/32 (>>5), 1/16 (>>4), 1/8 (>>3), 1/4 (>>2), 1/2 (>>1), 1 (>>0) and 2 (<<1) Now each core are dealing with this differently: - gens core is doing PHASE += (OUT + OLD_OUT) >> FB where FB = 9 - v - Mame core is doing (only if v !=0) PHASE += (OUT + OLD_OUT) << FB with FB = 6 + v I guess the Gens core is translating the 13-bits OUT value is in a 10-bits phase value (>>3) then applying the feedback factor (see above) I still don't understand the MAME implementation yet ps: for the record, here is the US patent describing self-feedback: http://www.google.com/patents?id=IeA3AAAAEBAJ another one describing FM synth in detail: http://www.google.com/patents?id=GNEzAAAAEBAJ ######## POST p6114 | Nemesis | 2008-08-28 | t386-150.html Well, I can't answer the questions about self-feedback yet. I haven't started doing any serious testing of self-feedback, but when I do, I'll definitely investigate these issues and see if I can track down the cause. I can post a lot of info about other aspects of the operator unit however. They should be an interesting read for someone. I've also finished my testing on the phase generator and accumulator. I'll write up my findings in those areas once I've got some time free. Until then, here's the OPN operator unit in a nutshell. The core of the operator unit is the process involved in evaluating a single operator. That process involves taking a 10-bit output from the envelope generator, a 10-bit output from the phase generator, a 10-bit phase modulation input (generated by the operator unit itself from either self-feedback or modulation by another operator), and producing a single 14-bit result, which is then either output to the accumulator or used to modulate another operator. The steps involved in generating this 14-bit output are IMO the most poorly expressed and documented parts of the MAME core, and you'd be hard pressed to figure out what was going on by looking at the MAME implementation alone. There's one very important thing to note before I say anything more about the operator unit. There's a very big lie in all of the OPN documentation. You will read time and time again that the envelope generator has the power to attenuate the output by between 0db and 96db. This is incorrect. In fact, the envelope generator can only attenuate the output by 0db to 48db. This doesn't change anything about how you implement the envelope generator itself, but for every table you see in any documentation that discusses decibels, you need to divide every value by 2 to get the real attenuation values. TL is actually 0-48db. SL is actually 0-12db (or 48db when all set), and the 10-bit output of the envelope generator itself is of course 0 to 48db. There wouldn't be much point in giving the envelope generator a 96db range. The output of the OPN operator unit is only 14-bit, and lacks the resolution required in order to represent numbers over around 40db attenuation anyway. Anything past that point just outputs 0, so they couldn't have implemented a 96db effective range without a significant increase in the precision of the operator unit. On paper, the calculations the operator unit performs are simple. The operator unit simply has to calculate the sine value for the phase, and attenuate it by the output from the envelope generator. That's it. You could implement the operator unit like this: [CODE] //attenuationBitCount = 10 //phaseBitCount = 10 //operatorOutBitCount = 14 //phase = the output from the phase generator //attenuation = the output from the envelope generator //Calculate the sine value double phaseNormalized = ((double)phase / ((1 << phaseBitCount) - 1)) double sinResult = sin(phaseNormalized * M_PI * 2); //Convert the attenuation to a linear representation of power double attenuationIndividualBitWeighting = 48.0 / (1 << attenuationBitCount); double attenuationInBels = (((double)attenuation * attenuationIndividualBitWeighting) / 10.0); double powerLinear = pow(10.0, -attenuationInBels); //Attenuate the result double resultNormalized = sinResult * powerLinear; //Calculate the 14-bit operator output unsigned int maxOperatorOutput = ((1 << (operatorOutBitCount - 1)) - 1); int result = (int)(resultNormalized * maxOperatorOutput); [/CODE] This was actually my first implementation. It works, and if the YM2612 was a "perfect" device, this would actually be a very accurate implementation. In reality, Yamaha had to actually build the operator unit as a physical device, and they had to do it as cheaply and efficiently as possible, within the boundaries of what was possible with the technology of the time. The end-result is that the operator unit is not as precise as the calculation which is performed above. I doubt you'll hear any audible difference, but if you want to build an accurate emulator, it is possible to perfectly emulate the operator unit calculations performed by the YM2612, but the implementation is a little more complex than the algorithm I've just presented. I've done a lot of analysis and testing, and I've figured out what I believe are the exact steps the real operator unit performs. I can guarantee if you follow the information I'm about to show, you will be able to create a 100% binary exact implementation of the YM2612 operator unit. I've implemented all of this in my YM2612 core, and it works a treat. It is worth noting that MAME already gets a 100% accurate output for this area, though the implementation is a little hard to understand. I found the easiest way to document the core of the operator unit was using a diagram. They say a picture says a thousand words, so hopefully this will save me some typing: [IMG http://nemesis.hacking-cult.org/MegaDrive/Documentation/YM2612%20Notes/ym2612%20operator.png] Here's my (heavily commented) algorithm to build the perfect contents for the sine table: [CODE] //sinTableBitCount = 8 //attenuationFixedBitCount = 8 for(unsigned int i = 0; i < (1 << sinTableBitCount); ++i) { //Calculate the normalized phase value for the input into the sine table. Note //that this is calculated as a normalized result from 0.0-1.0 where 0 is not //reached, because the phase is calculated as if it was a 9-bit index with the //LSB fixed to 1. This was done so that the sine table would be more accurate //when it was "mirrored" to create the negative oscillation of the wave. It's //also convenient we don't have to worry about a phase of 0, because 0 is an //invalid input for a log function, which we need to use below. double phaseNormalized = ((double)((i << 1) + 1) / (1 << (sinTableBitCount + 1))); //Calculate the pure sine value for the input. Note that we only build a sine //table for a quarter of the full oscillation (0-PI/2), since the upper two bits //of the full phase are extracted by the external circuit. double sinResultNormalized = sin(phaseNormalized * (M_PI / 2)); //Convert the sine result from a linear representation of volume, to a //logarithmic representation of attenuation. The YM2612 stores values in the sine //table in this form because logarithms simplify multiplication down to addition, //and this allowed them to attenuate the sine result by the envelope generator //output simply by adding the two numbers together. double sinResultAsAttenuation = -log(sinResultNormalized) / log(2.0); //The division by log(2) is required because the log function is base 10, but the //YM2612 uses a base 2 logarithmic value. Dividing the base 10 log result by //log10(2) will convert the result to a base 2 logarithmic value, which can then //be converted back to a linear value by a pow2 function. In other words: //2^(log10(x)/log10(2)) = 2^log2(x) = x //If there was a native log2() function provided we could use that instead. //Convert the attenuation value to a rounded 12-bit result in 4.8 fixed point //format. unsigned int sinResult = (unsigned int)((sinResultAsAttenuation * (1 << attenuationFixedBitCount)) + 0.5); //Write the result to the table sinTable[i] = sinResult; } [/CODE] And here's my algorithm to build the perfect contents for the power table: [CODE] //powTableBitCount = 8 //powTableOutputBitCount = 11 for(unsigned int i = 0; i < (1 << powTableBitCount); ++i) { //Normalize the current index to the range 0.0-1.0. Note that in this case, 0.0 //is a value which is never actually reached, since we start from i+1. They only //did this to keep the result to an 11-bit output. It probably would have been //better to simply subtract 1 from every final number and have 1.0 as the input //limit instead when building the table, so an input of 0 would output 0x7FF, //but they didn't. double entryNormalized = (double)(i + 1) / (double)(1 << powTableBitCount); //Calculate 2^-entryNormalized double resultNormalized = pow(2, -entryNormalized); //Convert the normalized result to an 11-bit rounded result unsigned int result = (unsigned int)((resultNormalized * (1 << powTableOutputBitCount)) + 0.5); //Write the result to the table powTable[i] = result; } [/CODE] I'd also suggest you wrap the entire power conversion into a function like this: [CODE] unsigned int YM2612::InversePow2(unsigned int num) const { unsigned int shiftCount = num >> powTableBitCount; unsigned int tableIndex = num & ((1 << powTableBitCount) - 1); unsigned int tableEntry = powTable[tableIndex]; unsigned int outputShifted = (tableEntry << 2) >> shiftCount; return outputShifted; } [/CODE] A quick note about fixed point, in case you've never encountered that term before. What "fixed point" means is that a number is an integer value, but one or more of the bits in the number are treated as if they were after the decimal place, so you could represent non-whole numbers like 3.6 or 1.5. In the case of a 4.8 fixed point number, the upper 4 bits are used to represent the whole number portion, while the lower 8 bits are used to represent the "fractional" portion below the decimal place, meaning 1.5 would be represented by 0x180 for example. You'll see that the operator unit uses fixed point math when handling attenuation values. Everything you should need to implement a perfect operator unit is shown above. What I'm going to do now is simply talk about how the actual implementation created by Yamaha relates to the "perfect" algorithm shown right at the start, so you can understand why the Yamaha implmentation works. You'll need to be clear on logarithms first of all. I find it easiest to think of a logarithm as the "reverse" of a power function, so: 10^log10(num)=log10(10^num)=num The envelope generator output is represented in decibels. Decibels are a 10th of a "bel", so a value of 48 decibels is 4.8 bels. Bels are a value on the base 10 logarithmic scale. This means in order to convert back to a linear value, we would need to use a pow10 function, or 10^num, where num is a base 10 number representing a value in bels. In the case of attenuation, you could calculate 10^-num to get a normalized representation of the attenuation in the linear scale. In the first algorithm I presented, this is exactly what we did. The 10-bit attenuation output from the envelope generator was scaled to a floating point value between 0 and 4.8, and converted to a linear normalized result. Yamaha don't do this in the YM2612. Instead, they use a useful property of logarithms to reduce the work the operator unit has to do. Logarithms reduce multiplication down to addition. As you'll find right near the top of the wiki article, log(x * y) = logx + logy. Yamaha took advantage of this fact when designing the OPN operator unit. Rather than convert the attenuation from the envelope generator into a linear scale and multiply it with the output from the sine table, they converted the sine table itself to return values which are also a logarithmic representation of attenuation. This allowed them to simply add the two numbers together, then convert the whole thing back to a linear scale to get the final output, doing away with the need for multiplication. This is the reason the sine table in the YM2612 is built in a non-standard way, it's the reason the power conversion happens after the sine value is attenuated by the envelope generator output, and it's the reason the attenuation from the envelope generator and the output from the sine table are simply added together. There's one remaining quirk about the implementation which needs explanation, and that's all about bases. In the algorithm I presented at the start, we convert the envelope generator output to an expression of attenuation in bels, then use a base 10 power function to convert from bels, which is a base 10 logarithmic scale, to a linear value. You'll see the Yamaha implementation uses a base 2 power function to convert back to a linear value however. That's not a problem for the sine table, as you'll see in the comments for building the sine table that we (effectively) use a base 2 log function to build the table, so the base 2 power function is the valid conversion to turn those back to linear values. What about the envelope generator output though? We talk about the attenuation of the envelope generator in decibels, and doesn't that require a base 10 power function to convert back to a linear scale? First of all, here's the weighting table I gave previously for the 10-bit envelope generator output: [CODE] EG attenuation output bit weighting = 96 / 2^10 --------------------------------------------------------------------------------- | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |-------------------------------------------------------------------------------| | 48 | 24 | 12 | 6 | 3 | 1.5 | 0.75 | 0.375 | 0.1875|0.09375| --------------------------------------------------------------------------------- [/CODE] Given that the official documentation is incorrect, and that the output of the envelope generator is 0-48db, this is the actual weighting of each bit of the output: [CODE] EG attenuation output bit weighting = 48 / 2^10 ---------------------------------------------------------------------------------- | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |--------------------------------------------------------------------------------| | 24 | 12 | 6 | 3 | 1.5 | 0.75 | 0.375 | 0.1875|0.09375|0.046875| ---------------------------------------------------------------------------------- [/CODE] You can see from the diagram above that I indicate this 10-bit output is also actually a 4.6 fixed point value, like so: [CODE] |------Whole number portion-----|---------------Fractional portion---------------| ---------------------------------------------------------------------------------- | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |--------------------------------------------------------------------------------| | 24 | 12 | 6 | 3 | 1.5 | 0.75 | 0.375 | 0.1875|0.09375|0.046875| ---------------------------------------------------------------------------------- [/CODE] First of all, you'll note that these numbers are not in base 10 at all. Bit 6, which is the first "whole number" bit of the output, actually has a reported weighting of 3db. If this was a base 10 number, 3db would be represented by a whole number value of 0x03, not 0x01, and 24db would be represented by a whole number value of 0x18, whereas here it's 0x08. To understand what's going on here, have a look at the code to build the sine table. We need to calculate a log2 value, but there's only a log10 function available. We can in fact convert a log10 value into a log2 value using a useful identity however. As presented in the comments, that identity as it applies to this case is as follows: 2^(log10(x)/log10(2))=2^log2(x)=x In more general terms, if you divide the result of logx(num) value by logx(y), where x and y are two arbitrary bases, you convert bases, giving you the same result as logy(num). What that means is that if we wanted to convert from base 10 logarithmic values, that being the attenuation in bels in this case, into base 2 logarithmic values, we would have to divide the base 10 logarithmic value by log10(2). So, what is the value of log10(2)? Well, it's approximately 0.30103. That's fairly close to 0.3. The guys at Yamaha decided it was close enough. First of all, let's convert our attenuation values from decibels to bels, by simply dividing all the numbers by 10: [CODE] |------Whole number portion-----|----------------Fractional portion----------------| ------------------------------------------------------------------------------------ | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |----------------------------------------------------------------------------------| | 2.4 | 1.2 | 0.6 | 0.3 | 0.15 | 0.075 | 0.0375|0.01875|0.009375|0.0046875| ------------------------------------------------------------------------------------ [/CODE] Now look what happens when we divide all those numbers in our weighting table by 0.3: [CODE] |------Whole number portion-----|---------------Fractional portion---------------| ---------------------------------------------------------------------------------- | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |--------------------------------------------------------------------------------| | 8 | 4 | 2 | 1 | 0.5 | 0.25 | 0.125 | 0.0625|0.03125|0.015625| ---------------------------------------------------------------------------------- [/CODE] Now we see what we've actually got is straight values in powers of 2. This shows the output from the envelope generator is in fact a base 2 logarithmic expression of attenuation, and we can see from the table above it is in fact in 4.6 fixed point form, so we just need to convert it to 4.8 fixed point form, and it's ready to be combined with the output from the sine table. And I think that's everything there is to know about how an operator is calculated. The only other parts of the operator unit which remain relate to how the phase modulation input is calculated for self-feedback and modulation. ######## POST p6115 | AamirM | 2008-08-28 | t386-150.html Hi, Interestingly, track 2 of Mega Turrican uses the so-called "Illegal" CSM mode (with key-on using Timer A) which Nemesis documented. stay safe, AamirM ######## POST p6117 | Nemesis | 2008-08-28 | t386-150.html Awesome. That means everyone can implement CSM support and say they have more accurate YM2612 emulation than Kega. [IMG ./images/smilies/icon_biggrin.gif] ######## POST p6119 | King Of Chaos | 2008-08-28 | t386-150.html Haha, has anyone contacted Steve Snake and informed him of these new developments yet? I'm sure he'd be quite interested to know. [IMG ./images/smilies/icon_smile.gif] ######## POST p6121 | TulioAdriano | 2008-08-28 | t386-150.html I find it quite hard to undestand why he doesn't post here... [IMG ./images/smilies/icon_sad.gif] [IMG ./images/smilies/icon_question.gif] ######## POST p6122 | King Of Chaos | 2008-08-29 | t386-150.html Steve Snake? It's because of his job and real life getting in the way. I'm sure he'd love conversing with everyone and stuff, but he doesn't have the time at all. ######## POST p6124 | Stef | 2008-08-29 | t386-150.html Thanks a tons nemesis, your awesome work and research on YM2612 is very appreciated ! ######## POST p6142 | AamirM | 2008-08-31 | t386-150.html Hi, Nemesis, thanks a lot for the detailed description on operator unit. I have now fixed all the tables in my YM2612 core according to your tests and it has fixed a lot of sound issues in my core. As you said, MAME implementation wasn't clear (though it itself was 100% correct) so I was doing some wrong calculations which resulted in incorrect sound in many games (Urban Strike intro, Sonic 1/2/3/Knuckles special stages etc..) had a pop/crackle. I was thinking I had done them right (as MAME/docs say) but I didn't. Now thanks to you, I have just fixed it [IMG ./images/smilies/icon_smile.gif] . The bug is most apparent in Sonic 3 (Angel Island Zone Act 2) when plane drops the bombs. Listen to it in the latest beta 3, the sound is distorted a lot. Thanks again. AamirM ######## POST p6151 | AamirM | 2008-09-01 | t386-150.html Hi, Although I cannot confirm this but a Regen user has reported that track 12 in BattleTech does not sound like real hardware. And guess what, that track is reproducing GEMS bug but yet it does not goes into high frequency in the real hardware. Again, this needs to be confirmed. Only Gens plays this track correctly according to his recordings because it does not handle the GEMS bug. stay safe, AamirM ######## POST p6155 | AamirM | 2008-09-01 | t386-150.html Hi, The same user has also sent in another interesting thing. He has reported that the sound in the first stage of "Spider-Man and Venom - Separation Anxiety" doesn't sound correct in any emu except Kega (and later I found out that it was correct in the same VGM plugin by blargg [IMG ./images/smilies/icon_eek.gif] ). So I guess there is an overflow again somewhere but I couldn't find any myself after a quick look. stay safe, AamirM ######## POST p6156 | Nemesis | 2008-09-02 | t386-150.html The sound issue in the first level of Separation Anxiety seems to be a self-feedback related issue, or at least it has similar symptoms to track 3 in Mega Turrican. I don't think it's related to detune. I'll be carrying out some tests to try and isolate this problem, and track down the cause. The title screen music has a separate issue however, one that is related to detune overflow. If you compare Kega and Regen, you'll hear the differences. As for Battletech, I'll try it out on the actual hardware this afternoon. I can hear that Regen and Kega are getting a different result though. It's probably just an accuracy issue with how the overflow has been implemented in Regen, Kega, or both. I should buckle down and write up my notes on the phase generator. There's no reason we can't get detune overflow perfect, and it seems like a lot of games rely it. ######## POST p6162 | AamirM | 2008-09-02 | t386-165.html Hi, Updating envelope generator (just the attenuation level) on key-on has completely fixed the spiderman problem for me [IMG ./images/smilies/icon_smile.gif] . It decrease the attenuation level which then results in the correct sound. Although I don't know if its correct or not. I tried doing the same in MAME but it didn't fixed the problem. Must be some other problem with it then or I didn't do it correctly. Although I can tell that MAME's envelope generator is not handling certain cases correctly. I'll dig up some more on this and hopefully can fix those problems with MAME as well. Someone more knowlegeable (Nemesis, Eke) with MAME core should try and look into that. EDIT: Possibly found the cause of MAME problems. Notice how high is the sustain level while sustain rate is low. MAME is surely not handling this right. stay safe, AamirM ######## POST p6166 | King Of Chaos | 2008-09-02 | t386-165.html Great work! I can notice the issue in Separation Anxiety now, might have to test Maximum Carnage soon as well. The only sound issue left I know of is the Robocop issue. [IMG ./images/smilies/icon_wink.gif] ######## POST p6177 | Nemesis | 2008-09-03 | t386-165.html Here's my description of the phase generator. I'm pretty sure this is everything you need to get a 100% accurate implementation of the phase generator, with the exception of phase modulation by the LFO. I'll cover LFO phase and amplitude modulation in a full description of the low frequency oscillator at a later date. Overview of the phase generator: The purpose of the phase generator is to generate a phase value for the operator unit. The phase represents the current progress through a single oscillation of a sine wave. The 10-bit phase output is mapped to a value between 0 and 2PI by the operator unit (or you can think of it as a value between 0 and 360 if you prefer degrees to radians), and is used as the input for a sine function. In practical terms, the phase generator is just a counter. The current value of this counter is output as a 10-bit value, and it increases in a linear fashion, counting from 0x000 to 0x3FF, then overflowing and looping again and again. The rate at which this counter advances is what determines frequencies in the YM2612. If the phase counter overflows exactly once every second, the frequency of the output wave will be 1Hz. If the phase counter overflows exactly 440 times every second, the frequency of the output wave will be 440Hz. Inputs and internal data: The phase generator receives the following register data: [CODE] FNUM Frequency 11 bits BLK Block 3 bits DT Detune 3 bits MUL Multiple 4 bits [/CODE] In addition, the phase generator stores a separate 20-bit internal phase counter for each operator. Inside the phase generator: Even though the phase generator only outputs a 10-bit value for the phase counter, internally, the counter is actually 20-bit, with only the upper 10 bits being output to the operator unit. MAME refers to this as 10.10 fixed point. I wouldn't really call this fixed point format. I prefer to think of it more like the operator unit only accepts the phase with 10 bits of precision, while the phase generator calculates and stores the phase with 20 bits of precision. This extra precision is necessary in order to accurately calculate the phase, particularly with low frequencies. There's an extremely important formula on page 24 of the YM2608 manual relating to the phase generator update cycle. It is as follows: F-Number = (144 * fnote * 2^20 / M) / 2^(B-1) fnote: Pronunciation frequency M: Master clock B: Block data This actually gives away quite a bit of vital information about the phase generator. What this formula is doing is calculating the increment value you would need to provide to cause a 20-bit register (2^20) to overflow the specified number of times each second, if the counter was advanced 144*clock times each second. This tells us each operator gets updated once every 144 clock cycles, it confirms that the phase generator is a counter which is increased in a linear fashion, it tells us that counter is 20-bit, and it shows us the relationship between block and fnum to form the increment value for this counter. There are a few things this formula doesn't explain however. No indication is given as to how the detune or multiple registers are applied for example. A full description of the update cycle is given in the next section. Phase generator update cycle: The phase generator only has to perform one task each cycle, which is simply to advance the phase counter. It does this by calculating the current phase increment value, and adding it to the phase counter. The addition with the phase counter is trivial, so all the real work goes into calculating the current phase increment value. The phase increment is built by starting with the 11-bit fnum register data for the current operator. That fnum value is then adjusted through a series of steps to apply block, detune, and multiple data. Please note that the order is critically important. If you perform the detune adjustment out of order in particular, you will introduce errors into your phase calculation which may be subtle and hard to track down. An overview of these steps, and the register sizes at each stage of the process, are shown in the basic diagram below: [IMG http://nemesis.hacking-cult.org/MegaDrive/Documentation/YM2612%20Notes/phase%20generator%20diagram.png] Here's an in-depth look at each of the three key steps in calculating the phase increment: 1. Shift fnum by block The block data acts as a shift counter for fnum, but it isn't as straight forward as it might initially appear. The block data is a number between 0-7, but if you look at the frequency calculation shown above, you'll see that the calculation applies block data by multiplying by 2^(B-1). That formula does treat the block data starting at 0, meaning when block = 0, you've got 2^-1=0.5, or in other words, when block is 0, the number is shifted down by 1, when it's 1, no shift occurs, when it's 2, the number is shifted up by 1, etc. Just so there's no ambiguity, here's a table showing the relative shift operations each possible value of the block register applies to the fnum data. [CODE] ------------------------------------------------- | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | |-----------------------------------------------| | >>1 | - | <<1 | <<2 | <<3 | <<4 | <<5 | <<6 | ------------------------------------------------- [/CODE] Eg: When fnum = 0x7FF and block = 7, calculation is 0x7FF<<6=0x1FFC0. When fnum = 0x7FF and block = 0, calculation is 0x7FF>>1=0x3FF. As shown on the diagram above, the intermediate result of fnum after the block data is applied is a 17-bit number, allowing for a shift up by 6 with no overflow or limiting of any kind. When shifting down by 1 however, the LSB of fnum is of course discarded, so you do loose precision with a block value of 0. 2. Calculating and applying detune Detune allows a very small offset to be applied to the phase increment value. The implementation of detune is a little more complex, and there are several stages to the calculation. The first step is to calculate the current key-code value for the operator. The key-code is a 5-bit number build from the block and fnum data. The calculation is outlined in the YM2608 documentation, page 25. To add a bit more info on top of what's given in the documentation, here's how I've described it in the comments for my YM2612 core, building on what's written in the YM2608 docs: [CODE] --------------------- | 4 | 3 | 2 | 1 | 0 | |-------------------| | Block |N4 |N3 | --------------------- Where Block is the 3-bit block data, and N4/N3 are built from fnumber as follows: N4=F11 N3=F11&(F10|F9|F8) | !F11&F10&F9&F8 Where FXX indicates bit XX from fnumber, starting with the LSB as 1. [/CODE] The N3 bit obviously requires a bit of work to build, but the other bits are simple. The info above should be all you need to calculate the key-code. Now that we've got the key-code value, just put it to the side for a moment, since there's another step we need to carry out before we're ready to use it. There's a detune register in the YM2612 which we of course need in order to calculate the detune value. The detune register stores a 3-bit value, which determines how extreme the detune adjustment will be, and whether the detune adjustment is positive or negative. The weighting of each bit is shown in the following table from the YM2608 manual, page 26: [IMG http://nemesis.hacking-cult.org/MegaDrive/Documentation/YM2612%20Notes/detune%20register.png] As you can see, this isn't a normal 2's compliment signed value. The detune register uses a primitive sign bit, so you've got a range of -3 to +3, with both -0 and +0, which are equivalent. In order to use the detune data, we need to separate the sign bit, leaving us with just the lower 2 bits of the register value, and a flag indicating whether the detune is positive or negative. With both the key-code calculated, and the detune data interpreted, we now need to calculate the detune adjustment itself. For that, we need to use a table. The YM2608 manual also lists a detune table on page 26, which looks a little something like this: [IMG http://nemesis.hacking-cult.org/MegaDrive/Documentation/YM2612%20Notes/detune%20table.png] Note that where this table lists "block" and "note" down the side, what those really correspond with is the key-code we just calculated. "Block" is of course the upper 3 bits of the key-code, while "Note" is the lower 2 bits of the key code, so essentially the table is listing detune values in order for a key-code from 0 to 0x1F. The other index used here is the lower 2 bits of the detune register data, which we separated above, so we've got a multi-dimensional array of [32][4]. These values that are given in the detune table are accurate. Unfortunately, they're given in Hz. We need to convert these values into actual numbers we can add to our frequency increment value in order to apply them. In fact, that's not too tricky. Looking at the detune table, we can see that every value detune value is given as a multiple of 0.053Hz. There's a little but of rounding coming into play for the higher values, but basically they're all a common factor of 0.053. This tells us that the resolution of the detune table only allows minimum adjustments to the increment value by steps of 0.053Hz, and we can break each value in the table down into a multiple of this adjustment. Now we just need to calculate what fnum value corresponds with a single step in the detune table. For that, we can use the frequency formula given earlier, to calculate the fnum value needed to produce an output of the specified frequency. Taking out the block adjustment which doesn't apply here, the fnum calculation for a frequency of 0.053Hz is as follows: fnum = 144 * 0.053 * 2^20 / 8000000 = 1 (rounded) So basically, we've just confirmed a single step in the detune corresponds with a single number adjustment to the frequency increment value. Note that we used a clock frequency of 8MHz in this calculation, as all the values given in the YM2608 manual have been calculated assuming a clock rate of 8MHz. After converting all those numbers in the detune table from Hz to fnum values, you get something a little like this: [CODE] // Detune Key-Code // 0 1 2 3 {0, 0, 1, 2}, //0 (0x00) {0, 0, 1, 2}, //1 (0x01) {0, 0, 1, 2}, //2 (0x02) {0, 0, 1, 2}, //3 (0x03) {0, 1, 2, 2}, //4 (0x04) {0, 1, 2, 3}, //5 (0x05) {0, 1, 2, 3}, //6 (0x06) {0, 1, 2, 3}, //7 (0x07) {0, 1, 2, 4}, //8 (0x08) {0, 1, 3, 4}, //9 (0x09) {0, 1, 3, 4}, //10 (0x0A) {0, 1, 3, 5}, //11 (0x0B) {0, 2, 4, 5}, //12 (0x0C) {0, 2, 4, 6}, //13 (0x0D) {0, 2, 4, 6}, //14 (0x0E) {0, 2, 5, 7}, //15 (0x0F) {0, 2, 5, 8}, //16 (0x10) {0, 3, 6, 8}, //17 (0x11) {0, 3, 6, 9}, //18 (0x12) {0, 3, 7,10}, //19 (0x13) {0, 4, 8,11}, //20 (0x14) {0, 4, 8,12}, //21 (0x15) {0, 4, 9,13}, //22 (0x16) {0, 5,10,14}, //23 (0x17) {0, 5,11,16}, //24 (0x18) {0, 6,12,17}, //25 (0x19) {0, 6,13,19}, //26 (0x1A) {0, 7,14,20}, //27 (0x1B) {0, 8,16,22}, //28 (0x1C) {0, 8,16,22}, //29 (0x1D) {0, 8,16,22}, //30 (0x1E) {0, 8,16,22}}; //31 (0x1F) [/CODE] So we can see the maximum adjustment that detune will make to the increment value is 22. Using the lookup table above, we're able to calculate phase adjustment values for detune, but we still have to factor in the sign bit from the detune register. For positive detune adjustments, the numbers from the table can be directly added to the intermediate fnum result. When the sign bit is set however, we have to calculate the 2's compliment of the detune value before we can add it to fnum, and this 2's compliment value needs to be sign-extended to a 17-bit value. To give some examples about how detune is applied, consider a case where fnum is 0x100 and block is 5. In this case, we perform the following operation: 0x100 << 4 = 0x1000 So, our intermediate 17-bit fnum result before applying detune is 0x1000. The next step is to calculate the key-code value, which from a block of 5 and fnum of 0x100, is 0x14. Let's say the detune register data is 0x3. When we look at the table above, a detune value of 3 and a key-code of 0x14 gives a detune adjustment value of 11(0xB). So, to apply detune, we simply add that detune adjustment value to the intermediate fnum result: 0x1000 + 0xB = 0x100B And that's fnum adjusted for detune. Now consider the case where the detune data is 0x7. In this case, the detune adjustment is -3. First of all, we read the detune adjustment value for +3 from the table, which is of course still 11(0xB). We need to calculate the 2's compliment of this number now, in a register size of 17-bit, like so: 0 - 0xB = 0x1FFF5 (17-bit) We now add that inverted detune value to the intermediate fnum result, and cap the result to 17-bits: 0x1000 + 0x1FFF5 = 0xFF5 (17-bit) Since 0x1000 - 0xB = 0xFF5, we can see we've obtained the correct result. It's up to you how you want to implement this in code, whether you use 2's compliment and addition, or just use subtraction for negative values, what you represent using signed and unsigned types, etc, but these are the results you need to get at the end. There's some further discussion of detune in the next section. 3. Applying the frequency multiplier This step is fairly simple. The multiple register provides a 4-bit value to the phase generator. This 4-bit value specifies a multiplier for the frequency, which in real terms means it's a multiplier for the frequency increment value. There's another good table in the YM2608 manual which shows the multiplier each possible value of the multiple register applies to the frequency increment value: [IMG http://nemesis.hacking-cult.org/MegaDrive/Documentation/YM2612%20Notes/multiple%20register.png] You can see from this table that the multiple register data is simply directly multiplied with the frequency increment value, except for the special case of 0 where it acts as a 0.5 multiplier, or in other words, it halves the frequency increment. For an example of how the multiplier is applied, consider a case where fnum is 0x1FF and block is 4. From the first stage of the process, we perform the following operation: 0x1FF << 3 = 0xFF8 So, the intermediate 17-bit frequency increment value is 0xFF8. Skipping past detune, let's say the multiple register is loaded with the value 0x8. Looking at the table above, that means the multiplier is 8, so: 0xFF8 * 8 = 0x7FC0 So, our final frequency increment value in this case is 0x7FC0, after the multiplier has been applied. If the multiple data was 0, our multiplier would be 0.5 instead, so: 0xFF8 * 0.5 = 0x7FC In code, you'll probably want to implement the 0.5 multiplier special case as a simple shift down by 1. If you correctly apply these main frequency calculation steps, you'll be able to calculate the correct phase increment values for each update. All you've got to do now is add this phase increment value to the stored 20-bit phase value for each operator on each update cycle, and you've got a working phase generator. There is a special case to consider when implementing the phase generator however, which is covered in the next section. Detune overflow: The detune setting allows a negative detune value to be applied, which will subtract a small frequency adjustment from the supplied fnum. This begs the question, what happens when fnum is smaller than the number the detune setting is subtracting? The answer is, you get an overflow. The register size at the time the detune value is applied is 17-bit, so if detune attempted to subtract a value of 1 from an fnum of 0, the result would be 0x1FFFF. You can't get an overflow when detune is positive, as the max output from the shift step is 0x1FFC0 (0x7FF<<6), and the max value we add through detune is 0x16(22), giving a combined total of 0x1FFD6. As you can see, you can actually slightly exceed the maximum intermediate frequency you could normally obtain with fnum and block using detune overflow. The GEMS sound driver for the Mega Drive has an inbuilt instrument which makes use of detune overflow. A large number of Mega Drive games use the GEMS sound driver, and a significant number of those use this instrument, so if you're working on a Mega Drive emulator, you'll get bad sound in a lot of games unless detune overflow is implemented correctly. There's actually a second point in the frequency increment calculation where an overflow can occur, and that's when the frequency multiplier is applied. The input to the multiplier is 17-bit, the output from the multiplier is 20-bit, but when you multiply the maximum 17-bit input (0x1FFFF) by the maximum multiplier value (15), you get a result of 0x1DFFF1, which is well over the maximum 20-bit output of 0xFFFFF. This upper bit of data is lost, so an output of 0x1DFFF1 is equivalent to 0xDFFF1. You shouldn't have to do anything special to handle multiplier overflow however, as the phase counter itself is only 20-bit, so this upper bit is going to be discarded anyway when you add the final frequency increment value to the phase counter. 20-bit or 21-bit?: After reading the information above, you may wonder if the internal phase counter is really 21-bit. It wouldn't have any radical impact at all if the phase counter was actually 21-bit, and the block register actually only shifted up, rather than shifting down one place when the block data was 0. This is certainly a simpler system to emulate. If you test this on the hardware however, you'll find this is not the case. If the register was really 21-bit, you would still have 11 bits of precision in fnum when block = 0. As it turns out, when block is set to 0, an fnum value of 1 = 0, 3 = 2, etc. This shows that the LSB of fnum is lost when block = 0, which means the phase counter is actually 20-bit. A small sidenote really, but you might be left wondering about this like I was, so I thought I'd mention it. So yeah, I think that just about covers it. Anyone who worked on adding support for the detune overflow bug might want to doublecheck their implementation. The magic register size is 17-bit. If you're representing frequency numbers properly, all you should have to do is mask your increment value to a 17-bit result before applying the frequency multiplier. ######## POST p6179 | Nemesis | 2008-09-03 | t386-165.html [QUOTE] AamirM wrote:Updating envelope generator (just the attenuation level) on key-on has completely fixed the spiderman problem for me [IMG ./images/smilies/icon_smile.gif] . It decrease the attenuation level which then results in the correct sound. Although I don't know if its correct or not. [/QUOTE] Well, an envelope generator update should definitely occur at the same time as the key-on event is processed, or rather, a key-on event shouldn't be processed until the start of an envelope generator update cycle. I must say though, I'm not entirely clear on exactly what you did to fix the problem. Can you provide a bit more info? Unfortunately, Separation Anxiety doesn't want to run properly in my emulator right now (Z80 bug somewhere), so I don't know if my core has the same problem. From what you said, one thought about a possible cause of this problem jumped to mind though, which is in how maximum attack rates are handled. When the calculated rate value for the attack phase is 60-63, I think you need to immediately switch the attenuation to minimum, and enter the decay phase. You should never generate a single sample based on the attack phase in such a case. The very first sample you output for that operator after the envelope generator has processed the key-on event should be starting from TL and decaying from there. Perhaps something relating to this is the cause of the problem? [QUOTE] Possibly found the cause of MAME problems. Notice how high is the sustain level while sustain rate is low. MAME is surely not handling this right. [/QUOTE] There's a number of things about the envelope generator I didn't think about when I was doing my tests in that area, and one of them was what happens when, in a single update cycle during the decay phase, the envelope generator moves past the sustain level. In most cases the attenuation isn't going to fall perfectly on the sustain level when the decay phase is completed. There's only two possibilities I can see. One possibility is that if the decay phase moves past the specified sustain level, the decay phase begins from that level instead of the sustain level. This would mean if you have a very fast decay and a slow sustain, the decay phase might jump significantly past the sustain level, and the decay may begin at a significantly higher attenuation level than intended. I think it's more likely that the YM2612 clamps the decay phase to the sustain level, so if the last update cycle for the decay phase tries to move past the sustain level, the envelope generator forces the result to SL, and changes to the sustain phase at that point in time, in preparation for the next update cycle. Perhaps MAME is doing the first, and jumping past SL? I'm going to go back and do more testing on the envelope generator at some point, and these little remaining ambiguities are things I'll be targeting. ######## POST p6181 | AamirM | 2008-09-03 | t386-165.html Hi, [QUOTE] I think it's more likely that the YM2612 clamps the decay phase to the sustain level, so if the last update cycle for the decay phase tries to move past the sustain level, the envelope generator forces the result to SL, and changes to the sustain phase at that point in time, in preparation for the next update cycle. Perhaps MAME is doing the first, and jumping past SL? [/QUOTE] Yes, exactly. And in fact, forcing the envelope to sustain phase instead of decay on key-on or envelope update in MAME seems to fix the wrong sound in mega turrican. But sound in other channels get broken but its expected of course. stay safe, AamirM ######## POST p6204 | Eke | 2008-09-07 | t386-165.html Nemesis, this is awesome. I already figured some stuff by reading/analysing the MAME implementation but I never figured where they get the bits width for fixed point calculation. The fact you double-checked everything from testing is just great [IMG ./images/smilies/icon_biggrin.gif] now, did you find any mistakes in Operator (sin table, db to linear conversion, ...) or Phase generator (bit width) operations in the MAME implementation ? ######## POST p6205 | Nemesis | 2008-09-08 | t386-165.html The MAME operator unit gets a perfect result (mainly implemented through sin_tab and tl_tab), so there are no mistakes to fix there, although personally if it was my core, I'd rewrite some of it to make it simpler if nothing else (at the cost of a little extra overhead most likely). I know the detune table in MAME is correct, but I haven't checked the actual phase increment calculation. We know the MAME core didn't handle detune overflow, so it obviously wasn't perfect before, but I haven't compared my test results to the MAME implementation in this case. ######## POST p6219 | Eke | 2008-09-10 | t386-165.html Ok, I fixed the problem in Mega Turrican track #3 (and some others) COntrary to what I was saying, this is indeesd an Envelope Update issue: the game set Operator #2 with a SL value of 0 and a maximal Attack Rate (0x1F), and the enveloppe generator should directly start at the substain phase Modifying the Key ON function this way fixed it: [QUOTE] if ((SLOT->ar + SLOT->ksr) < 94 /*32+62*/) { SLOT->state = EG_ATT; /* phase -> Attack */ SLOT->volume = MAX_ATT_INDEX; /* fix Ecco 2 splash sound */ } else { /* directly switch to Decay (or Substain)*/ SLOT->volume = MIN_ATT_INDEX; SLOT->state = (SLOT->sl == MIN_ATT_INDEX) ? EG_SUS : EG_DEC; } [/QUOTE] similar thing should be done in "advance_eg_channel" function, at the end of the attack phase and, in SSG-EG mode, at the end of the substain phase EDIT: another way to fix it is, as aamir said, to always call advance_eg_channel when a KEY ON occurs to adjust the state & level correctly also, I'm wondering, contrary to the GENS core, the MAME core is updating the enveloppe BEFORE calculating the operator output, shouldn't that be the contrary as for PHASE calculation (output a sample then update the counters).. the only difficulty being that Enveloppe Counter is updated between each 2nd and 3rd samples (352/144) ######## POST p6220 | AamirM | 2008-09-10 | t386-165.html Hi, [QUOTE] COntrary to what I was saying, this is indeesd an Envelope Update issue: the game set Operator #2 with a SL value of 0 and a maximal Attack Rate (0x1F), and the enveloppe generator should directly start at the substain phase [/QUOTE] Haha, told ya [IMG ./images/smilies/icon_wink.gif] . By the way, did it fix Spider Man issue too? stay safe, AamirM ######## POST p6221 | Eke | 2008-09-10 | t386-165.html which issue in which Spiderman game ? the mega turrican one was the only one I was still looking for but there are certainly other ######## POST p6222 | AamirM | 2008-09-10 | t386-165.html Hi, Listen to the first stage of Spiderman - Separation Anxiety. Has same sort of problems like in Mega Turrican. I have fixed it in Regen by updating envelope on key on but couldn't fix it in MAME. stay safe, AamirM ######## POST p6224 | Nemesis | 2008-09-11 | t386-165.html [QUOTE] the only difficulty being that Enveloppe Counter is updated between each 2nd and 3rd samples (352/144) [/QUOTE] .... umm, yeah, about that..... [IMG ./images/smilies/icon_smile.gif] When I was doing my tests on the envelope generator and calculating the update cycle, I had assumed the minimum output level was reached when the envelope generator hit max attenuation. As I discovered when I was doing my tests on the operator unit, due to precision limitations, the minimum output level is actually reached before the envelope generator reaches the maximum attenuation (around 40db, instead of the full 48db). My calculations to determine the envelope generator clock rate were based on total decay times, but since I was measuring the final output, and the final output was hitting minimum before the envelope generator output was hitting maximum, this invalidates my findings. The envelope generator update cycle is actually slower than I had calculated. Going back to my numbers and making a rough adjustment for the point at which I now know precision cut off the output, the envelope generator clock rate is in fact 1/3 of the FM clock, which means MAME was right all along. Just so there's no confusion, here's what I said previously in the "Clock Sources" section of my discussion on the envelope generator: [QUOTE] This is where things get a little more interesting. The Envelope Generator does NOT update once for each sample the YM2612 produces, as you might initially expect it would. More than that, the envelope generator isn't even tied to the FM clock source. Testing has shown that the clock for the envelope generator is independent of the FM clock. Here is the formula for the rate at which the envelope generator updates: EG Clock = External Clock / 351 This may seem a little odd. I agree. I have tested and re-tested my results however, and the numbers come back the same. The ratio of the frequency output to the envelope generator clock is 1:2.4375. This directly contradicts MAME, which has the output cycle at a ratio of 1:3, or in other words, the envelope generator updates once for every 3 FM clock pulses. Comparing the output from MAME with the output from the YM2612 shows that MAME is incorrect however. Getting this update cycle for the envelope generator correct is important, and SSG-EG mode in particular is very sensitive to this. [/QUOTE] All of that is wrong. The phase generator clock is the same as the FM clock: PG Clock = FM Clock Since there are 6*4=24 operators to update, and a single operator is updated each clock cycle, each operator gets updated once every 24 phase clock cycles. The envelope generator clock is 1/3 of the FM clock: EG Clock = FM Clock / 3 Since there are 6*4=24 operators to update, and a single operator is updated each clock cycle, each operator gets updated once every 24 envelope clock cycles, or once every 24*3=72 FM clock cycles. ######## POST p6225 | Nemesis | 2008-09-11 | t386-165.html Looking at the envelope generator update process in the MAME core, specifically in the advance_eg_channel function, I suspect you need to change this: [CODE] if ( SLOT->volume >= SLOT->sl ) SLOT->state = EG_SUS; [/CODE] into something like this: [CODE] if ( SLOT->volume >= SLOT->sl ) { SLOT->volume = SLOT->sl; SLOT->state = EG_SUS; } [/CODE] for both the SSG-EG and normal update steps. This will ensure that the decay phase doesn't move past SL, which will prevent over-attenuated output when you have a high SL (low attenuation), a fast decay, and a slow sustain. I think you'll find the YM2612 is performing the exact same operation to prevent the decay phase from eating into sustain. This is what I'm doing in my core. ######## POST p6226 | Eke | 2008-09-11 | t386-165.html [QUOTE] AamirM wrote:Hi, Listen to the first stage of Spiderman - Separation Anxiety. Has same sort of problems like in Mega Turrican. I have fixed it in Regen by updating envelope on key on but couldn't fix it in MAME. stay safe, AamirM [/QUOTE] did not find any problem with this game at first listening, maybe it's due to my implementation I however got a new problem with Alisia Dragon, the track of the first level now starts with a bigg buzz sound, this can also be reproduced in sound test (track 03). Strangely, if I play track 00 then switch to track 03; it plays fine, maybe it has something related to key on/enveloppe update [QUOTE] Looking at the envelope generator update process in the MAME core, specifically in the advance_eg_channel function, I suspect you need to change this: [/QUOTE] yes, I recently changed this also. According to Gens sourcecode, it fixes Gynoug exploding SFX thanks for you precision about EG clock anyway ######## POST p6233 | AamirM | 2008-09-11 | t386-165.html Hi, [QUOTE] My calculations to determine the envelope generator clock rate were based on total decay times, but since I was measuring the final output, and the final output was hitting minimum before the envelope generator output was hitting maximum, this invalidates my findings. The envelope generator update cycle is actually slower than I had calculated. Going back to my numbers and making a rough adjustment for the point at which I now know precision cut off the output, the envelope generator clock rate is in fact 1/3 of the FM clock, which means MAME was right all along. [/QUOTE] And here was I thinking why SSG-EG was going so wrong [IMG ./images/smilies/icon_smile.gif] . I've been working for the past 4 hours or so trying to revert back the changes in my core. Now after these changes, SSG-EG in Regen sounds very close to the SSG-EG recording you posted. And Buba 'n' Stix track 5 seems to have been fixed too (it doesn't produce any crackling anymore). Good thing this mistake has been caught early. Nice work again, Nemesis. I am feeling very happy right now [IMG ./images/smilies/icon_smile.gif] . [QUOTE] did not find any problem with this game at first listening, maybe it's due to my implementation [/QUOTE] Maybe it is somehow fixed in your implementation. Did you compare with Kega? [QUOTE] I however got a new problem with Alisia Dragon, the track of the first level now starts with a bigg buzz sound, this can also be reproduced in sound test (track 03). Strangely, if I play track 00 then switch to track 03; it plays fine, maybe it has something related to key on/enveloppe update [/QUOTE] Ahh..I remember I had this problem as well when I used MAME core in Regen (you can still hear it in 0.77, the last version to use MAME core). I remember that it was related to SSG-EG. You should look there. stay safe, AamirM ######## POST p6237 | Eke | 2008-09-11 | t386-180.html [QUOTE] Ahh..I remember I had this problem as well when I used MAME core in Regen (you can still hear it in 0.77, the last version to use MAME core). I remember that it was related to SSG-EG. You should look there. [/QUOTE] thanks, indeed it was a problem with the SSG-EG invert flag: I reseted it when key-off occurs at Nemesis explained but the game will set it again after KEY OFF by writing 0xFF into the SSG-EG register before later setting it back to 0x00 before next KEY ON), which will activate SSG-EG enveloppe type during this time. Also, the write will mess up the invert flag status which should not be set during Release Phase. I fixed it by checking we are not in Release Phase before eventually inverting the output in SSG-EG mode [QUOTE] if ((SLOT->ssg&0x08) && (SLOT->ssgn&2) && (SLOT->state > EG_REL)) out ^= MAX_ATT_INDEX; [/QUOTE] but I'm wondering if this write to SSG-EG register is intentional and should really affect the Release Phase ? Maybe SSG-EG register state is latched on Key ON only and can not be affected during Enveloppe update ? Also, what would happen if you write the register during Decay or Substain phase ? Anyway, I don't think this game use SSG-EG intentionnaly in any way, it just has no sense in setting it to 0xff then to 0x00 ######## POST p6238 | Nemesis | 2008-09-11 | t386-180.html I still need to do tests to determine when various register changes take effect. I think you'll find most of the decisions about SSG-EG are only made when changing between envelope generator states, but I think it's quite possible that toggling the SSG-EG enabled state during the release phase (or the sustain and decay phases) could cause the 6x multiplier effect on the attenuation increment to be toggled on or off as the phase progresses. Perhaps this is what they are trying to do in Alisia Dragoon? They'd have to control the timing in software, but if it was done correctly, you could effectively achieve two stages of release, with the second stage being 6 times slower than the first. ######## POST p6239 | AamirM | 2008-09-11 | t386-180.html Hi, My guess would be that it toggles between 4x and 6x multiplier rather than off. stay safe, AamirM ######## POST p6255 | Snake | 2008-09-13 | t386-180.html [QUOTE] TulioAdriano wrote:I find it quite hard to undestand why he doesn't post here... [IMG ./images/smilies/icon_sad.gif] [IMG ./images/smilies/icon_question.gif] [/QUOTE] Well one reason would be that I didn't know of it's existance [IMG ./images/smilies/icon_wink.gif] I've spent the best part of the last 4 years being almost completely absent from the internet. And, yeah, life is more than a bit evil right now. I won't go into it here. Interesting stuff. I think I have most of it correct, but I've forgotten more about the YM2612 than I remember. There were a few things I knew weren't correct but I think I've already fixed most of them. Really should release a new build at some point. And cross reference with these documents. For the record I've not been intentionally hiding any findings, Stef will tell you I sent him the source for an early Kega implementation, but he likes to try to figure things out on his own [IMG ./images/smilies/icon_smile.gif] It's only more recently that people have been asking, and I've been not very good at remembering to look things up. But if there's anything I can add to the discussion I shall do so. Yes, most of what I found was done via hacking at the hardware rather than documentation. It also helped that I already understood how FM synthesis worked. But I'd kill for a YM2612 on a PC card. The CSM stuff is news to me, though. I haven't really looked at this since 1997, when I was talking to Tatsuyuki Satoh (original MAME core, and the one I think Stef based his on) - he has some japanese documents which suggested CSM mode was useless without the timer interrupts. Timer A would do key ON, and you'd have to key it OFF again yourself in an interrupt. We tried to figure it out but I eventually decided it'd be pretty useless on the Genesis. The only thing (as far as I remember) that I still want to know is this: The YM2612 (apparently, and I don't remember where I found this) output DAC has one bit less than it would normally need. Something is done to remove one bit before it goes into the DAC. It appears to be some sort of compression/scaling which results in values close to silence being much louder. If you can figure that out I'd be very interested. I no longer have access to my hardware so I can't do tests anymore [IMG ./images/smilies/icon_sad.gif] ######## POST p6256 | King Of Chaos | 2008-09-13 | t386-180.html Welcome to the party Snakey. [IMG ./images/smilies/icon_wink.gif] The circle is now complete... ######## POST p6258 | Nemesis | 2008-09-13 | t386-180.html Hi Snake, I was hoping you'd drop by at some point. Welcome to the forum. [IMG ./images/smilies/icon_smile.gif] [QUOTE] The CSM stuff is news to me, though. I haven't really looked at this since 1997, when I was talking to Tatsuyuki Satoh (original MAME core, and the one I think Stef based his on) - he has some japanese documents which suggested CSM mode was useless without the timer interrupts. Timer A would do key ON, and you'd have to key it OFF again yourself in an interrupt. We tried to figure it out but I eventually decided it'd be pretty useless on the Genesis. [/QUOTE] I get the feeling CSM is one of those functions that's probably implemented a little differently across a variety of chips, possibly even within the OPN line. Those documents he had may have been correct for another Yamaha chip. It would be nice to have a look at them, but I guess he never scanned them in. [QUOTE] The only thing (as far as I remember) that I still want to know is this: The YM2612 (apparently, and I don't remember where I found this) output DAC has one bit less than it would normally need. Something is done to remove one bit before it goes into the DAC. It appears to be some sort of compression/scaling which results in values close to silence being much louder. If you can figure that out I'd be very interested. [/QUOTE] I think I know the answer to that one. [IMG ./images/smilies/icon_smile.gif] The YM2612 has an embedded YM3016 DAC. I know that for sure. I also obtained a datasheet for the YM3016 DAC when I got the YM2608 documentation, but unfortunately, the YM3016 datasheet is also in Japanese, and I haven't found an English version. Fortunately, that doesn't matter one bit, as I've noticed the YM3015 is identical to the YM3016, with the exception that it takes a 12V input rather than the 5V input the YM3016 uses, and there's a YM3015 datasheet publically available in English. If you look at the datasheets, they contain the exact same information, with only the operating voltages differing. Here's the YM3016 datasheet in Japanese: http://nemesis.hacking-cult.org/MegaDri ... M3016J.pdf and here's the YM3015 datasheet in English: http://nemesis.hacking-cult.org/MegaDri ... YM3015.pdf Many other DAC's in the YM301X line like the YM3012 and YM3014 take the input to the DAC in a floating point format, with a 3-bit exponent and a 10-bit mantissa. The YM3015 and YM3016 are different in that they take their input as a 16-bit integer value in either binary or 2's compliment form. Internally, the DAC still converts that 16-bit input into a 3-bit exponent and 10-bit mantissa before using it however. Looking at the YM3015 datasheet, here's a block diagram of the internal operations the DAC performs: [IMG http://nemesis.hacking-cult.org/MegaDrive/Documentation/YM2612%20Notes/DAC.png] SD is the 16-bit serial data input, which comes from the accumulator in the case of the YM2612. The "Form Select" line switches between binary and 2's compliment mode. The "Form Select" and "ICL" lines are also tied to bits in the test register. This internal conversion process means that although the output from the accumulator is 16-bit (with 14-bits of meaningful data from the operator unit), internally, the DAC converts it back to a 10-bit mantissa and 3-bit exponent before generating the analog output, so there is the potential for some loss of precision within the DAC unit. I haven't had a good look yet at the effects of the internal floating point conversion in the DAC on the precision of the signal output. There's also still a question in my mind about what the YM2612 sets the lower 2 bits of the 16-bit accumulator output to. They might not simply be 0. I was going to look at the DAC last, once I've finished examining the other components of the YM2612. I've also noticed the extreme jump between low volume and silence though. I'm sure the answer to that behaviour lies in the DAC. ######## POST p6259 | HardWareMan | 2008-09-13 | t386-180.html [QUOTE] Nemesis wrote:I was going to look at the DAC last, once I've finished examining the other components of the YM2612. I've also noticed the extreme jump between low volume and silence though. I'm sure the answer to that behaviour lies in the DAC. [/QUOTE] I confirm that! A very noticeable ladder effect is exist. [IMG http://img261.imageshack.us/img261/3083/80397931gn5.th.png] [IMG http://img522.imageshack.us/img522/5593/16493221uy4.th.png] [IMG http://img131.imageshack.us/img131/2051/19696138zd5.th.png] ######## POST p6260 | Snake | 2008-09-13 | t386-180.html [QUOTE] Nemesis wrote:The YM2612 has an embedded YM3016 DAC. I know that for sure. [/QUOTE] Ok, from what I know, *most* chips that have an embedded DAC do indeed use that one. But in the YM2612? It's 9 bit instead of 10... Unfortunately I can't remember where I got this info. ######## POST p6267 | Nemesis | 2008-09-14 | t386-180.html Well, looking at the YM3016 datasheet, the 10-bit mantissa actually includes the sign bit. Traditionally when taking about floating point formats, the sign bit would be counted separately from the mantissa, so maybe that's where that came from. If the embedded DAC in the YM2612 did use a different floating point format, it would have to be an unknown variant. Every Yamaha YM301X DAC I've heard of uses the same floating point representation. I'll do tests on the DAC later on to see if I can confirm the mantissa size. I'm pretty confident in the assertion that the YM2612 has an embedded YM3016 though. ######## POST p6275 | AamirM | 2008-09-17 | t386-180.html Hi, @Snake I've been busy lately myself but I noticed that Kega has lower level in some places than all other emu and I was wondering why was that (if you remember of course). It noticeable in Spiderman - Spearation Anxiety intro music. Also the first stage sound of Sonic And Knuckles sounds a bit different from other emus. stay safe, AamirM ######## POST p6286 | Snake | 2008-09-19 | t386-180.html [QUOTE] AamirM wrote:I was wondering why was that (if you remember of course). [/QUOTE] Hmm, I have no idea, I'd have to see exactly what those games are doing, and even then that might only give me an *idea* why. When I get the chance I'll check it out and see if I can hear what you're reporting. Ok, quick postage of some interesting bits I missed earlier. [QUOTE] TmEE wrote:Kega won't play the currently played sample on the channel in next one when you change Left/Right reg so you can get nice and clean stereo sample playback [/QUOTE] Heh, that's interesting [IMG ./images/smilies/icon_smile.gif] I guess the hardware doesn't allow you to switch channels that fast. Admittedly something I never tested, because I didn't expect anybody to ever do that. What happens on the real hardware? Do you have a recording? [QUOTE] Eke wrote:at least , this was not correctly emulated in emulators (counter was reloaded every time the timer load value was changed) [/QUOTE] It's right in Kega. Or if it isn't, it should be, because I knew this [IMG ./images/smilies/icon_smile.gif] [QUOTE] TmEE wrote:One interesting thing : Hellfire, on MD2s (and other systems with Sega implementation of YM2612 in the ASIC) the music plays half as slow as it would on Yamaha discrete YM2612 chip [/QUOTE] Also interesting. I remember this game giving me trouble back in the very early days of KGen. One thing it does is spam the living hell out of the YM2612, repeatedly writing registers that haven't changed. I don't remember if it checks the status to see if the chip is busy between writes - but maybe it does, and those writes take a bit longer on the different chip? (or, maybe the newer chip forces a delay if you write to quick?) It's possible it wastes so much time with all this spamming that it misses an interrupt or timer interval. That'd explain why it runs at half speed. [QUOTE] Nemesis wrote:I know Steve Snake mentioned once that SSG-EG "doesn't always behave like it should" in the YM2612, but I haven't found any indication of that so far. [/QUOTE] Yes, I can't remember now what that was. But I was definitely doing some tests on it and getting rather odd and unexpected results back. At the time I couldn't make any sense of it, and I meant to look at it again later. I don't know if it's actually important, i.e. if any games try to do what I was doing. [QUOTE] Nemesis wrote:For the record, I haven't finished working on this chip. Not by a long shot. [/QUOTE] Heh, eight years on and off for me, and I'm not done yet either [IMG ./images/smilies/icon_smile.gif] [QUOTE] Nemesis wrote:Operators which directly modulate another operator can simply have their output fed directly into the input for the next operator and they never need to be stored. [/QUOTE] Aha. The document you found mentions there is only one operator. Incorrect. There are two, running in parallel. It simplifies the hardware design. This is the reason for the 'odd' operator numbering (1,3,2,4) in the registers. It also means that in most algorithms, an operator may need input from another one that's running parallel with it, and thus not ready yet. And so... it uses the previous output of that operator. This is what all the MEM stuff in Mame is all about, and it's correct. ######## POST p6287 | Nemesis | 2008-09-20 | t386-180.html [QUOTE] Aha. The document you found mentions there is only one operator. Incorrect. There are two, running in parallel. It simplifies the hardware design. This is the reason for the 'odd' operator numbering (1,3,2,4) in the registers. It also means that in most algorithms, an operator may need input from another one that's running parallel with it, and thus not ready yet. And so... it uses the previous output of that operator. This is what all the MEM stuff in Mame is all about, and it's correct. [/QUOTE] Yeah, once I had a closer look at the MAME implementation, I guessed that's what they were emulating. I haven't verified that on the hardware yet, but I expect I'll find it's correct once I test for it. I must say however, the self-feedback implementation still baffles me. MAME adds the last two samples together to build the self-feedback modulation value. This seems to be correct, but I can't figure out why it's correct, or rather, why the guys at Yamaha chose to implement it this way. Of course, there's no rule that says self-feedback has to be implemented in any particular way. Maybe they found this method "sounded better". It does produce a better saw-tooth when FB=5. I should probably stop wasting time on it and look at something else.