mitxela.com forum
Welcome. Please log in or register.

software FM Synthesis (wave discontinuity)
pub_123 Posted: 30 Aug 2021, 10:09 AM
Avatar


Member
Posts: 5
Joined: 30-August 21
I'm currently building my own software synthesizer and it's all well and good, except one small problem. When performing fm synthesis after some time it begins to crackle and pitch out slightly. After some experimentation i determined that this function is a culprit.


public double Oscillate_FM(double dTime, double sampleRate, double A, double B, double mFreq, double cFreq){
double modulating = Pack.w(cFreq);
double carrier = Pack.w(mFreq);
return A*Math.sin(carrier*dTime + B/modulating*(Math.sin(modulating*dTime-Math.PI/2))+1);
}


w() calculates angular velocity
and dTime is determined by a counter with something like this:


double step = 1.0/samplerate // sample rate is 44100 hz


Could someone please help me with this. Thanks in advance.

-------------
[top]
mit Posted: 30 Aug 2021, 10:21 AM
Avatar
yeah whatever

Admin
Posts: 566
Joined: 4-May 16
QUOTE (pub_123)
after some time it begins to crackle and pitch out slightly
When you have a problem like that it's almost always the limit of the floating point precision catching up with you. It's imperative to keep those doubles in the usable range by wrapping them when they get too big.

Something like

while (dTime > PI) {
dTime -= 2*PI;
}
should do it. In the case of FM synthesis, sometimes you have to wrap in both directions.

Last edit by mit at 30 Aug 2021, 10:22 AM

-------------
[top]
pub_123 Posted: 30 Aug 2021, 01:24 PM
Avatar


Member
Posts: 5
Joined: 30-August 21
Well i attempted to wrap them from both dirrection. However all it does is increase ammount of time before the crackling starts.

https://mega.nz/file/nuwwSI5K#oESTuPW3__IMJv5Mr4VgqRJqX6zk9Z_ESuxhbYdVhLQ

-------------
[top]
mit Posted: 1 Sep 2021, 09:13 AM
Avatar
yeah whatever

Admin
Posts: 566
Joined: 4-May 16
Where did you put the wrap code? It would need to go right after wherever dTime is increased. And any other angular variables will need to be wrapped also.

In my synths I usually have a separate phase variable for each oscillator instead. In the case of FM, the modulated oscillator's phase is increased by the output of the previous oscillator, and that's when it's possible for phase to go backwards and needs wrapping in both directions.

Technically that's "phase modulation" but virtually all digital FM synthesis is technically phase modulation.

-------------
[top]
pub_123 Posted: 5 Sep 2021, 07:05 PM
Avatar


Member
Posts: 5
Joined: 30-August 21
I looked into it some more and i found that i need to cap both of the phases separately because both of these run at different frequencies. It makes much more sense to store them as seperate variables for phase and cap them that way.

-------------
[top]

Sign in to post a reply.