import classic_puckette_timestretch
import common
import attack_finder

SAMPLE_RATE=16000
W=common.get_env('W',default=2048,conv=int)
H=common.get_env('H',default=512,conv=int)
S=common.get_env('S',default=0.5,conv=float)
NG_TH=common.get_env('NG_TH',default=-30,conv=float)

attack_times=np.array([0.5,1.,1.25])
attack_times=(attack_times*SAMPLE_RATE).astype('int')

av=time_map_tstretch.attack_avoider(
attack_times,
-3*H,
W+2*H,
H)

# make signal

sigs=[]
for fname in [
    '/tmp/piano_adj_beg/60.f64',
    '/tmp/piano_adj_beg/64.f64',
    '/tmp/piano_adj_beg/67.f64']:
    sigs.append(np.fromfile(fname))

file_lengths=np.array([len(s) for s in sigs])
output_length=np.max(np.add.outer(attack_times,file_lengths))
x=np.zeros(output_length)
        N += H
    x = x[:N]
    n = np.arange(N)
    x += np.random.standard_normal(N) * 1e-8
    attack_time_pairs = attack_finder.attacks_from_spectral_diff(
        x, lmax_filt_rate=SR)
    attack_times = np.array([b for a, b in attack_time_pairs])
else:
    N = 500 * H
    attack_times = np.array([100 * H + 10, 200 * H - 10, 300 * H - 20])
    n = np.arange(N)
    # chirp frequency
    f0 = 0.01
    x = signal.chirp(n, f0, N, f0)
    x[attack_times] = 1
av = attack_avoider(attack_times, -H, H + W, H)
# stretch factor
min_S = .5
max_S = 1
S_osc_freq = 0.0001
s_ = signal.chirp(n, S_osc_freq, N, S_osc_freq)
s = np.zeros_like(s_)
s[s_ > 0] = max_S
s[s_ <= 0] = min_S

#s=0.5*(s+1)
#s*=(max_S-min_S)
#s+=min_S

# shift factors
min_P = .75
Пример #3
0
T_out = T
N_out = int(np.ceil(SR * T_out))
y = np.zeros(N_out)

# activation gate
tone_out_T0 = 1
tone_out_N0 = tone_out_T0 * SR
tone_out_N1 = N_out
gate_0 = np.zeros_like(y)
gate_0[tone_out_N0:tone_out_N1] = 1

rs = envelopes.region_segmenter(H)
wl = windowed_lookup(x, W)
pv = pvoc_synth(signal.get_window('hann', W), signal.get_window('hann', W), W,
                H, lambda n: wl.access(n))
av = time_map_tstretch.attack_avoider(attack_times, -3 * H, W + 2 * H, H)
aaa = time_map_tstretch.attack_avoid_access(
    lambda t, r: pv.process(int(np.round(t)), r), av)
ps = pitch_shift.pitch_shifter(aaa, B=H)
adsr = envelopes.gate_to_adsr(200, 1, 1, 200)

# control signals
pos_sig = np.linspace(3 * SR, 3 * SR, N_out)
ps_sig = np.linspace(ps_0, ps_0, N_out)
ts_sig = np.linspace(ts_0, ts_0, N_out)

for n_ in range(0, N_out, H):
    H_ = min(N_out - n_, H)
    en, st, ed, ac, sta = adsr.gate_to_adsr_env_start_end_active(gate_0[n_:n_ +
                                                                        H_])
    ant, ans, ane, regs = rs.region_segmenter_update(st, ed, ac)