I want to know how I could implement a Low Frequency Oscilator on a simple synth I've coded in C. First in order to understand how to make this happen I would like just to modulate a sine wave by a sine LFO, and then I would adapt this to other oscilators and so on.
I tried adapting to adapt this LFO formula I found on my sine oscilator:
dLFOAmplitude * dHertz * (sin(w(dLFOHertz) * dTime
But I didn't found a correct way to do this. Here's my sinewave generator function:
static void build_sine_table(int16_t *data, int wave_length) {
double phase_increment = (2.0f * pi) / (double)wave_length;
double current_phase = 0;
for(int i = 0; i < wave_length; i++) {
int sample = (int) (sin(current_phase) * INT16_MAX);
data[i] = (int16_t)sample;
current_phase += phase_increment;
}
}
EDIT: I tried again to multiply my lfo signal with my oscilator. Each time I'm doing it I got no sound released. Same by divinding. When I sum up the two signal I got sound but no modulation. Here's what I tried in order to follow advices from the comment:
static void build_sine_table(int16_t *data, int wave_length) {
double phase_increment = (2.0f * pi) / (double)wave_length;
int lfo_phase = (2.0f * pi) / 20 / 44100;
double lfo = 0;
double current_phase = 0;
for(int i = 0; i < wave_length; i++) {
int sample = (int) (0.5 * sin(current_phase) * INT16_MAX + 0.5 * sin(lfo) * INT16_MAX);
data[i] = (int16_t)sample;
current_phase += phase_increment;
lfo += lfo_phase;
}
}
I tried many other thing, and the "best result" I got was a wave looking like this :
I've spent a lot of time trying to figure out a to make it work, and the more I looking into it, the less I'm confident to be able of coding it.