Synthesizing tones to generate music
The previous section described how to generate a simple monotone, but it's not all that meaningful. It was just a single frequency through the signal. Let's use that principle to synthesize music by stitching different tones together. We will be using standard tones like A, C, G, F, and so on to generate music. In order to see the frequency mapping for these standard tones, you can check out this link: http://www.phy.mtu.edu/~suits/notefreqs.html . Let's use this information to generate a musical signal.
Create a new Python file and import the following packages:
import json import numpy as np import matplotlib.pyplot as plt from scipy.io.wavfile import write
Define a function to generate a tone based on the input parameters:
# Synthesize the tone based on the input parameters def tone_synthesizer(freq, duration, amplitude=1.0, sampling_freq=44100): # Construct the time axis time_axis = np.linspace(0, duration, duration...