Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_audio_generator3.py ZZZ an attempt to create beautiful samples of sound
- dir='C://py//audio//samples//'
- ww = 600
- hh = 600
- try:
- from Tkinter import *
- except:
- from tkinter import *
- import random
- import wave
- import math
- import struct
- import itertools
- sample_rate = 44100
- duration = 1 # seconds of audio
- SAMPLE_LEN = sample_rate * duration
- # -32767 to 32767
- for_amp = 32767
- def ttt():
- AMPS[amp,dur] += [int(t)]
- freq = 16
- AMPS = {}
- for amp in range(10,for_amp,10):
- print for_amp,'/',amp
- for dur in range(freq,freq+32,freq):
- t = 0
- AMPS[amp,dur] = []
- bit = (amp*1.0)/(dur*4)
- for _ in range(dur/4): # up
- ttt()
- t += bit
- for _ in range(dur/2): # down
- ttt()
- t -= bit
- for _ in range(dur/4): # up
- ttt()
- t += bit
- root = Tk()
- canvas = Canvas(root, width=ww, height=hh, bg='white')
- canvas.pack()
- def save_wave(packed_value):
- sss = str(tag)
- noise_output = wave.open(dir+sss+'.wav', 'w')
- noise_output.setparams((2, 2, sample_rate, 0, 'NONE', 'not compressed'))
- noise_output.writeframes('\n'.join(packed_value))
- noise_output.close()
- def draw_wave(values):
- canvas.delete(ALL)
- canvas.create_line(values, fill='red')
- canvas.update()
- amplitude = -0.1
- frequency = 20
- '''
- t = 100
- while 1: # 9282
- for p in itertools.permutations(AMPS, t):
- print t
- t += 1
- break
- '''
- tag = 0
- for p in itertools.permutations(AMPS, 3680): # note: keep permutations near lowest
- p = list(p)
- graph = []
- sound = []
- x = 0
- for bit in range(2,int(SAMPLE_LEN*2)+2):
- while 1:
- try:
- data = segment.pop()
- break
- except:
- amp,freq = p.pop()
- segment = AMPS[amp,freq][:]
- graph += [(x,data*0.12+hh/2)]
- sound += [struct.pack('h', data)]
- x += 1
- draw_wave(graph)
- save_wave(sound)
- tag += 1
Add Comment
Please, Sign In to add comment