Exemplo n.º 1
0
def gen():
    nframes = 128
    numpy.random.seed(42)
    y = numpy.random.rand(nframes).astype('float32')
    n_fft = 64
    win_length = n_fft  # by default win_length = n_fft
    hop_length = win_length // 4  # default hop length is win_length / 4
    # window function = 'hann'
    D = librosa.stft(y,
                     n_fft=n_fft,
                     hop_length=hop_length,
                     win_length=win_length)
    #print(D.shape)

    # NOTE: librosa uses Fortran order for stft matrix.
    if numpy.isfortran(D):
        D = numpy.transpose(D)

    print('const float g_input[] = {' + print_c_array(y) + '};')
    print('const float g_reference[] = {' + print_c_array(D) + '};')
    print('const size_t k_n_fft = {};'.format(n_fft))
    print('const size_t k_nframes = {};'.format(nframes))
    print('const size_t k_out_dim0 = {};'.format(D.shape[0]))
    print('const size_t k_out_dim1 = {};'.format(D.shape[1]))
    #print('const size_t k_nrows = {};'.format(1))
    print('const size_t k_hop_length = {};'.format(hop_length))
    print('const size_t k_win_length = {};'.format(win_length))
Exemplo n.º 2
0
def gen():
    nframes = 16
    nrows = 4

    numpy.random.seed(42)
    volume = numpy.random.rand(nrows, nframes).astype(numpy.float32)

    fft_len = nframes - 1
    f = numpy.fft.rfft(volume, fft_len)
    #print(len(y))
    #print(numpy.absolute(y))

    #a = numpy.absolute(y)
    #print(a.shape)

    #print('sum = ', numpy.sum(a, 1))

    n = 6
    y = numpy.fft.ifft(f, n)

    print('const float g_input[] = {' + print_c_array(f) + '};')
    print('const float g_reference[] = {' + print_c_array(y) + '};')
    print('const size_t k_n = {};'.format(n))
    print('const size_t k_ncolumns = {};'.format(f.shape[1]))
    print('const size_t k_nrows = {};'.format(f.shape[0]))
Exemplo n.º 3
0
def gen():
    n = 32
    ksize = 3
    numpy.random.seed(42)
    volume = numpy.random.rand(n).astype(numpy.float32)
    out = scipy.signal.medfilt(volume, kernel_size=ksize)

    print('const float g_input[] = {' + print_c_array(volume) + '};')
    print('const float g_reference[] = {' + print_c_array(out) + '};')
    print('const size_t k_input_n = {};'.format(n))
    print('const size_t k_window_size = {};'.format(ksize))
Exemplo n.º 4
0
def gen():
    nframes = 16
    ncoeffs = 5

    numpy.random.seed(42)
    volume = numpy.random.rand(nframes, ncoeffs).astype(numpy.float32)

    y = lifter(volume)

    print('const float g_input[] = {' + print_c_array(volume) + '};')
    print('const float g_reference[] = {' + print_c_array(y) + '};')
    print('const size_t k_nframes = {};'.format(nframes))
    print('const size_t k_ncoeffs = {};'.format(ncoeffs))
Exemplo n.º 5
0
def gen():

    win_length = 64
    y = scipy.signal.get_window('hann', win_length)  # fftbins=True = peridoc

    print('const float g_reference[] = {' + print_c_array(y) + '};')
    print('const size_t k_win_length = {};'.format(win_length))
Exemplo n.º 6
0
def gen():
    n = 32
    seed = 42
    numpy.random.seed(seed)
    volume = numpy.random.normal(0.0, 1.0, n).astype(numpy.float32)

    print('const float g_reference[] = {' + print_c_array(volume) + '};')
    print('const size_t k_n = {};'.format(n))
    print('const size_t k_seed = {};'.format(seed))
Exemplo n.º 7
0
def gen():
    n = 5
    m = 3

    seed = 42
    numpy.random.seed(seed)
    a = numpy.random.rand(n).astype(numpy.float32)
    v = numpy.random.rand(m).astype(numpy.float32)
    c = numpy.convolve(a, v, mode='full')

    assert len(c) == (n + m - 1)

    print('const float g_a[] = {' + print_c_array(a) + '};')
    print('const float g_v[] = {' + print_c_array(v) + '};')
    print('const float g_reference[] = {' + print_c_array(c) + '};')
    print('const size_t k_n = {};'.format(n))
    print('const size_t k_m = {};'.format(m))
    print('const size_t k_outnum = {};'.format(len(c)))
def gen():
    sr = 22050
    n_fft = 2048
    M = librosa.filters.mel(sr, n_fft)

    if numpy.isfortran(M):
        M = numpy.transpose(M)

    print('const float g_reference[] = {' + print_c_array(M) + '};')
    print('const size_t k_sr = {};'.format(sr))
    print('const size_t k_nfft = {};'.format(n_fft))