""" """ User selected parameters """ input_wav = "speech.wav" grain_len = 20 # in milliseconds grain_over = 0.99 # grain overlap (0,1) shift_factor = 1.5 # open WAV file samp_freq, signal = wavfile.read(input_wav) signal = signal[:,] # get first channel data_type = signal.dtype MAX_VAL = np.iinfo(data_type).max # derived parameters GRAIN_LEN_SAMP = ms2smp(grain_len, samp_freq) STRIDE = compute_stride(GRAIN_LEN_SAMP, grain_over) OVERLAP_LEN = GRAIN_LEN_SAMP-STRIDE # allocate input and output buffers input_buffer = np.zeros(STRIDE, dtype=data_type) output_buffer = np.zeros(STRIDE, dtype=data_type) # state variables and constants def init(): # lookup table for tapering window global WIN WIN = win_taper(GRAIN_LEN_SAMP, grain_over, data_type) # lookup table for linear interpolation
from utils import ms2smp, double_len, double_len_taper f = 100 grain_len = 32 # ms overlap = 0.3 duration = 100 # ms disp = 60 fs = 16000 # original time = np.arange(int(duration * 1e-3 * fs)) / fs x = np.sin(2 * np.pi * f * time) # double length grain_len_samp = ms2smp(grain_len, fs) x_double = double_len(x, grain_len_samp) time_double = np.arange(len(x_double)) / fs # double length with overlap/window x_double_win, stride_samp, grains = double_len_taper(x, grain_len_samp, overlap) stride_len = stride_samp / fs * 1000 time_double_win = np.arange(len(x_double_win)) / fs # visualize discontinuous f, (ax1, ax2) = plt.subplots(2, 1) ax1.plot(time, x) ax1.grid() ax1.set_ylabel("Original", fontsize=18)
import numpy as np from utils import ms2smp, compute_stride, win_taper, build_linear_interp_table import sounddevice as sd """ Real-time pitch shifting with granular synthesis for shift factors <=1.0 """ """ User selected parameters """ grain_len = 30 grain_over = 0.2 shift_factor = 0.7 data_type = np.int16 # derived parameters MAX_VAL = np.iinfo(data_type).max GRAIN_LEN_SAMP = ms2smp(grain_len, 8000) STRIDE = compute_stride(GRAIN_LEN_SAMP, grain_over) OVERLAP_LEN = GRAIN_LEN_SAMP - STRIDE # allocate input and output buffers input_buffer = np.zeros(STRIDE, dtype=data_type) output_buffer = np.zeros(STRIDE, dtype=data_type) # state variables and constants def init(): # lookup table for tapering window global WIN WIN = win_taper(GRAIN_LEN_SAMP, grain_over, data_type) # lookup table for linear interpolation