-
-
Save ludwig/4277feb6af02e680e9ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wave, struct, sys | |
from math import pow, sin | |
samples = 100000 | |
terms = 50 | |
normalizer = 32768/1.5 | |
weier = wave.open('weierstrass.wav', 'w') | |
weier.setparams((1, 2, 44100, 0, 'NONE', 'not compressed')) | |
print "Progress (%):", | |
for i in range(samples): | |
x = float(1000*i)/samples | |
value = normalizer * reduce(lambda sum,n:sum+pow(2,-n)*sin(pow(2,n)*x), range(terms), 0) | |
if i%5000==0: print int(100*float(i)/samples),; sys.stdout.flush() | |
packed_value = struct.pack('h', int(value)) | |
weier.writeframes(packed_value) | |
weier.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment