Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scipy.io.wavfile
- import numpy as np
- import random
- sr = 44100
- duration = 10 # secs
- y = np.zeros((sr*duration), dtype='float')
- func_names = ('saw', 'square', 'tri', 'sin')
- funcs = [
- lambda i, l: i/(l-1) * 2 - 1, # saw
- lambda i, l: round(i / (l-1)) * 2 - 1, # square
- lambda i, l: min(i/l,-(i/l-0.5))*4 if i/l < 0.5 else max(-(i/l-0.5), i/l-1)*4, # tri
- lambda i, l: np.sin(np.pi*2 * i/l) # sin
- ]
- for func in range(len(func_names)):
- print('processing', func_names[func])
- try:
- index = 0
- while True:
- length = random.randint(10, 50)
- mul = random.uniform(0.2, 1)
- for i in range(length):
- y[index] = funcs[func](i, length) * mul
- if index % sr == 0:
- print(index/sr, 'sec')
- index += 1
- except:
- pass
- scipy.io.wavfile.write(func_names[func] + '_noise.wav', sr, y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement