Ejemplo n.º 1
0
    def __init__(self, no_patterns: int, steps: int, bpm: float):
        """
        :param no_patterns: number of patterns (number of samples to trigger)
        :param steps: number of steps
        :param bpm: beats per minute
        """
        self.time_per_step = 1. / bpm * 60 / 4
        self.duration = steps * self.time_per_step
        self.offsets = [[0.] * steps for _ in range(no_patterns + 1)]
        self.pattern = [[False] * steps for _ in range(no_patterns + 1)]
        self.pattern_tables = [
            pyo.NewTable(self.duration) for _ in range(no_patterns + 1)
        ]
        self.trigger_tables = [
            pyo.TableRead(table, freq=1. / self.duration, interp=1, loop=1)
            for table in self.pattern_tables
        ]
        self.trigger_functions = [
            pyo.TrigFunc(trigger, lambda: None)
            for trigger in self.trigger_tables
        ]
        self.sampling_rate = self.trigger_tables[0].getSamplingRate()

        # the last pattern is always on to implement a callback at each step
        for step in range(steps):
            self.activate(no_patterns, step)
Ejemplo n.º 2
0
    def __init__(self, extractor):
        self.extractor = extractor

        self.table = pyo.NewTable(extractor.table.length)
        self.player = pyo.TableRead(self.table, freq=self.table.getRate())
        self.metro = pyo.Metro()
        self.trig = pyo.Percent(self.metro)

        self.trig_play = pyo.TrigFunc(self.trig, self.play)
        self.samples = np.asarray(self.table.getBuffer())
Ejemplo n.º 3
0
    def __init__(self, inp):
        self.inp = inp
        self.rec = False
        self.chain_data = np.zeros((CHAIN_LEN, 3))
        self.last_pitch = 0
        self.iw = 0
        self.ir = 0

        self.pitch_track = pyo.Yin(self.inp)
        self.vol_track = pyo.Clip(pyo.Follower(self.inp) * 500, 0.1, 1)
        self.pitch_table = pyo.NewTable(MAX_NOTE_LEN)
        self.vol_table = pyo.NewTable(MAX_NOTE_LEN)
        self.pitch_rec = pyo.TableRec(self.pitch_track, self.pitch_table)
        self.vol_rec = pyo.TableRec(self.vol_track, self.vol_table)
        self.pitch_samples = np.asarray(self.pitch_table.getBuffer())
        self.vol_samples = np.asarray(self.vol_table.getBuffer())

        self.note_detector = pyo.AttackDetector(self.inp)
        self.trig_rec = pyo.TrigFunc(self.note_detector, self.start_rec)
        self.trig_stop = pyo.TrigFunc(self.pitch_rec['trig'], self.stop_rec)
Ejemplo n.º 4
0
def TableWrap(audio, duration):
    '''
    Records a PyoAudio generator into a sound table, returns a tableread object which can play the audio with .out()
    '''
    # Duration is in ms, so divide by 1000
    audio.play()
    tab = pyo.NewTable(length=(float(duration) / 1000),
                       chnls=rpiset.NUM_CHANNELS)
    tabrec = pyo.TableRec(audio, table=tab, fadetime=0.01)
    tabrec.play()
    sleep((float(duration) / 1000))
    tabread = pyo.TableRead(tab, loop=0)
    return tabread
Ejemplo n.º 5
0
    def __init__(self):
        super().__init__()

        self.sine = pyo.CosTable([(0, 0), (100, 1), (1000, .25), (8191, 0)])
        self.square = pyo.SquareTable()
        self.saw = pyo.SawTable()
        self.synth = pyo.NewTable(8192 / 44100)

        self.pointer = pyo.Sig(0)
        self.morph = pyo.TableMorph(self.pointer, self.synth,
                                    [self.sine, self.square, self.saw])
        self.osc = pyo.Osc(self.synth, 440)
        self.filter = pyo.Biquad(self.osc)
        self.verb = pyo.WGVerb(self.filter).mix(2)
