import numpy as np import matplotlib.pyplot as plt import envelopes import common N = 30 n = np.arange(N) adsr = envelopes.gate_to_adsr(5, 1, 1, 5) gate0 = np.zeros(N) gate0[5:20] = 1 states0 = adsr.gate_to_adsr_seq(gate0) gate1 = np.zeros(N) gate1[5:8] = 1 gate1[9:19] = 1 states1 = adsr.gate_to_adsr_seq(gate1) plt.figure() common.logic_plot(n, states0) plt.figure() common.logic_plot(n, states1) plt.show()
N_blk = 16 note_starts = np.zeros(N).astype('int') note_starts[[2, 7, 11, 14, 28, 70, 87, 90, 112]] = 1 note_ends = np.zeros(N).astype('int') note_ends[[7, 10, 12, 21, 50, 83, 89, 96, 112]] = 1 note_states = np.cumsum(note_starts - note_ends) # a signal that changes sign when there is a note_end and note_state is on and at the beginning of a block seg_sig = np.zeros(N).astype('int') seg_sig[np.arange(0, N, N_blk).astype('int')] = 1 seg_sig[np.where(note_ends & note_states)[0]] = 1 seg_sig = np.power(-1, np.cumsum(seg_sig)) * note_states seg_starts = np.diff(np.concatenate(([0], seg_sig))) seg_starts[seg_starts != 0] = seg_starts[seg_starts != 0] / np.abs( seg_starts[seg_starts != 0]) seg_starts *= note_states seg_ends = np.diff(np.concatenate((seg_sig, [0]))) seg_ends[seg_ends != 0] = seg_ends[seg_ends != 0] / np.abs( seg_ends[seg_ends != 0]) seg_ends *= note_states n = np.arange(N) common.logic_plot(n, 0.9 * note_starts + 2, label='note starts') common.logic_plot(n, 0.9 * note_ends + 1, label='note ends') common.logic_plot(n, 0.9 * note_states, label='note states') common.logic_plot(n, 0.5 * seg_sig + 3.5, label='segmenting signal') common.logic_plot(n, 0.25 * seg_starts + 3.5, label='segment starts') common.logic_plot(n, 0.25 * seg_ends + 3.5, label='segment ends') plt.legend() plt.show()
import numpy as np import matplotlib.pyplot as plt import common B = 256 adsr_active = np.fromfile('/tmp/adsr_active.f32', dtype='float32') start = np.fromfile('/tmp/start.f32', dtype='float32') end = np.fromfile('/tmp/end.f32', dtype='float32') adsr_envelope = np.fromfile('/tmp/adsr_envelope.f32', dtype='float32') P = len(adsr_envelope) N = len(adsr_active) n = np.arange(N) common.logic_plot(n, start, label='start') common.logic_plot(n, end + 1, label='end') common.logic_plot(n, adsr_active + 2, label='adsr_active') regions = np.fromfile('/tmp/regions.txt', sep=' ').reshape(-1, 2) for reg in regions: common.region_plot(reg[0], reg[1], height=0.5, level=3, color='k') for m in range(0, P, B): common.region_plot(m, m + B, height=0.5, level=3.5, color='k') p = np.arange(P) plt.plot(p, adsr_envelope + 4) plt.legend() plt.show()
# a signal that changes sign when there is a note_end and note_state is on and at the beginning of a block seg_sig = np.zeros(N).astype('int') seg_sig[np.arange(0, N, N_blk).astype('int')] = 1 seg_sig[np.where(note_ends & note_states)[0]] = 1 seg_sig = np.power(-1, np.cumsum(seg_sig)) * note_states seg_starts = np.diff(np.concatenate(([0], seg_sig))) seg_starts[seg_starts != 0] = seg_starts[seg_starts != 0] / np.abs( seg_starts[seg_starts != 0]) seg_starts *= note_states seg_ends = np.diff(np.concatenate((seg_sig, [0]))) seg_ends[seg_ends != 0] = seg_ends[seg_ends != 0] / np.abs( seg_ends[seg_ends != 0]) seg_ends *= note_states n = np.arange(N) common.logic_plot(n, 0.9 * note_starts + 2, label='note starts') common.logic_plot(n, 0.9 * note_ends + 1, label='note ends') common.logic_plot(n, 0.9 * note_states, label='note states') common.logic_plot(n, 0.5 * seg_sig + 3.5, label='segmenting signal') common.logic_plot(n, 0.25 * seg_starts + 3.5, label='segment starts') common.logic_plot(n, 0.25 * seg_ends + 3.5, label='segment ends') rs = region_segmenter(N_blk) rs_starts_dict = dict(label='augmented starts') rs_ends_dict = dict(label='augmented ends') for n_ in range(0, N - N_blk, N_blk): ant, ans, ane, regs = rs.region_segmenter_update(note_starts[n_:], note_ends[n_:], note_states[n_:]) common.logic_plot(n[n_:n_ + N_blk + 1], 0.4 * ans + 4.5,
import numpy as np import matplotlib.pyplot as plt from envelopes import gate_to_ramp from common import logic_plot N=100 thresh=1. gate=np.random.standard_normal(N) gate=(gate>1.).astype('float') gate=np.cumsum(gate) gate %= 2 ramp_sig=gate_to_ramp(gate) assert(len(gate)==len(ramp_sig)) logic_plot(np.arange(N),gate) logic_plot(np.arange(N),ramp_sig,color='purple') plt.show()
import numpy as np import matplotlib.pyplot as plt from envelopes import gate_to_adsr from common import logic_plot N = 1000 thresh = 1 gate = np.random.standard_normal(N) gate = (gate > thresh).astype('float') gate = np.cumsum(gate) gate %= 2 #gate=np.zeros(N) #gate[25:N-25]=1 gate_to_adsr_inst = gate_to_adsr(3, 4, 0.5, 5, decay_min_dB=-24) adsr_sig = gate_to_adsr_inst.gate_to_adsr_seq(gate) adsr_env = gate_to_adsr_inst.adsr_seq_to_env(adsr_sig) logic_plot(np.arange(N), gate, label='gate') logic_plot(np.arange(N), adsr_sig, color='purple', label='ADSR states') logic_plot(np.arange(N), adsr_env, color='orange', label='ADSR envelope') plt.legend() plt.show()