Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
62 lines (49 sloc) 1.98 KB
Script for creating and saving optophonic sounds for playback with Part of the Optophone Kit
and the Kits for Cultural History series by the MLab at the
University of Victoria (
Link to the Optophone Kit repository:
This script synthesizes tones of a particular frequency and
duration into a single .wav file.
import math
import wave
import struct
frate = 44100.00
amp = 8000.0
sine_list = []
datasize = 0
#Define function for combining sounds, synthesizing them into one chord
#freq = pitch, coef = amplitude, datalength = length, fname = name of wav file
def synthComplex(freq=[], coef=[], datalength=10000):
#returns a tone for each number in datasize and appends it to a list
for x in range(datalength):
samp = 0
for k in range(len(freq)):
samp = samp + coef[k] * math.sin(2*math.pi*freq[k]*(x/frate)) #the equation for creating a pure sine wav
Synthesize the sounds by filling in the synthComplex functions
below and "uncommenting them" (deleting the hashtag at the start
of the line).
Inside synthComplex(), replace the first [] with the desired
frequencies, the second [] with the amplitude, and the last no.
with the length in milliseconds.
For more on how the schema works, see
#synthComplex([784, 740, 659, 587, 523], [1, 1, 1, 1, 1], 2500)
#synthComplex([], [], 2500)
#Write the sounds into a single .wav file
def synthMelody():"name.wav","w") #replace name.wav with your own file name
nchannels = 1
sampwidth = 2
framerate = int(frate)
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)))