FM synthesis

Wave form generation for audio synthesis. We'll focus on additive FM synthesis first.

Sine wave

$$ A \sin ( 2 \pi f t + \varphi ) $$

Term denotes
\( A \) amplitude
\( \sin \)
\( 2 \pi \)
\( f \) frequency(hz)
\( t \) time
\( \varphi \) phase

Sinewave playback example on Github

Only works with PulseAudio PulseAudio pacat

import subprocess
import numpy as np
import math

f = 3 # frequency in hz (incorrect, need to modify code for accurate timing.)
a = 0.1 # amplitude
p = 0 # phase
t = 0 # time step

buffersize = 1024 * 4 # size of sound buffer
current_time = math.pi*2 / buffersize

latency = buffersize * 8 # latency in number of bytes
pacatbuffer = bytearray()

# output sound using Pulseaudio using Pacat and stdin
output_sound = subprocess.Popen(('pacat', '--latency', str(latency),  '--format', 'float32ne', 
                                 '--channels', '1'), stdin=subprocess.PIPE)

while True:
    for i in range(buffersize):
        t = t+current_time
        sinewave = math.sin((math.pi*2)*(f*t)+p)*a
        sample = np.float32(sinewave) # Python float to Numpy float32
        sample.tobytes() # convert sound sample to bytes
        pacatbuffer += bytearray(sample) # add bytes to buffer
    output_sound.stdin.write(pacatbuffer) #write buffer to stdin
    pacatbuffer = bytearray() # empty buffer

Episode 4: Sines And Cosines Part I - Project MATHEMATICS!

Buffering, threading and timing

Envelope

Mapping keyboard key presses to octaves

Octave

https://en.wikipedia.org/wiki/Decibel

FREQUENCY MODULATION

Wave table synthesis

Serial port

Filters

High-pass

Band-pass

Low-pass

Moving average

Brown noise