# OPLL frequency calculation & pitch bend - BLARGH!?

Página 1/2
| 2

Oh, Yamaha, why must you be so impenetrable? I've been hacking up some sound-test software and poring over tech documents with an eye towards writing a music engine that supports the OPLL chip found in MSX-Music cartridges and MSX-2+ machines, and chief among the things that baffle me about the chip (just after why maximum volume is 0) is the crazy moon logic that drives the frequency-control registers.

It took me the better part of the afternoon to even wrap my head around how it works, but it's my understanding that, given the 9-bit "F-number" and the 3-bit "block," the formula is:

`Frequency = Fnum * (2 ^ Block-1) * 50000 / 2^18`

where 50000 is the master frequency for the chip. The crazy thing is, and this took me hours of wracking my brain and actual direct confirmation on my own unit to understand, even though the block value would logically serve as an octave-selector, the ranges overlap! Block value 1 gives the various F-numbers output frequencies from about 0.19Hz to 97Hz, block 2 covers from 0.38Hz to 194.93Hz, and so on and so forth.

This means that, even though there's exactly as much register space devoted to frequency control as on the PSG or SCC, the huge majority of the range is completely redundant. I'm wondering if I shouldn't just hard-code the block value to 7, since that gives a range from ~12Hz to ~6KHz, more than covering the full piano keyboard. I'm just not 100% sure on this, since it means that a range of frequencies with over 4000 values on the PSG/SCC is going to be squashed to under 512 on the OPLL!

If I wanted to make use of all the bits, it'd be a simple thing to work out a pre-calculated note table with the optimum block/fnum combination for each note (and, in fact, I already did.) But the question then is, how do I handle pitch bends? They're not too difficult to figure out in a linear frequency range, but when you bring the block numbers into it, it's madness.

Does anyone have any thoughts on this or experience with coding for Yamaha FM chips? I keep thinking that there has to be something I missed, but I can't seem to find anything that would make this make any kind of sense at all...

Login sesión o register para postear comentarios

I`m a little bit familiar with the YM2612. It uses the same scheme for specifying frequencies except with 11 bits for f-number. Looking at a couple of register dumps, I can tell you that the way Sega did it was by always using an f-number in the 600-1200 range, and setting the octave as needed to keep it there.

Yai. I suppose that might work, but it'd make pitch bends hell...

I use this expression to calculate the frequency of values in OPLL registers in an openMSX script:

```
"MSX-MUSIC" {
set regs "\"\${soundchip} regs\""
set basefreq [expr 3579545.454545 / 72.0]
set factor [expr \$basefreq / (1 << 18)]
if {\$channel >= 9} {
#drums
incr channel -3
}
return "expr { (\[debug read \$regs [expr \$channel + 0x10]\] + 256 * ((\[debug read \$regs [expr \$channel + 0x20]\]) & 1)) * \$factor * (1 << (((\[debug read \$regs [expr \$channel + 0x20]\]) & 15) >> 1)) }"
```

Does that help, or is it gibberish?

I understand that, it's just the whole "trying to figure out how to build a music engine for this" thing that baffles me.

Maybe you should try to check out how MoonBlaster does this:
http://www.msx.org/forumtopic9883p23.html

Please don't use the value's that you will find in the yamaha datasheets as they are pre calculated for a frequency of 3.6 Mhz not the msx frequency of 3.54 Mhz !
You don't want to know what i all came across during the MIDI-PAC development, sjjeesss some really won't take the effort to read the datasheet

But for your question, use this formula to calculate the correct frequency for a specific keyboard note (Note 69 will give you a A on octave 4):

fmus=440*(2^(((<note>-69)/12)))

Then use this formula to calculate the F-Num for a specific octave (default 4):
Fnum=(<frequency>*5,27284)/(2^(<Octave>-1))

Just calculate the desired frequency's for one octave as you use the mul bit's for the octave !

But if you want to calculate your pitch bending destination, use this magic number: 1,059463
It's the note to note multiplier value, try it !

Good luck,
Tjeerd.

Yeah, I figured that would be the case, so I put in an option in my table-builder to change the master clock frequency.

Perhaps MSD can shed some more light on the subject? (he's been doin' calcs on OPLL frq a while ago..) where ye at Marcel!?

WORP3: um, MSX clock runs at 3579545.454545 Hz... not 3.54MHz... or did I misunderstand you?

@Manuel, you are correct that 3.54 was a typo
Formula is still right as the pre-calculated did originate from a 3.57.. MHz base.

Página 1/2
| 2