I don’t know if this will help, but here is some code synthesizing a complex sound based on frequencies and amplitudes:
import math
import wave
import struct
def synthComplex(freq=[440],coef=[1], datasize=10000, fname="test.wav"):
frate = 44100.00
amp=8000.0
sine_list=[]
for x in range(datasize):
samp = 0
for k in range(len(freq)):
samp = samp + coef[k] * math.sin(2*math.pi*freq[k]*(x/frate))
sine_list.append(samp)
wav_file=wave.open(fname,"w")
nchannels = 1
sampwidth = 2
framerate = int(frate)
nframes=datasize
comptype= "NONE"
compname= "not compressed"
wav_file.setparams((nchannels, sampwidth, framerate, nframes, comptype, compname))
for s in sine_list:
wav_file.writeframes(struct.pack('h', int(s*amp/2)))
wav_file.close()
synthComplex([440,880,1200], [0.4,0.3,0.1], 30000, "tone.wav")
This is the code I use to create notes and chords in python. You have a list of frequencies for the first parameter, a list of amplitudes (the same size as the first), the number of samples and the file name. It will generate a wav file with the specified combination.
source
share