electro-smith / DaisySP

A Powerful DSP Library in C++
https://www.electro-smith.com/daisy
Other
848 stars 134 forks source link

Fm2 #82

Closed beserge closed 3 years ago

beserge commented 3 years ago

Still in need of testing, but at first glance it seems to work OK.

andrewikenberry commented 3 years ago

fm2 DaisySP FM Pair Osc

andrewikenberry commented 3 years ago

fm2 DaisySP FM Pair Osc

stephenhensley commented 3 years ago

Alright! sorry for the delay on this.

This definitely already sounds cool, but I think since this is already going to be a bit of a hard-coded module (one modulator/one carrier), with the expectation of most often, if not exclusively, being used with sine waves.

I believe the breakdown of the FM becomes incorrect in this context because the base-oscillator class does not handle negative frequencies (you avoided this by taking the absolute value of the frequency at all times), but I don't think that has the same effect since the frequency would be PI radians out of phase when frequency is negative, likely changing the expected side-bands.

We might as well do it with PM instead of actual FM with stuff as it is. Might simplify some of the interface a bit, too. (Only dual sines). Pretty sure our existing oscillator class will suit this fine, and if it can't we should fix it to support it, though I'm pretty sure the PhaseAdd function should be able to do what you need.

stephenhensley commented 3 years ago

Alright. Sounding gnarly.

Few things I noticed:

Regarding the ratio tracking: it seems that its not really possible to set/forget this as the SetRatio is what sets the modulator frequency, depending on the carrier frequency. So trying to just have a Fm2 with ratio set to 2x, and a fixed index doesn't have the expected output because the modulator just gets stuck on the initial frequency.

After a brief discussion the path forward (since this is a module with a pretty specific use-case) is to:

If we still want some semblance of independent control we could do a carrier ratio and modulator ratio, but

That'll simplify the overall module, and should fix any of the inconsistencies related to ratio.

Future improvements: