2013-07-15 15:34:50 +02:00
|
|
|
import math, random, itertools, pyaudio
|
|
|
|
|
|
|
|
opzioni = {
|
2013-07-13 23:47:37 +02:00
|
|
|
"format": pyaudio.paFloat32,
|
|
|
|
"channels": 2,
|
|
|
|
"rate": 96000,
|
|
|
|
"input": True,
|
|
|
|
"frames_per_buffer": 1024
|
2013-07-15 15:34:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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 caso(inizio, fine, stop):
|
2013-01-05 01:20:04 +01:00
|
|
|
audio = pyaudio.PyAudio()
|
2013-07-13 23:47:37 +02:00
|
|
|
input = audio.open(**opzioni)
|
|
|
|
dati = input.read(opzioni["rate"]//opzioni["frames_per_buffer"] * stop//2)
|
2013-01-05 01:20:04 +01:00
|
|
|
input.close()
|
|
|
|
audio.terminate()
|
|
|
|
dati = [i for i in dati if i != 0]
|
2013-07-13 23:47:37 +02:00
|
|
|
dati = [i for i in dati if i in range(inizio,fine)]
|
|
|
|
random.shuffle(dati)
|
2013-01-05 01:20:04 +01:00
|
|
|
for i in range(stop):
|
2013-07-13 23:47:37 +02:00
|
|
|
yield dati[i]
|
2013-07-15 15:34:50 +02:00
|
|
|
|
|
|
|
def onetimepad(l):
|
|
|
|
return tuple(generatore.caso(0,2*16,l))
|