import fart import nuclear import wave import pickle from array import array import struct smoothie = 77 #nuc = [ [pickle.load(open("plutonium")),1,[100,100]], #nuc = [ [fart.Zero(),0,[100,100]], nuc = [ [fart.One(),1,[33,33]], # [fart.One(),0,[123,123]], # [fart.Two(),0,[123,123]], # [fart.Three(),0,[200,200]], # [fart.Four(),0,[200,200]], # [fart.Five(),0,[300,300]], # [fart.Six(),0,[300,300]], # [fart.Seven(),2,[500,500]], # [fart.Eight(),0,[500,500]], # [fart.Nine(),0,[123,123]], #nuc = [ [nuclear.Zero(),0,[500,500]], # [nuclear.Zero(),0,[300,300]], # [nuclear.One(),0,[123,123]], [nuclear.Two(),0,[222,222]], # [nuclear.Three(),0,[200,200]], [nuclear.Four(),0,[500,500]], [nuclear.Five(),3,[500,500]], [nuclear.Six(),0,[500,500]], [nuclear.Seven(),2,[100,100]], # [nuclear.Seven(),0,[500,500]]] [nuclear.Eight(),0,[500,500]], [nuclear.Nine(),0,[500,500]]] n_len = len(nuc) # [nuc,switch,[smoothie,smaller the bigger]] # 0=free 1=fixed 2=can only - (getbigger) 3= can only + (get smaller) def l2h(thang): h_thang = array('h') l_thang = len(thang) for gas in range(l_thang): h_thang.append(thang[gas]) return h_thang src = wave.open("src.wav", "r") tmp = src.readframes(src.getnframes()) bass = list(struct.unpack('%dh' % (len(tmp) / src.getsampwidth()), tmp)) src.close() tmp = [] b_len = len(bass)/2 print b_len for i in range(1,b_len): bass[2*i-2] = bass[2*i] - bass[2*i-2] bass[2*i-1] = bass[2*i+1] - bass[2*i-1] mx = abs(max(bass)) mn = abs(min(bass)) if mn > mx: mx = mn print "bassv max",mx del bass[-2:] b_len = b_len-1 fmx = float(mx) for i in range(b_len): bass[2*i] = bass[2*i]/fmx bass[2*i+1] = bass[2*i+1]/fmx filter = 35753 stereo = [0,0] a_stereo = [32767,32767] ml = mx for f in range(b_len): tmll = ml tmlr = ml tl = a_stereo[0]+int(ml*bass[2*f]) tr = a_stereo[1]+int(ml*bass[2*f+1]) if tl > 65534 or tl < 0: if a_stereo[0] > 32767: tmll = 65534-a_stereo[0] else: tmll = a_stereo[0] w = a_stereo[0]%n_len nuc[w][0].reincarnate(a_stereo[1]) if nuc[w][1] < 10: nuc[w][1] = nuc[w][1] + 10 else: nuc[w][1] = 10 + a_stereo[1]%4 if tr > 65534 or tr < 0: if a_stereo[1] > 32767: tmlr = 65534-a_stereo[1] else: tmll = a_stereo[1] w = a_stereo[1]%n_len nuc[w][0].reincarnate(a_stereo[0]) if nuc[w][1] < 10: nuc[w][1] = nuc[w][1] + 10 else: nuc[w][1] = 10 + a_stereo[0]%4 if tmlr < tmll: tmll = tmlr if tmll < ml: ml = tmll a_stereo[0] = a_stereo[0]+int(ml*bass[2*f]) a_stereo[1] = a_stereo[1]+int(ml*bass[2*f+1]) if a_stereo[0] > 66534 or a_stereo[0] < 0 or a_stereo[1] > 66534 or a_stereo[1] < 0: print "!!!!!!!!!!!!!!!!!! out of range =", a_stereo[0], a_stereo[1] for n in nuc: if n[1] > 9: continue song = n[0].sing() for s in range(2): if song > 0: v = (65534-a_stereo[s])/float(n[2][s]) else: v = a_stereo[s]/float(n[2][s]) a_stereo[s] = a_stereo[s]+int(v*song) w = (s*n[2][s]+a_stereo[s])%n_len if n[2][s] > smoothie and n[2][s] != n[2][(s+1)%2]+1 and nuc[w][2][s] != nuc[w][2][(s+1)%2]-1: if n[1] != 1 and n[1] != 3 and nuc[w][1] != 1 and nuc[w][1] != 2: n[2][s] = n[2][s]-1 nuc[w][2][s] = nuc[w][2][s]+1 if n[2][s]-1==smoothie and nuc[w][1] < 10: n[1] = 0 nuc[w][1] = 12 stereo.append(a_stereo[0]-32767) stereo.append(a_stereo[1]-32767) h = (f+stereo[-1]+stereo[-2])%filter if h == 5434: guy = a_stereo[0]%n_len gal = a_stereo[1]%n_len print guy,"fuck",gal nuc[guy][0].fuck(nuc[gal][0]) if nuc[guy][1] < 10: nuc[guy][1] = nuc[guy][1] + 10 else: nuc[guy][1] = nuc[guy][1] - 10 if nuc[gal][1] < 10: nuc[gal][1] = nuc[gal][1] + 10 else: nuc[gal][1] = nuc[gal][1] - 10 elif h == 333: w = a_stereo[0]%n_len nuc[w][0].reincarnate(a_stereo[1]) nuc[w][1] = a_stereo[1]%4 if f % 44100 == 0: print f/44100, "/", b_len/44100 print "[", a_stereo[0], a_stereo[1], "]" for n in nuc: print n[2], print if ml < mx: ml = ml+1 for f in range(44100): stereo[-2*f-1] = int(stereo[-2*f-1]*(f/44100.0)) stereo[-2*f-2] = int(stereo[-2*f-2]*(f/44100.0)) track_thang = l2h(stereo) a_thang = wave.open("radiation.wav", "w") a_thang.setnchannels(2) a_thang.setsampwidth(2) a_thang.setframerate(44100) a_thang.writeframes(track_thang.tostring()) a_thang.close() #print "dumping plutonium" #pickle.dump(nuc[0],open("plutonium","w")) print "done"