-
-
Save MLLeKander/5f6c73e4a8b54f425c13 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#too short to license, so public domain | |
from wavegen import wavegen | |
from sys import stdout | |
import random | |
def tochar(sample): | |
return chr(int(sample * 127 + 127)) | |
a = wavegen(440) | |
ash = wavegen(466.16) | |
b = wavegen(493.88) | |
c = wavegen(523.25) | |
csh = wavegen(554.37) | |
d = wavegen(587.33) | |
dsh = wavegen(622.25) | |
e = wavegen(659.25) | |
f = wavegen(698.46) | |
fsh = wavegen(739.99) | |
g = wavegen(783.99) | |
gsh = wavegen(830.61) | |
lfo = wavegen(.5) | |
notes = [a,b,c,d,e,f,gsh,a.octup(),b.octup(),c.octup(),d.octup(),e.octup(),f.octup(),gsh.octup(),a.octup().octup()] | |
i = 44101 | |
slices = 1 | |
currnote = 1 | |
currndx = len(notes)/2 | |
while True: | |
if i > 44100 / slices: | |
currndx = min(max(0,currndx+random.randint(-3,3)),len(notes)-1) | |
current = notes[currndx] | |
if currnote == slices: | |
slices = random.choice([1,2,4,4,8,8,8]) | |
lfo = wavegen(slices * .5) | |
currnote = 0 | |
currnote = currnote + 1 | |
i = 0 | |
samp = current.get_sample(i) | |
samp = samp * lfo.get_sample(i) | |
i = i + 1 | |
stdout.write(tochar(samp)) |
This file contains hidden or 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
#too short to license, so public domain | |
from math import pi,sin | |
class wavegen(): | |
samprate=None | |
freq=None | |
def __init__(self,freq,samprate=44100): | |
self.samprate=float(samprate) | |
self.freq=float(freq) | |
def get_sample(self,time): | |
return sin(time*2*pi*self.freq/self.samprate) | |
def octup(self): | |
return wavegen(self.freq*2,self.samprate) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment