#!/usr/bin/python # https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ import struct import math import sys # frequency in wav file Freq = int (sys.argv[1]) # track length in seconds TrackLength = 5 # sample rate: 8000, 44100, etc. SampleRate = 44100 # number of channels: Mono = 1, Stereo = 2, etc. NumChannels = 1 # 8 bits = 8, 16 bits = 16, etc. BitsPerSample = 16 # PCM = 1 (i.e. Linear quantization) # Values other than 1 indicate some form of compression. AudioFormat = 1 # number of samples NumSamples = int (TrackLength * SampleRate) print 'freq: [', Freq, '], Hz', 'samples: [', NumSamples, '], length: [', TrackLength, '] seconds' f = open ('freq-' + str(Freq) + '.wav', 'w') ######################## # headers of wave file # Please note, that the data is stored in little-endian byte order. ######################## # Chunk ID # we are makeing RIFF file, so we have to mark the file as a riff file. # (4 bytes) f.write ('RIFF') # Size of Chunk ID # This is the size of the entire file in bytes. # 36 bytes of header + XXX bytes of content # (4 bytes) f.write (struct.pack ('