Ejemplo n.º 6
0
    def __init__(self, chain, extractor):
        self.chain = chain
        self.extractor = extractor

        self.table = pyo.NewTable(self.extractor.table.length)
        self.window = pyo.HannTable(self.table.size)
        self.samples = np.asarray(self.table.getBuffer())
        self.pitch = pyo.Sig(0)
        self.vol = pyo.Sig(0)
        self.env = pyo.Adsr()

        self.osc = pyo.Granule(self.table, self.window, dens=100)
        self.osc.setSync(False)

        self.sin = pyo.Blit(self.pitch, mul=self.vol)
        self.vocoder = pyo.Vocoder(self.sin, self.osc, self.pitch)
        self.compressor = pyo.Compress(self.vocoder)
Ejemplo n.º 7
0
        def table_wrap(self, audio, duration=None):
            """Records a PyoAudio generator into a sound table, returns a
            tableread object which can play the audio with .out()

            Args:
                audio:
                duration:
            """

            if not duration:
                duration = self.duration

            # Duration is in ms, so divide by 1000
            # See https://groups.google.com/forum/#!topic/pyo-discuss/N-pan7wPF-o
            # TODO: Get chnls to be responsive to NCHANNELS in prefs. hardcoded for now
            tab = pyo.NewTable(
                length=(float(duration) / 1000), chnls=prefs.NCHANNELS
            )  # Prefs should always be declared in the global namespace
            tabrec = pyo.TableRec(audio, table=tab, fadetime=0.005).play()
            sleep((float(duration) / 1000))
            self.table = pyo.TableRead(tab, freq=tab.getRate(), loop=0)
Ejemplo n.º 8
0
    def __init__(self, inp):
        self.inp = inp
        self.sounds = np.zeros((N_SEGMENTS, pyo.secToSamps(MAX_NOTE_LEN)))
        self.lens = np.zeros(N_SEGMENTS, dtype=np.int32)
        self.iw = 0
        self.on = False

        self.thresh = pyo.Sig(0.01)

        self.follower = pyo.Follower(self.inp, freq=10)
        self.up = pyo.Thresh(self.follower, self.thresh, dir=0)
        self.down = pyo.Thresh(self.follower, self.thresh, dir=1)

        self.table = pyo.NewTable(MAX_NOTE_LEN)
        self.rec = pyo.TableRec(self.inp, self.table)

        self.trig_start = pyo.TrigFunc(self.up, self.start_rec)
        self.trig_save = pyo.TrigFunc(self.down, self.save_sound)
        self.trig_drop = pyo.TrigFunc(self.rec['trig'], self.drop_rec)

        self.samples = np.asarray(self.table.getBuffer())
Ejemplo n.º 9
0
    def __init__(self, obj, path, chnls):
        # instance variables
        self._chnls = chnls
        self._path = path  # root path for recordings
        self._table_dur = 120.0  # min 5 sec.
        self._current_table_index = -1
        self._table_count = 2
        self._table_list = [
            pyo.NewTable(self._table_dur, self._chnls)
            for i in range(self._table_count)
        ]
        self._total_count = 0

        # pyo objects
        self._getNextTable()
        self._rec_obj = pyo.TableRec(
            obj, self._table_list[self._current_table_index])
        self._tswitch_trig = pyo.TrigFunc(
            self._rec_obj['trig'],
            self._switchNextTable,
            arg=[i for i in range(self._table_count)])
