Is there any equation of converting PCM to FM?

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Is there any equation of converting PCM to FM?
by on (#87664)
Such as an equation that can take a PCE-style PCM samples to Genesis-like FM?

by on (#87665)
I believe there's a way to convert pulse waves to FM instead, but PCM?. No, I have no clue how. :(

by on (#87667)
PCM can have an arbitrary waveform. FM is only capable to make rather simple waveforms (comparable to arbitrary), in case with Genesis all made from sine waves. So no, you can't convert arbitrary sound to FM.

by on (#87669)
If you can make sawtooth waves in FM, you're already halfway there. Most PCE sample sets are somewhat limited. Check out the PCE demo "Ultimate HuC Sample Player" to get a graphical view of some of the most common sample definitions used in PCE games.

Also, check out YouTube videos about combining harmonics from sine waves to make square waves (not needed on Genesis 'cause you have a PSG there too), sawtooth waves, and others.

by on (#87671)
See the previous FM vs. PCM topic. In this post, TmEE claimed to be able to create an FM patch that has "1:1 waveforms to my bass guitar".

by on (#87678)
The YM2612 allows for CH 6 to be used as an 8-bit DAC (but the YM2612's timer foolishly can't be used on the Genesis so it'll require timed code).

by on (#87681)
tepples wrote:
See the previous FM vs. PCM topic. In this post, TmEE claimed to be able to create an FM patch that has "1:1 waveforms to my bass guitar".

Bass guitar has a quite simple waveform so its not so difficult to recreate it. Many natural instruments can be very accurately recreated. I would say one FM channel can recreate one string of some musical instrument. Since you only got like 6 or 8 channels (some chips got more) you cannot do very convincing sounds of instruments usually played in groups like orchestras. Good percussion is not so easy to make aswell, there's lot of sounds you can make but even more you cannot...

Sawtooth is very easy to make in FM, and you only need 2 operators to do it leaving 2 free for other sound such as square waves or beefing up the sawtooth to get fatter sound.

FM is excellent for bass, pads and brass and certain types of string instruments like acoustic guitars.

by on (#87686)
Wait, so I'm changing the question a bit. Is there a function to generate FM samples from square waves?

by on (#87789)
there are no FM "samples"

by on (#87790)
TmEE wrote:
there are no FM "samples"


So there's no sound "sample rate".

by on (#87803)
All the FM synthesizers made by Yamaha have a sample rate, because they are digital devices. (In the PC, the adlib soundcard produced sound at 49kHz). You could even argue there are two samples in every OPLx card: a logsin table and an exponent table. (see also this decap project). But the ways in which the device can use those two samples are very proscribed and should be thought of in the analog domain anyway.

PCM sound can be hacked out on an FM synth, and I remember Inertia Player for DOS supported it. But sound quality was awful, only better than Inertia's "use the PC speaker for sound" mode.

by on (#87804)
Pardon me, but I didn't get. Isn't the waveform (file) composed by samples, 4 bytes for 16-bit stereo output? I didn't get that "there are no FM samples", unless he misunderstood me. I'm not saying about "sound samples" used by an ad-lib board, for example, like guitar, sax or any other.

by on (#87805)
A sound sample is something that is sampled, recorded from an audio source. FM does not have samples, because it is not a recording, it is a set of parameters. So it is called an instrument, or a patch.

Playing PCM through an FM synth is nothing special, and it does not involve converting samples into FM parameters. It just abuses the synth's DAC one way or another.

by on (#87806)
Maybe it is worth considering re-reading your original question:
Zepper wrote:
Wait, so I'm changing the question a bit. Is there a function to generate FM samples from square waves?

One way I can reinterpret it is : "Is there a way to use square waves as operators (either carrier or modulator) ?"
Yes, the OPL3 can use square waves as operators.

Here I assume that Zeeper understand the inner working of FM-based sound, that is, sound is produced via phase modulation synthesis (while modulating the phase affect frequency and hence, it's also frequency modultion, the way these chips produce sound is trully by phase modulation).

If we didn't help with these answers, Zeeper, could you clarify your question?
Re: Is there any equation of converting PCM to FM?
by on (#204287)
It is possible to develop a program to produce an FM patch from a short PCM sequence. The result would be an approximation — a simpler waveform from a sound.

Any further detail would require, in theory, wave sampling — a driver (using the CPU) to render a sequence of FM waves to come closer to the original sound. But because you don't get a lot of precision for the parameters — particularly modulation and amplitude, it would probably require more than one mixed channel and the results would still be rough and vary.
Re:
by on (#204306)
ccovell wrote:
Also, check out YouTube videos about combining harmonics from sine waves to make square waves (not needed on Genesis 'cause you have a PSG there too)

It's needed if you want to reach the lower notes and/or have more than 3 channels and/or have a non-50% square wave.
Re: Is there any equation of converting PCM to FM?
by on (#204314)
There's no need to combine harmonics in brute force way, you only get 4 anyway then. One op modulating another with right freq ratios is able to give saw and square easily and can even simulate lowpass filters when modulation strength is adjusted, from sharp to dull to just a sine.

I have had lot of success by looking at spectrograms of sounds I want to create to see and then recreate the main harmonics via combining raw sines and modulation. Once tonality is correct you can add the dynamics via ADSR, and you can go step above by adjusting the parameters as time goes on rather than doing the regular static approach.
Re: Is there any equation of converting PCM to FM?
by on (#204327)
My problem in TFM Music Maker, a tracker for OPN FM chips, is how to go from the spectrogram to the best algorithm and modulation settings. Is it something that just comes with practice, or is there something that new FM sound designers are expected to read in order to make key insights?
Re: Is there any equation of converting PCM to FM?
by on (#204334)
All I know is that the fourier transform of a "classic" (sinusoid carrier and modulator) FM synthesis sound is a Bessel function of the first kind. Using a non-sinusoid carrier changes this in a more complex way; using a non-sinusoid modulator is "just" a convolution of the result.)

Eventually after playing around with it enough I eventually got some intuition for how to get the sound I wanted, but I never found it easy. At some point I just started using pre-built patch sets (debian package "alsa-tools" ; /usr/share/sounds/opl3 ) and adjusting them.
Re: Is there any equation of converting PCM to FM?
by on (#204343)
tepples wrote:
My problem in TFM Music Maker, a tracker for OPN FM chips, is how to go from the spectrogram to the best algorithm and modulation settings. Is it something that just comes with practice, or is there something that new FM sound designers are expected to read in order to make key insights?

I don't know of any textbook that teaches how to make good FM instrument patches. Finding a well balanced tone is usually very sensitive to small changes, a brief peak of serenity in a sea of BLAARRP. Hard to generalize.

Find patches that you think are good, and modify them. Turn off each operator in turn and see how it contributes. Turn the modulator strength up and down for each to see what they are doing.

In 2-op you are pretty limited, but in 4-op the extra operators tend to contribute a lot to the envelope/dynamic changes of tone, e.g. you can have an operator that's mainly for the attack, one for the main body of the tone, another for a slow change across the decay, etc. Beyond the first 2, more operators will usually be used in an approximately "additive" way even though it's technically more complicated than that.

As far as trying to synthesize the tones of other instruments, I don't think FM is well suited to this endeavour. I think FM can produce a good substitute for any given musical sound, but that's very different than a good imitation of that sound. Trying to imitate might give you some ideas to experiment with, and you could find some good sounds in the process of trying, but you'll almost never be able to duplicate anything closely with it.

If you can, use some tools to extract patches from FM music with good patches (e.g. anything by Ryu Umemoto) and take a good look at them!
Re: Is there any equation of converting PCM to FM?
by on (#204365)
rainwarrior wrote:
I don't know of any textbook that teaches how to make good FM instrument patches. Finding a well balanced tone is usually very sensitive to small changes, a brief peak of serenity in a sea of BLAARRP. Hard to generalize.

That's why you start making the right tone without dynamics, ADSR set to max attack and infinite sustain. Then dynamics part is out the equation and you can entirely focus on the serenity part or the BLAARRP and anything inbetween. If modulation grows too high you're gonna get those harsh sounds, so you scale back modulation factor accordingly so that such state isn't reached. TL parameter is the peak level the operator can reach.

If you see regularly placed harmonics then you use one op modulating the other to create them, if you see regularly placed harmonics in the sequence you add one more op to the mix for that, if things are offset and not following exact same sequence but are still in a sequence you need another frequency ratio for them. If there's some random non repeating harmonics you're very much forced to waste an operator on those, non modulated ops that is.
You'll want to make the computer record its output and see a spectrogram taken realtime how the modulation changes harmonic structure. The rules between TL, MUL and other parameters are very straightforward, you just got to ignore that dynamics exist first.

Once tonality is set you can then work on dynamics. Start with output ops, and then touch the modulators. Changing ADSR parameters of the modulators will affect tonal qualities, the lower the modulation factor gets (operator level) the more smoother (sine like) the sound gets, which mimics how the higher energy harmonics fade away first when a note is decaying. Parameters like Key Scale will speed up the envelope has notes go higher, something that real instruments experience also, high keys on piano will never have a long sustain no matter how hard you hit them. There's also an LFO and detune parameters which can be used to create beat frequencies or other things to make a sound more dynamic, unfortunately speed of LFO is global.
And you'll want to keep your eyes on a spectrogram.

I do think using FM to recreate classic instruments is wasting away the potential, you can do so much more, things that don't exist yet. Having said that, one 4op FM channel can do very much 1:1 or nearly that approximation of *a string* of any classic instrument, but you only have 6 or 8 channels on the popular chips so things like pianos are gonna be very ineffective because their characteristic sound comes from the fact that most notes have 2 or 3 strings used, and their tuning isn't exact, using half or 1/3rd of the chip for one note is not great for making a full composition however... You can do a very nice acoustic guitar though, but a lot of effort will have to go into adding the human playback imperfections such as finger sliding and fret noises.