Exemplo n.º 1
0
def model_predict(model, input_track, sample_size, trans_fw=None, trans_bw=None):
    dim = sample_size
    n_batches = int(len(input_track) / dim) - 1

    pred_batches = input_track[0:n_batches * dim].reshape((-1, dim))
    pred_batches_shifted = input_track[dim // 2:n_batches * dim + dim // 2].reshape((-1, dim))

    print("FFT transforming...")

    if trans_fw is not None:
        pred_batches, pred_batches_shifted = map(lambda x: parallel_apply_along_axis(trans_fw, 0, x),
                                                 (pred_batches, pred_batches_shifted))

    if trans_bw is None:
        trans_bw = lambda x: x

    xfp = x_fade_profile(dim)

    print("Predicting and transforming...")

    pred_batches, pred_batches_shifted = map(lambda x: parallel_apply_along_axis(trans_bw, 0, model.predict(x)),
                                             (pred_batches, pred_batches_shifted))

    print("Applying x-fade and mixing...")
    x0 = np.array([xfp * batch for batch in pred_batches]).reshape(-1)
    x1 = np.array([xfp * batch for batch in pred_batches_shifted]).reshape(-1)

    return mix_at(x0, x1, dim // 2)
Exemplo n.º 2
0
def forward_stft(data, stft_sample_size=4096, stft_stride=256, window=None):
    stft_ix = np.arange(0, len(data) - stft_sample_size, stft_stride)
    stft_samples = []
    for ix in stft_ix:
        sample = data[ix:ix + stft_sample_size]
        stft_samples.append(sample)

    stft_samples = np.array(stft_samples)

    if window is not None:
        if len(window) != stft_sample_size:
            raise ValueError(f"Number of samples in window parameter should match the sample size ({stft_sample_size})")

        stft_samples *= np.outer(np.ones(stft_samples.shape[0]), window)

    transformed = parallel_apply_along_axis(rfft, 0, stft_samples)
    return transformed
Exemplo n.º 3
0
def backward_stft(data, stft_stride, window=None):

    n_stft_samples = data.shape[0]
    stft_sample_size = data.shape[1]
    overlap_factor = stft_stride / stft_sample_size

    stft_samples = parallel_apply_along_axis(irfft, 0, data)

    stft_samples *= overlap_factor
    out = np.zeros(stft_stride * n_stft_samples + stft_sample_size)

    for ii, sample in enumerate(stft_samples):
        i_begin = ii*stft_stride
        i_end = i_begin + stft_sample_size
        out[i_begin:i_end] += sample

    return out
Exemplo n.º 4
0
def apply_fourier_on_input(input_track, window_size):
    n_batches = int(len(input_track) / window_size)
    batches = input_track[0:n_batches*window_size].reshape((-1, window_size))
    return parallel_apply_along_axis(rfft, 0, batches)
Exemplo n.º 5
0
def decoder_predict(decoder_model, encoded_x, trans_bw):
    return parallel_apply_along_axis(trans_bw, 0, decoder_model.predict(encoded_x)).reshape(-1)