Ejemplo n.º 10
0
    def __init__(self):
        super().__init__()

        self.wv1 = pyo.CosTable([(0, 0), (4060, 1), (8191, 0)])
        self.wv2 = pyo.CosTable([(0, 0.00), (2074, 0.59), (4060, 1.00),
                                 (8191, 0.00)])
        self.wv3 = pyo.CosTable([(0, 0.00), (2074, 0.59), (4060, 1.00),
                                 (6117, 0.60), (8191, 0.00)])
        self.wv4 = pyo.CosTable([(0, 0.00), (2039, 0.29), (2039, 0.60),
                                 (4060, 1.00), (6117, 0.60), (6117, 0.30),
                                 (8191, 0.00)])
        self.wv5 = pyo.CosTable([(0, 0.00), (2039, 0.29), (2039, 0.60),
                                 (3255, 0.29), (4060, 1.00), (4900, 0.30),
                                 (6117, 0.60), (6117, 0.30), (8191, 0.00)])
        self.wv6 = pyo.CosTable([(0, 0.00), (769, 1.00), (2039, 0.29),
                                 (2039, 0.60), (3255, 0.29), (4060, 1.00),
                                 (4900, 0.30), (6117, 0.60), (6117, 0.30),
                                 (7333, 1.00), (8191, 0.00)])
        self.wv7 = pyo.CosTable([(0, 0.00), (769, 0.00), (769, 1.00),
                                 (2039, 0.29), (2039, 0.60), (3255, 0.29),
                                 (4060, 1.00), (4900, 0.30), (6117, 0.60),
                                 (6117, 0.30), (7333, 1.00), (7333, 0.00),
                                 (8191, 0.00)])
        self.wv8 = pyo.CosTable([(0, 0.00), (769, 0.00), (769, 1.00),
                                 (2039, 0.29), (2039, 0.60), (3255, 0.29),
                                 (3255, 1.00), (4900, 1.00), (4900, 0.30),
                                 (6117, 0.60), (6117, 0.30), (7333, 1.00),
                                 (7333, 0.00), (8191, 0.00)])
        self.synth = pyo.NewTable(8192 / 44100)

        self.pointer = pyo.Sig(0)
        self.morph = pyo.TableMorph(self.pointer, self.synth, [
            self.wv1, self.wv2, self.wv3, self.wv4, self.wv5, self.wv6,
            self.wv7, self.wv8
        ])
        self.osc = pyo.Osc(self.synth, 440)
        self.filter = pyo.Biquad(self.osc)
        self.verb = pyo.WGVerb(self.filter).mix(2)
Ejemplo n.º 11
0
    def __init__(self, input, buf_size=SAMPLE_RATE, buffer_count=2, overlap=0):
        """
        Parameters
        ----------
        input : PyoObject
            Parent PyoObject
        length : int
            Number of samples per buffer
        buffer_count : int 
            Number of buffers used to record (min 2)
        overlap : int
            Number of overlapping samples between adjacent buffers
        """

        self.buf_size = buf_size
        duration = (buf_size - overlap) / SAMPLE_RATE
        self.last_thread = None
        self.data_ready = pyo.Trig()
        self.rec_triggers = []
        self.tables = []
        self.ends = []
        self.overlap = overlap
        self.overlap_buffer = np.zeros(self.overlap)
        self.buffer_count = buffer_count
        self.curr_buf = 0
        self.playing = False
        self.np_buffer = None

        for i in range(buffer_count):
            self.rec_triggers.append(pyo.Trig())
            self.tables.append(pyo.NewTable(duration))
            table_rec = pyo.TrigTableRec(input, self.rec_triggers[i],
                                         self.tables[i])
            self.ends.append(pyo.TrigFunc(table_rec['trig'], self._table_full))

        self._base_objs = self.data_ready.getBaseObjects()
        self._trig_objs = self._base_objs
Ejemplo n.º 12
0
import pyo

s = pyo.Server().boot()
s.start()

#audioIn = pyo.Input(chnl=[0,1], mul=0.7)
a = pyo.Noise(.25)

fft = pyo.FFT(a, size=1024, overlaps=1, wintype=2)
re = fft['real']
im = fft['imag']
bin = fft['bin']
mag = pyo.Sqrt(re * re + im * im)

magTable = pyo.NewTable(1024)
tablerec = pyo.TableRec(mag, magTable)

refreshTrig = pyo.Select(bin, value=0)
pyo.TrigFunc(refreshTrig, tablerec.play)

value = pyo.TableIndex(magTable, bin)

