2013-01-05 01:20:04 +01:00
|
|
|
import math,random,itertools,pyaudio
class primi:
def primo(n):
for i in range(3, int(math.sqrt(n)) + 1,2):
if n % i == 0: return False
return True
def prossimo(n):
if n % 2 == 0: n += 1
while True:
n += 2
if primi.primo(n): yield n
def lista(p, n):
return tuple([p for p in itertools.islice(primi.prossimo(p), n)])
class generatore:
def rumore(l):
audio = pyaudio.PyAudio()
output = audio.open(format = pyaudio.paInt8, channels = 1, output=True, rate = 50000)
for i in range(int(l*100/3)):
output.write(chr(int(random.random() * 25 + 1)))
output.close()
audio.terminate()
def leggirumore(inizio, fine, stop):
|
|
|
|
audio = pyaudio.PyAudio()
|
|
|
|
input = audio.open(format = pyaudio.paInt16, channels = 2, rate = 44100, input = True, frames_per_buffer = 1024)
|
|
|
|
dati = input.read(int(44100 / 1024 * stop * 10))
|
|
|
|
input.close()
|
|
|
|
audio.terminate()
|
|
|
|
dati = [i for i in dati if i != 0]
|
|
|
|
numeri = [(i + random.randint(inizio,fine)) % (fine + abs(inizio)) + inizio for i in dati]
|
|
|
|
for i in range(stop):
|
|
|
|
yield numeri[i]
|
|
|
|
def onetimepad(l):
return tuple(generatore.leggirumore(0,2*16,l))
|