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)
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
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)
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())
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)])
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())
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)