s.gui(locals())
Ejemplo n.º 13
0
def main():
    '''Main method. Inits gpio, bridge, jack, and pyo. Then reads effects and starts handling gpio'''
    # If GPIO is enabled, initialize the pins and GPIO module.
    if GPIO_CAPABLE:
        GPIO.setmode(GPIO.BCM)
        GPIO.setwarnings(False)
        GPIO.setup(button_pin, GPIO.IN, GPIO.PUD_UP)
        GPIO.setup(23, GPIO.OUT)

        gpio_controller = gpiocontrol.GpioController()

    # Initialize the bridge to allow the app to accept connections.
    bridge_conn = bridge.Bridge()

    # Set up custom options for the sockets
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) #UDP SOCKET
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #TCP SOCKET
    s.setblocking(0)
    sock.setblocking(0)
    s.bind(('', 10000))
    sock.bind(('', 10001))

    jack_id = jackserver.start_jack_server()

    # give the application time for JACK to boot.
    time.sleep(5)

    # JACK and Pyo set up procedures
    pyo_server = start_pyo_server()
    pyo_server.setJackAuto()

    # Read input from the audio device on channel 0
    # and apply the necessary effects from the config file 
    enabled_effects = chain_effects(pyo.Input(chnl=0), configparser.get_effects())
    apply_effects( enabled_effects )

    # Create necessary variables used by the GPIO controller module
    record_table = []
    audio_recorder = []
    loop = []
    record_table.append(pyo.NewTable(length=60, chnls=1, feedback=0.5))
    audio_recorder.append(pyo.TableRec((enabled_effects[len(enabled_effects) - 1]), table=record_table[-1], fadetime=0.05))
    already_recording = False
    recording_time = 0
    inactive_end_time = 0
    signal.signal(signal.SIGINT, partial(signal_handler, jack_id, pyo_server))

    while True:
        # Executes GPIO and loop machine logic flow.
        if GPIO_CAPABLE:
            # Read the state of the button press. 
            BUTTON_STATE = gpio_controller.update_gpio()
            # Perform actions dependent on the state of the button press.
            if BUTTON_STATE == 'INACTIVE' or BUTTON_STATE == 'LOOPING':
                inactive_end_time = time.time()
            if BUTTON_STATE == 'RECORDING':
                recording_time = time.time()
                if not already_recording:
                    print("Recording audios for 5 segundos")
                    (audio_recorder[-1]).play()
                    already_recording = True
            elif BUTTON_STATE == 'ACTIVATE_LOOP':
                loop_len = recording_time - inactive_end_time
                loop.append(
                    pyo.Looper(
                        table=record_table[-1],
                        dur=loop_len, xfade=0,
                        mul=1).out()
                    )
                record_table.append(
                    pyo.NewTable(
                        length=60,
                        chnls=1,
                        feedback=0.5)
                    )
                audio_recorder.append(
                    pyo.TableRec(
                        (enabled_effects[len(enabled_effects) - 1]),
                        table=record_table[-1],
                        fadetime=0.05)
                    )
                print("ACTIVATING LOOP")
                gpio_controller.set_state("LOOPING")
                already_recording = False
            elif BUTTON_STATE == 'CLEAR_LOOP':
                loop = []
                record_table = []
                audio_recorder = []
                record_table.append(
                    pyo.NewTable(
                        length=60,
                        chnls=1,
                        feedback=0.5)
                    )
                audio_recorder.append(
                    pyo.TableRec(
                        (enabled_effects[len(enabled_effects) - 1]),
                        table=record_table[-1],
                        fadetime=0.05)
                    )
                gpio_controller.set_state("INACTIVE")

        # See if we got a message from the frontend application
        res = bridge_conn.backend(s,sock)
        if res:
            print(res)
            if 'UPDATEPORT' == res[0]:
                # There was a request to update the ports. Kill the
                # JACK server and restart it with the new ports.
                print("Request to update ports")
                pyo_server.shutdown()
                jackserver.kill_jack_server(jack_id)
                time.sleep(2)
                jack_id = jackserver.start_jack_server(jackserver.filter_port_selection(res[1]), jackserver.filter_port_selection(res[2]))
                time.sleep(2)
                pyo_server.reinit(**PYO_INIT_SETTINGS)
                pyo_server.boot()
                pyo_server.start()
            enabled_effects[-1].stop()
            enabled_effects = chain_effects(pyo.Input(chnl=0), configparser.get_effects())
            apply_effects( enabled_effects )
        time.sleep(0.0001)