def geometric_delay(sig, dur, copies, pamp=0.5): """ Delay effect by copying data (with Streamix). Parameters ---------- sig: Input signal (an iterable). dur: Duration, in samples. copies: Number of times the signal will be replayed in the given duration. The signal is played copies + 1 times. pamp: The relative remaining amplitude fraction for the next played Stream, based on the idea that total amplitude should sum to 1. Defaults to 0.5. """ out = Streamix() sig = thub(sig, copies + 1) out.add(0, sig * pamp) # Original remain = 1 - pamp for unused in xrange(copies): gain = remain * pamp out.add(dur / copies, sig * gain) remain -= gain return out
def __init__(self, lista_filtros, ncanais=1,rate=44100): """ Inicia o Player. lista_filtros: lista de filtros aplicados, se for uma tupla, se trata de uma preset. pos: Posição Inicial no preset """ self.filtros = lista_filtros if self.filtros is not None: self.filter = CascadeFilter(self.filtros) else: self.filter = CascadeFilter() self.ncanais = ncanais self.release = 0.05*filters.s self.rate = rate self.player = AudioIO() self.streamix = Streamix(True) self.input = ChangeableStream(self.player.record(nchannels=ncanais,rate=self.rate)) self.input.last = 0. self.stream = ChangeableStream(self.filter(self.input)) self.stream.last = 0. self.player.play(self.streamix, rate=self.rate) self.streamix.add(0,self.stream)
def geometric_delay(sig, dur, copies, pamp=.5): """ Delay effect by copying data (with Streamix). Parameters ---------- sig: Input signal (an iterable). dur: Duration, in samples. copies: Number of times the signal will be replayed in the given duration. The signal is played copies + 1 times. pamp: The relative remaining amplitude fraction for the next played Stream, based on the idea that total amplitude should sum to 1. Defaults to 0.5. """ out = Streamix() sig = thub(sig, copies + 1) out.add(0, sig * pamp) # Original remain = 1 - pamp for unused in xrange(copies): gain = remain * pamp out.add(dur / copies, sig * gain) remain -= gain return out
# Basic initialization rate = 44100 s, Hz = sHz(rate) kHz = 1e3 * Hz # Some parameters table_len = 8192 min_freq = 20 * Hz max_freq = 10 * kHz duration = 60 * s # "Track-by-track" partials configuration noctaves = abs(log2(max_freq/min_freq)) octave_duration = duration / noctaves smix = Streamix() data = [] # Global: keeps one parcial "track" for all uses (but the first) # Inits "data" def partial(): smix.add(octave_duration, partial_cached()) # Next track/partial event # Octave-based frequency values sequence scale = 2 ** line(duration, finish=True) partial_freq = (scale - 1) * (max_freq - min_freq) + min_freq # Envelope to "hide" the partial beginning/ending env = [k ** 2 for k in window.hamming(int(round(duration)))] # The generator, properly: for el in env * sinusoid(partial_freq) / noctaves: data.append(el) yield el
# Basic initialization rate = 44100 s, Hz = sHz(rate) kHz = 1e3 * Hz # Some parameters table_len = 8192 min_freq = 20 * Hz max_freq = 10 * kHz duration = 60 * s # "Track-by-track" partials configuration noctaves = abs(log2(max_freq / min_freq)) octave_duration = duration / noctaves smix = Streamix() data = [] # Global: keeps one parcial "track" for all uses (but the first) # Inits "data" def partial(): smix.add(octave_duration, partial_cached()) # Next track/partial event # Octave-based frequency values sequence scale = 2**line(duration, finish=True) partial_freq = (scale - 1) * (max_freq - min_freq) + min_freq # Envelope to "hide" the partial beginning/ending env = [k**2 for k in window.hamming(int(round(duration)))] # The generator, properly: for el in env * sinusoid(partial_freq) / noctaves: data.append(el) yield el
octave. """ tk = tkinter.Tk() tk.title("Keyboard Example") lbl = tkinter.Label(tk, text=txt, font=("Mono", 30)) lbl.pack(expand=True, fill=tkinter.BOTH) rate = 44100 s, Hz = sHz(rate) ms = 1e-3 * s attack = 30 * ms release = 50 * ms level = .2 # Highest amplitude value per note smix = Streamix(True) cstreams = {} class ChangeableStream(Stream): """ Stream that can be changed after being used if the limit/append methods are called while playing. It uses an iterator that keep taking samples from the Stream instead of an iterator to the internal data itself. """ def __iter__(self): while True: yield next(self._data) has_after = None
class Player: """ Classe Player, gerencia um player de Audio. É destruído no STOP. Ao pausar apenas para de exibir novos valores """ def __init__(self, lista_filtros, ncanais=1,rate=44100): """ Inicia o Player. lista_filtros: lista de filtros aplicados, se for uma tupla, se trata de uma preset. pos: Posição Inicial no preset """ self.filtros = lista_filtros if self.filtros is not None: self.filter = CascadeFilter(self.filtros) else: self.filter = CascadeFilter() self.ncanais = ncanais self.release = 0.05*filters.s self.rate = rate self.player = AudioIO() self.streamix = Streamix(True) self.input = ChangeableStream(self.player.record(nchannels=ncanais,rate=self.rate)) self.input.last = 0. self.stream = ChangeableStream(self.filter(self.input)) self.stream.last = 0. self.player.play(self.streamix, rate=self.rate) self.streamix.add(0,self.stream) def last_input_output(self): """ Função que retorna os últimos valores de input e output Na forma de tupla (in,out) """ try: return (self.input.last, self.stream.last) except: return (0,0) def muda_filtro(self, novos_filtros, window): """ Muda o filtro aplicado, garantindo que não haja um "click" ao fazer isso """ #self.chamando = True novo_filtro = CascadeFilter(novos_filtros) last = self.stream.last self.stream.limit(0).append(line(self.release,last,0)) self.stream = ChangeableStream(novo_filtro(self.input)) self.stream.last = last self.streamix.add(0, self.stream) def __del__(self): if not self.player.finished: self.player.close() #self.playerGrava.close() def pausar (self): """ Para o player """ if not self.player.finished: self.player.close() def tocar (self, lista_filtros=None): """ Reinicia o player (tanto quando ele é pausado como parado) """ if lista_filtros is None: lista_filtros = self.filtros self.__init__(lista_filtros,ncanais=self.ncanais,rate=self.rate)
out.add(0, sig * pamp) # Original remain = 1 - pamp for unused in xrange(copies): gain = remain * pamp out.add(dur / copies, sig * gain) remain -= gain return out # # Audio mixture # tracks = 3 # besides unpitched track dur_note = 120 * ms dur_perc = 100 * ms smix = Streamix() # Pitched tracks based on a 1:2 triangular wave table = TableLookup(line(100, -1, 1).append(line(200, 1, -1)).take(inf)) for track in xrange(tracks): env = adsr(dur_note, a=20 * ms, d=10 * ms, s=.8, r=30 * ms) / 1.7 / tracks smix.add(0, geometric_delay(new_note_track(env, table), 80 * ms, 2)) # Unpitched tracks pfuncs = [unpitched_low] * 4 + [unpitched_high] snd = chain.from_iterable( choice(pfuncs)(dur_perc, randint(0, 1)) for unused in zeros()) smix.add(0, geometric_delay(snd * (1 - 1 / 1.7), 20 * ms, 1)) # # Finishes (save in a wave file)
out.add(0, sig * pamp) # Original remain = 1 - pamp for unused in xrange(copies): gain = remain * pamp out.add(dur / copies, sig * gain) remain -= gain return out # # Audio mixture # tracks = 3 # besides unpitched track dur_note = 120 * ms dur_perc = 100 * ms smix = Streamix() # Pitched tracks based on a 1:2 triangular wave table = TableLookup(line(100, -1, 1).append(line(200, 1, -1)).take(inf)) for track in xrange(tracks): env = adsr(dur_note, a=20 * ms, d=10 * ms, s=0.8, r=30 * ms) / 1.7 / tracks smix.add(0, geometric_delay(new_note_track(env, table), 80 * ms, 2)) # Unpitched tracks pfuncs = [unpitched_low] * 4 + [unpitched_high] snd = chain.from_iterable(choice(pfuncs)(dur_perc, randint(0, 1)) for unused in zeros()) smix.add(0, geometric_delay(snd * (1 - 1 / 1.7), 20 * ms, 1)) # # Finishes (save in a wave file)
for staff in tab: print("\n".join("".join(el) for el in zip(*(heading_cols + staff)))) print() # # Audio # # Useful values from AudioLazy rate = 44100 s, Hz = sHz(rate) ms = 1e-3 * s kHz = 1e3 * Hz beat_duration = 60. / beat * s # In samples dur = beat_duration / notes_per_beat # Per note smix = Streamix() # That's our sound mixture env = adsr(dur, a=40*ms, d=35*ms, s=.6, r=70*ms).take(inf) # Envelope # Effects used def distortion(sig, multiplier=18): return atan(multiplier * sig) * (2 / pi) # Intro count synth filt = (1 - z ** -2) * .5 if starting_beats > 0: inoisy_stream = filt(gauss_noise()) * env inoisy_thub = thub(inoisy_stream.append(0).limit(beat_duration), starting_beats) inoisy = chain.from_iterable(repeat(inoisy_thub).limit(starting_beats)) smix.add(.1 * s, inoisy) smix.add(starting_beats * beat_duration - dur, []) # Event timing
for staff in tab: print("\n".join("".join(el) for el in zip(*(heading_cols + staff)))) print() # # Audio # # Useful values from AudioLazy rate = 44100 s, Hz = sHz(rate) ms = 1e-3 * s kHz = 1e3 * Hz beat_duration = 60. / beat * s # In samples dur = beat_duration / notes_per_beat # Per note smix = Streamix() # That's our sound mixture env = adsr(dur, a=40 * ms, d=35 * ms, s=.6, r=70 * ms).take(inf) # Envelope # Effects used def distortion(sig, multiplier=18): return atan(multiplier * sig) * (2 / pi) # Intro count synth filt = (1 - z**-2) * .5 if starting_beats > 0: inoisy_stream = filt(gauss_noise()) * env inoisy_thub = thub( inoisy_stream.append(0).limit(beat_duration), starting_beats) inoisy = chain.from_iterable(repeat(inoisy_thub).limit(starting_beats))