adj_analysis_times=[av.adjust(at) for at in analysis_times] reset_times = np.where(np.array([b for t,b in adj_analysis_times]))[0] adj_analysis_times=np.array([t for t,b in adj_analysis_times]) plot_adj_atimes_x=np.sort(np.concatenate((adj_analysis_times,adj_analysis_times))) ones_osc=np.power(-1,np.arange(len(adj_analysis_times))) plot_adj_atimes_y=np.zeros(len(plot_adj_atimes_x)) plot_adj_atimes_y[1::2]=ones_osc plot_adj_atimes_y[2::2]=ones_osc[:-1] plot_adj_atimes_y[0]=-1 print(plot_adj_atimes_x[:10]) print(plot_adj_atimes_y[:10]) y=classic_puckette_timestretch.time_stretch_arb_times( x, adj_analysis_times, H, W, reset_times=adj_analysis_times[reset_times]) attack_regions=attack_finder.attacks_from_spectral_diff(x,ng_th=NG_TH) attack_starts=np.array([x for x,y in attack_regions]) attack_ends=np.array([y for x,y in attack_regions]) av_est=time_map_tstretch.attack_avoider( attack_ends, -2*H, W+2*H, H) adj_analysis_times_est=[av_est.adjust(at) for at in analysis_times] reset_times_est = np.where(np.array([b for t,b in adj_analysis_times_est]))[0] adj_analysis_times_est=np.array([t for t,b in adj_analysis_times_est]) plot_adj_atimes_x_est=np.sort(np.concatenate((adj_analysis_times_est,adj_analysis_times_est))) ones_osc_est=np.power(-1,np.arange(len(adj_analysis_times_est)))
import classic_puckette_timestretch as cpt import numpy as np H=5 W=32 x=np.random.standard_normal(1000) a_times=np.arange(0,len(x)-W,H) print('hop times') print(a_times) y=cpt.time_stretch_arb_times(x,a_times,H,W, window_type='blackmanharris', synth_window_type='hann') print(y/x[:len(y)])
x = snd t = np.arange(0, N, H) # distrupt the analysis times #t_d_idcs=np.arange(100,1100) # distrupt from 0.125 to 0.375 t_d_idcs = np.where((t > (0.25 * SAMPLE_RATE)) & (t < ((D - 1.5) * SAMPLE_RATE)))[0] #t[t_d_idcs]-=np.linspace(H,0,len(t_d_idcs)).astype('int') # freeze t[t_d_idcs] = t[t_d_idcs[0]] + np.linspace(0, 50, len(t_d_idcs)).astype('int') print(t[t_d_idcs]) # reset the pvoc after the disruption #reset_times=[t[t_d_idcs[-1]+1]] attack_time = D * SAMPLE_RATE reset_times = [t[np.argmin(np.abs(t - attack_time)) - 2]] y = cpt.time_stretch_arb_times(x, t, H, W, reset_times=reset_times)[:N] fig, axs = plt.subplots(3, 1) axs[0].plot(n, x) axs[0].set_title('original signal') axs[1].plot(n, y) axs[1].set_title('time stretched signal') axs[1].plot([t[t_d_idcs[0]], t[t_d_idcs[0]]], [0, 1], 'r') axs[1].plot([t[t_d_idcs[-1]], t[t_d_idcs[-1]]], [0, 1], 'r') axs[1].plot([reset_times[0], reset_times[0]], [0, 1], 'g') axs[2].plot(n, np.abs(x - y)) axs[2].set_title('error') x.tofile('/tmp/x.f64') y.tofile('/tmp/y.f64')
self.last_output_time + awin_start + awin_len): self.safe = 0 return ret # Signal to time stretch N = 1000 N_cycles = 30 x_ph = np.arange(N) * N_cycles / N * 2 * np.pi x = np.sin(x_ph) # points to corrupt crpt_points = np.array([150, 575], dtype='int') x[crpt_points] = 1 W = 256 H = 64 # analysis points (to make it twice as long) t_stretch = 0.5 apoints = np.arange(0, N - W, H * t_stretch, dtype='int') # correct them so we don't smear the impulses aavoider = attack_avoider() corrected_apoints = np.array( [aavoider.attack_avoid(crpt_points, at, -H, W + H, H) for at in apoints], dtype='int') #y=classic_puckette_timestretch.time_stretch_arb_times(x,corrected_apoints,H,W) y = classic_puckette_timestretch.time_stretch_arb_times(x, apoints, H, W) fig, axs = plt.subplots(2, 1) axs[0].plot(np.arange(N), x) axs[1].plot(np.arange(len(y)), y) plt.show()
augmented_io_time_pairs = [] lw = (H + W) * LOCK_WINDOW for pair in io_time_pairs: augmented_io_time_pairs.append(pair) if (pair.in_time + lw) < (orig_len_x - W): # we don't want to add any points that would make an analysis # window extend beyond the end of the sound file augmented_io_time_pairs.append( time_map_tstretch.io_time_pair(pair.in_time + lw, pair.out_time + lw)) io_time_pairs = augmented_io_time_pairs # sort because the lock window could have introduced points extending past the next points io_time_pairs = time_map_tstretch.sort_io_time_pairs_in_time(io_time_pairs) assert (time_map_tstretch.check_io_time_pairs_in_bounds( io_time_pairs, H, W, 0, len(x))) # we also want to map 0 -> 0. This will be okay (it will not cause an # out-of-bounds reading) because the time stretcher doesn't use a previous # input frame to synthesize the first output frame #io_time_pairs=[time_map_tstretch.io_time_pair(0,0)]+io_time_pairs io_time_pairs = time_map_tstretch.filter_close_inc_io_time_maps( io_time_pairs, H + W, H + W) out_locked_frames = time_map_tstretch.out_locked_frames( io_time_pairs, H, W) in_locked_frames = time_map_tstretch.in_locked_frames(out_locked_frames, W) in_locked_frames = np.array(in_locked_frames, dtype='int') print(in_locked_frames) y = classic_puckette_timestretch.time_stretch_arb_times( x, in_locked_frames, H, W) y = common.normalize(y) y.tofile(OUTPUT)
# create /tmp/guit.f64 via # sox sounds/guitar.wav -c 1 -r 16k /tmp/guit.f64 import numpy as np import classic_puckette_timestretch import common x = np.fromfile('/tmp/guit.f64', dtype='float64') H = 128 W = 1024 N = len(x) # simple 2x slower t_2x = np.concatenate(([0], np.arange(H, N - W, H / 2))).astype('int') y_2x = classic_puckette_timestretch.time_stretch_arb_times(x, t_2x, H, W) y_2x = common.normalize(y_2x) y_2x.tofile('/tmp/guit_2x.f64') # random t_rand = [0] t_ = H while t_ <= N - W: t_rand.append(t_) t_ += np.random.randint(2 * H) t_rand = np.array(t_rand) t_rand = np.random.randint(H, N - W, 10000) t_rand = np.concatenate(([0], t_rand)) y_rand = classic_puckette_timestretch.time_stretch_arb_times(x, t_rand, H, W)