def test_beat3a(server): inp = pyo.Input([0, 1]) mix = pyo.Mix(inp) ad = pyo.AttackDetector(mix, 0.005, 10, 3, -30, 0.1) ad.ctrl() tmr = pyo.Timer(ad, ad) prn = pyo.Print(tmr, 1, message='tmr') return ad, prn
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 __init__(self, signal: pyo.Input) -> None: self.signal = signal self.follower = pyo.Follower(self.signal, freq=30) self.attack_detector = pyo.AttackDetector( self.signal, deltime=0.005, cutoff=10, maxthresh=3, minthresh=-30, reltime=0.1, ) self.pitch_tracker = pyo.Yin( self.signal, tolerance=0.2, minfreq=40, maxfreq=1000, cutoff=1000, winsize=1024, mul=1, add=0, ) self.pitch_tracker.stop() self.attack_detector.stop() self.processed_signal = signal
def test_beat1(server): server.server_ms = 0 last_ms = 0 server.last_bpm = 0 server.bpms = [] server.last_avg = 0 def trig_func(): #ct = server.getCurrentTime() delta = server_ms - last_ms last_ms = server_ms #delta = ct - last_ct #bpm = print(delta, 'trig') def time_callback(hours, minutes, seconds, milliseconds): #print(hours, minutes, seconds, milliseconds) server.server_ms = hours * 3600000 + minutes * 60000 + seconds * 1000 + milliseconds def process_callback(): if ad.minthresh != thr.get(): ad.minthresh = thr.get() #if server.last_avg != avg.get(): # print('avg', avg.get()) # server.last_avg = avg.get() return #bpm = 120 / (tmr.get() or 0.001) #while bpm > 360: # bpm /= 2 #while bpm < 40: # bpm *= 2 #print('bpm?', bpm) data = table.getTable() if len(data): #data = [d for d in data if d] #print(len(data), sum(data), server.server_ms) bpm = len(data) * 60 / (sum(data) or 0.001) while bpm > 360: bpm /= 2 while bpm < 40: bpm *= 2 #server.bpms.append() bpm = int(bpm) if bpm != server.last_bpm: server.last_bpm = bpm print('bpm?', bpm) table.reset() #tfl.play() #print(ad.minthresh) server.setTimeCallable(time_callback) server.setCallback(process_callback) table = pyo.DataTable(size=32) inp = pyo.Input([0, 1]) mix = pyo.Mix(inp) flr = pyo.Follower2(mix, 0.5, 0.5) fla = pyo.Average(flr, server.getBufferSize()) #flr.ctrl() spl = pyo.AToDB(flr) thr = spl - 6 ad = pyo.AttackDetector(mix, 0.005, 1000, 12, -30, 0.05) #ad.ctrl() #prn = pyo.Print(ad, 1, message='ad') prn = None tmr = pyo.Timer(ad, ad) #avg = pyo.Average(tmr, server.getBufferSize()) #bpm = 60 / pyo.Min(tmr, 0.001) #trg = pyo.TrigFunc(ad, trig_func) prn2 = pyo.Print(tmr, 1, message='tmr') #tfl = pyo.TableFill(tmr, table) return ad, prn, thr, prn2