Пример #1
0
 def update_data(self):
     with AudioIO(api=api) as rec:
         for el in rec.record(
                 rate=rate):  # Appears to run at about 44100 hz
             self.data.append(el)
             if self.finishedUpdate:
                 break
Пример #2
0
 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)
Пример #3
0
def pitch_from_mic(upd_time_in_ms):
    rate = 44100
    s, Hz = sHz(rate)

    with AudioIO() as recorder:
        snd = recorder.record(rate=rate)
        sndlow = lowpass(400 * Hz)(limiter(snd, cutoff=20 * Hz))
        hop = int(upd_time_in_ms * 1e-3 * s)
        for pitch in freq2str(dft_pitch(sndlow, size=2 * hop, hop=hop) / Hz):
            yield pitch
def pitch_from_mic(upd_time_in_ms):
    rate = 44100
    s, Hz = sHz(rate)

    api = sys.argv[1] if sys.argv[1:] else None  # Choose API via command-line
    chunks.size = 1 if api == "jack" else 16

    with AudioIO(api=api) as recorder:
        snd = recorder.record(rate=rate)
        sndlow = lowpass(400 * Hz)(limiter(snd, cutoff=20 * Hz))
        hop = int(upd_time_in_ms * 1e-3 * s)
        for pitch in freq2str(dft_pitch(sndlow, size=2 * hop, hop=hop) / Hz):
            yield pitch
Пример #5
0
def update_data():
    with AudioIO(api=api) as rec:
        for el in rec.record(rate=rate):
            data.append(el)
            if update_data.finish:
                break
Пример #6
0
a1 = Stream(*cycle_a1)
a2 = Stream(*cycle_a2) * 2
b1 = sinusoid(18 * Hz)  # Sine phase
b2 = sinusoid(freq=7 * Hz, phase=pi / 2)  # Cosine phase

# The filter
filt = (1 + b1 * z**-1 + b2 * z**-2 + .7 * z**-5)
filt /= (1 - a1 * z**-1 - a2 * z**-2 - .1 * z**-3)

# A really simple input
input_data = sinusoid(220 * Hz)

# Let's play it!
api = sys.argv[1] if sys.argv[1:] else None  # Choose API via command-line
chunks.size = 1 if api == "jack" else 16
with AudioIO(api=api) as player:
    th = player.play(input_data, rate=rate)
    time.sleep(1)  # Wait a sec
    th.stop()
    time.sleep(1)  # One sec "paused"
    player.play(filt(input_data), rate=rate)  # It's nice with rate/2 here =)
    time.sleep(3)  # Play the "filtered" input (3 secs)

# Quiz!
#
# Question 1: What's the filter "cycle" duration?
# Hint: Who cares?
#
# Question 2: Does the filter need to be periodic?
# Hint: Import white_noise and try to put this before defining the filt:
#   a1 *= white_noise()
Пример #7
0
    "ɤ": [460, 1310],
    "o": [360, 640],
    "ɯ": [300, 1390],
    "u": [250, 595],
}

# Initialization
rate = 44100
s, Hz = sHz(rate)
inertia_dur = 1 * s
inertia_filter = maverage(rint(inertia_dur))

api = sys.argv[1] if sys.argv[1:] else None  # Choose API via command-line
chunks.size = 1 if api == "jack" else 16

with AudioIO() as player:
    first_coeffs = formants[vowels[0]]

    # These are signals to be changed during the synthesis
    f1 = ControlStream(first_coeffs[0] * Hz)
    f2 = ControlStream(first_coeffs[1] * Hz)
    gain = ControlStream(0)  # For fading in

    # Creates the playing signal
    filt = CascadeFilter([
        resonator.z_exp(inertia_filter(f1).skip(inertia_dur), 400 * Hz),
        resonator.z_exp(inertia_filter(f2).skip(inertia_dur), 2000 * Hz),
    ])
    sig = filt((saw_table)(100 * Hz)) * inertia_filter(gain)

    th = player.play(sig)
Пример #8
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of AudioLazy, the signal processing Python package.
# Copyright (C) 2012-2013 Danilo de Jesus da Silva Bellini
#
# AudioLazy is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Created on Wed Nov 07 2012
# danilo [dot] bellini [at] gmail [dot] com
"""
Simple I/O wire example, connecting the input directly to the output
"""

from audiolazy import AudioIO

with AudioIO(True) as player_recorder:
  input_data = player_recorder.record(chunk_size=16)
  player_recorder.play(input_data, chunk_size=16)
Пример #9
0
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


# Replicator ("track" data generator)
def partial_cached():
    smix.add(octave_duration, partial_cached())  # Next track/partial event
    for el in data:
        yield el


# Play!
smix.add(0, partial())  # Starts the mixing with the first track/partial
with AudioIO(True) as player:
    player.play(smix, rate=rate)
Пример #10
0
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Simple I/O wire example, connecting the input directly to the output

This example uses the default PortAudio API, however you can change it by
using the "api" keyword argument in AudioIO creation, like

  with AudioIO(True, api="jack") as pr:

obviously, you can use another API instead (like "alsa").

Note
----
When using JACK, keep chunks.size = 1
"""

from audiolazy import chunks, AudioIO
import sys

# Choose API via command-line
api = sys.argv[1] if sys.argv[1:] else None

# Amount of samples per chunk to be sent to PortAudio
chunks.size = 1 if api == "jack" else 16

with AudioIO(True, api=api) as pr: # A player-recorder
  pr.play(pr.record())
Пример #11
0
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Created on Wed Nov 07 2012
# danilo [dot] bellini [at] gmail [dot] com
"""
Simple I/O wire example, connecting the input directly to the output

This example uses the default PortAudio API, however you can change it by
using the "api" keyword argument in AudioIO creation, like

  with AudioIO(True, api="jack") as pr:

obviously, you can use another API instead (like "alsa").

Note
----
When using JACK, keep chunks.size = 1
"""

from audiolazy import chunks, AudioIO

chunks.size = 16  # Amount of samples per chunk to be sent to PortAudio
with AudioIO(True) as pr:  # A player-recorder
    pr.play(pr.record())
Пример #12
0
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)
        
        
        
        
Пример #13
0
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


# Replicator ("track" data generator)
def partial_cached():
    smix.add(octave_duration, partial_cached())  # Next track/partial event
    for el in data:
        yield el


# Play!
smix.add(0, partial())  # Starts the mixing with the first track/partial
api = sys.argv[1] if sys.argv[1:] else None  # Choose API via command-line
chunks.size = 1 if api == "jack" else 16
with AudioIO(True, api=api) as player:
    player.play(smix, rate=rate)
Пример #14
0
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Realtime STFT effect to robotize a voice (or anything else)

This is done by removing (zeroing) the phases, which means a single spectrum
block processing function that keeps the magnitudes and removes the phase, a
function a.k.a. "abs", the absolute value. The initial zero-phasing isn't
needed at all since the phases are going to be removed, so the "before" step
can be safely removed.
"""

from audiolazy import window, stft, chunks, AudioIO
import sys

wnd = window.hann
robotize = stft(abs, size=1024, hop=441, before=None, wnd=wnd, ola_wnd=wnd)

api = sys.argv[1] if sys.argv[1:] else None
chunks.size = 1 if api == "jack" else 16
with AudioIO(True, api=api) as pr:
    pr.play(robotize(pr.record()))