aboutsummaryrefslogtreecommitdiffstats
path: root/maximilian_examples/5.FM1.cpp
blob: 14f6593478436173e15563118c926d19459691d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// One way of thinking about FM synthesis is to see it as vibrato.
// You make a pitch, then vary it up and down at some rate.
// You can change the speed of the pitch variation (modulation frequency), and also the amount of variation (modulation index).
// In FM, usually only one of the waveforms - the carrier that provides the initial pitch - is sent to the output.
// The frequency of the the carrier wave is continually adjusted at a rate equal to the frequency of the second wave (the modulator).
// So at any given point in time, the frequency of the carrier can increase by an amount equal to the current amp of the modulator.
// This has some interesting effects.

#include "maximilian.h"

maxiOsc mySine,myOtherSine;//Two oscillators


void setup() {//some inits
    //nothing to go here this time
}

void play(double *output) {
    
    // In this example, the 'myOtherSine.sinewave' is at an amplitude of 1, it's original amplitude.
    // This is pretty simple and not too useful.
    //output[0]=mySine.sinewave(440*myOtherSine.sinewave(1));
    
    // Perhaps you should comment out the above line and uncomment the below one instead
    // It shows how the frequency of the carrier is altered by ADDING a second waveform to its frequency value.
    // The carrier frequency is 440, and the modulation frequency is 1.
    // It also shows how the modulation index works. In this case the modulation index is 100
    // Try adjusting the modolation index. Also, try altering the modulation frequency.
    output[0]=mySine.sinewave(440+(myOtherSine.sinewave(1)*100));
    
}

// In complex FM systems you can have lots of modulators stacked together in interesting ways, and theoretically this can make any sound.
// John Chowning is the guy you probably want to talk to about that.