1. Context
I'm using GLSL to plot the amplitude of a waveform at a given frequency like this:
Displaying simple waveforms like the ones above is a trivial task, it's just a matter of using the right equations (GLSL excerpt code available here). What I'm trying to do now is to display the results of a frequency modulation between two waveforms.
2. Research
After some research I've found two possible ways to accomplish this:
Using a dsp-like approach, as far as I know using phase accumulators (see first answer here) in combination with lookup tables is the suggested approach when working with signal processing. As a GLSL beginner I understood that this is not possibile with GLSL shaders because they can't store and increment variables across multiple GPU cycles.
Using a pure mathematical approach, this involves equations like Chowning's simple fm formula. FM formula http://img577.imageshack.us/img577/4820/fmformula.png
That formula works great in some situations (cosine wave modulating another cosine or cosine modulating a sawtooth) but I wasn't able to find a general equation that would work in every case (when a sawtooth wave modulates a cosine I expect the carrier frequency to be modulated by sawtooth amplitude, but all I get is the carrier wave apparently unmodulated).
3. Questions
- What would be the best approach to solve this problem?
- Is a dsp-like approach possible with GLSL?
- If not, is there any general FM equation flexible enough to do all the work?
Considering my lack of skills in all the disciplines involved here (audio dsp, computer sciences, gpu programming, maths) I won't be surprised if I'm missing something really simple here. Please be patient.