Generate Wav Files
eharetea

Generate audio files with Python for programming music!

Generate wav files with Python!

Date Created:Monday June 23rd, 2008 12:54 PM
Date Modified:Sunday August 03rd, 2008 01:18 PM


# File: genfile.py

import writewav
writewav.createWavlambda xwritewav.sin(x), "file.wav"0.5)




# File: writewav.py

import wave
from math import pisinfloorcos
def quantize(f,  time ,channels 2framerate 44100amplitude 127):
    dx 1.0 float(framerate)
    res ""
    0
    while time:
        res res chr(int(f(x) * amplitude amplitude)) * channels
        x += dx
    return res
def createWav(ffilenametime ,channels 2framerate 44100amplitude 127):
    out wave.open(filename"w")
    out.setnchannels(channels)
    out.setframerate(framerate)
    out.setsampwidth(1)
    out.setcomptype("NONE""NONE")
    out.writeframes(quantize(ftimechannelsframerateamplitude))
    out.close()
def dan1(x):
    % (pi)
    if pi or 3*pi/4:
        return sin(m)
    else:
        return -pi 2
def square(x):
    floor(pi)
    floor(10 pi)
    if sin(cos(x*x*x)) > 0:
        return d/m
    else:
        return -d/m
def waver(xAwp):
    return A*sin(2*pi*(wt-p))




Downloads:
Download: genfile.py 104 B
Download: writewav.py 916 B

Please login or Click Here to register for downloads
Creative Commons License
Generate Wav Files by Dan Lynch
is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Based on a work at www.3daet.com
Permissions beyond the scope of this license may be available at http://www.3daet.com