How to use the pyroomacoustics.bss function in pyroomacoustics

To help you get started, we’ve selected a few pyroomacoustics examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github onolab-tmu / overiva / auxiva_pca.py View on Github external
# v.shape == (n_freq, n_chan), w.shape == (n_freq, n_chan, n_chan)
        v, w = np.linalg.eigh(covmat)

        # Apply dimensionality reduction
        # new shape: (n_frames, n_freq, n_src)
        new_X = np.matmul(
            X.swapaxes(0, 1), np.conj(w[:, :, -n_src:])
        ).swapaxes(0, 1)

    else:
        new_X = X

    kwargs.pop('proj_back')
    Y = oiva(new_X, proj_back=False, **kwargs)

    z = pra.bss.projection_back(Y, X[:, :, 0])
    Y *= np.conj(z[None, :, :])

    return Y
github LCAV / pyroomacoustics / examples / bss_live.py View on Github external
elif bss_type == 'ilrma':
        # Run ILRMA
        Y = pra.bss.ilrma(X, n_iter=args.n_iter, n_components=30, proj_back=True,
            callback=cb_print)
    elif bss_type == 'fastmnmf':
        # Run FastMNMF
        Y = pra.bss.fastmnmf(X, n_iter=args.n_iter, n_components=8, n_src=2,
            callback=cb_print)
    elif bss_type == 'sparseauxiva':
        # Estimate set of active frequency bins
        ratio = 0.35
        average = np.abs(np.mean(np.mean(X, axis=2), axis=0))
        k = np.int_(average.shape[0] * ratio)
        S = np.sort(np.argpartition(average, -k)[-k:])
        # Run SparseAuxIva
        Y = pra.bss.sparseauxiva(X, S, n_iter=30, proj_back=True,
                             callback=cb_print)

    ## STFT Synthesis
    y = pra.transform.synthesis(Y, L, L, zp_back=L//2, zp_front=L//2).T

    ## GUI starts
    print('* Start GUI')
    class PlaySoundGUI(object):
        def __init__(self, master, fs, mix, sources):
            self.master = master
            self.fs = fs
            self.mix = mix
            self.sources = sources
            master.title("A simple GUI")

            self.label = Label(master, text="This is our first GUI!")
github LCAV / pyroomacoustics / examples / bss_live.py View on Github external
# shape == (n_chan, n_frames, n_freq)
    X = pra.transform.analysis(mics_signals.T, L, L, zp_back=L//2, zp_front=L//2)

    ## Monitor convergence
    it = 10
    def cb_print(*args):
        global it
        print('  AuxIVA Iter', it)
        it += 10

    ## Run live BSS
    print('* Starting BSS')
    bss_type = args.algo
    if bss_type == 'auxiva':
        # Run AuxIVA
        Y = pra.bss.auxiva(X, n_iter=args.n_iter, proj_back=True, callback=cb_print)
    elif bss_type == 'ilrma':
        # Run ILRMA
        Y = pra.bss.ilrma(X, n_iter=args.n_iter, n_components=30, proj_back=True,
            callback=cb_print)
    elif bss_type == 'fastmnmf':
        # Run FastMNMF
        Y = pra.bss.fastmnmf(X, n_iter=args.n_iter, n_components=8, n_src=2,
            callback=cb_print)
    elif bss_type == 'sparseauxiva':
        # Estimate set of active frequency bins
        ratio = 0.35
        average = np.abs(np.mean(np.mean(X, axis=2), axis=0))
        k = np.int_(average.shape[0] * ratio)
        S = np.sort(np.argpartition(average, -k)[-k:])
        # Run SparseAuxIva
        Y = pra.bss.sparseauxiva(X, S, n_iter=30, proj_back=True,
github LCAV / pyroomacoustics / examples / bss_example.py View on Github external
t_begin = time.perf_counter()

    ## START BSS
    bss_type = args.algo
    if bss_type == 'auxiva':
        # Run AuxIVA
        Y = pra.bss.auxiva(X, n_iter=30, proj_back=True,
                           callback=convergence_callback)
    elif bss_type == 'ilrma':
        # Run ILRMA
        Y = pra.bss.ilrma(X, n_iter=30, n_components=2, proj_back=True,
                          callback=convergence_callback)
    elif bss_type == 'fastmnmf':
        # Run FastMNMF
        Y = pra.bss.fastmnmf(X, n_iter=100, n_components=8, n_src=2,
                          callback=convergence_callback)
    elif bss_type == 'sparseauxiva':
        # Estimate set of active frequency bins
        ratio = 0.35
        average = np.abs(np.mean(np.mean(X, axis=2), axis=0))
        k = np.int_(average.shape[0] * ratio)
        S = np.sort(np.argpartition(average, -k)[-k:])
        # Run SparseAuxIva
        Y = pra.bss.sparseauxiva(X, S, n_iter=30, proj_back=True,
                                 callback=convergence_callback)

    t_end = time.perf_counter()
    print("Time for BSS: {:.2f} s".format(t_end - t_begin))
    
    ## STFT Synthesis
    y = pra.transform.synthesis(Y, L, hop, win=win_s)
github LCAV / pyroomacoustics / examples / bss_example.py View on Github external
y = y[L-hop: , :].T
        m = np.minimum(y.shape[1], ref.shape[1])
        sdr, sir, sar, perm = bss_eval_sources(ref[:, :m, 0], y[:, :m])
        SDR.append(sdr)
        SIR.append(sir)

    ## STFT ANALYSIS
    X = pra.transform.analysis(mics_signals.T, L, hop, win=win_a)

    t_begin = time.perf_counter()

    ## START BSS
    bss_type = args.algo
    if bss_type == 'auxiva':
        # Run AuxIVA
        Y = pra.bss.auxiva(X, n_iter=30, proj_back=True,
                           callback=convergence_callback)
    elif bss_type == 'ilrma':
        # Run ILRMA
        Y = pra.bss.ilrma(X, n_iter=30, n_components=2, proj_back=True,
                          callback=convergence_callback)
    elif bss_type == 'fastmnmf':
        # Run FastMNMF
        Y = pra.bss.fastmnmf(X, n_iter=100, n_components=8, n_src=2,
                          callback=convergence_callback)
    elif bss_type == 'sparseauxiva':
        # Estimate set of active frequency bins
        ratio = 0.35
        average = np.abs(np.mean(np.mean(X, axis=2), axis=0))
        k = np.int_(average.shape[0] * ratio)
        S = np.sort(np.argpartition(average, -k)[-k:])
        # Run SparseAuxIva
github LCAV / pyroomacoustics / examples / bss_live.py View on Github external
print('  AuxIVA Iter', it)
        it += 10

    ## Run live BSS
    print('* Starting BSS')
    bss_type = args.algo
    if bss_type == 'auxiva':
        # Run AuxIVA
        Y = pra.bss.auxiva(X, n_iter=args.n_iter, proj_back=True, callback=cb_print)
    elif bss_type == 'ilrma':
        # Run ILRMA
        Y = pra.bss.ilrma(X, n_iter=args.n_iter, n_components=30, proj_back=True,
            callback=cb_print)
    elif bss_type == 'fastmnmf':
        # Run FastMNMF
        Y = pra.bss.fastmnmf(X, n_iter=args.n_iter, n_components=8, n_src=2,
            callback=cb_print)
    elif bss_type == 'sparseauxiva':
        # Estimate set of active frequency bins
        ratio = 0.35
        average = np.abs(np.mean(np.mean(X, axis=2), axis=0))
        k = np.int_(average.shape[0] * ratio)
        S = np.sort(np.argpartition(average, -k)[-k:])
        # Run SparseAuxIva
        Y = pra.bss.sparseauxiva(X, S, n_iter=30, proj_back=True,
                             callback=cb_print)

    ## STFT Synthesis
    y = pra.transform.synthesis(Y, L, L, zp_back=L//2, zp_front=L//2).T

    ## GUI starts
    print('* Start GUI')
github LCAV / pyroomacoustics / examples / bss_example.py View on Github external
elif bss_type == 'ilrma':
        # Run ILRMA
        Y = pra.bss.ilrma(X, n_iter=30, n_components=2, proj_back=True,
                          callback=convergence_callback)
    elif bss_type == 'fastmnmf':
        # Run FastMNMF
        Y = pra.bss.fastmnmf(X, n_iter=100, n_components=8, n_src=2,
                          callback=convergence_callback)
    elif bss_type == 'sparseauxiva':
        # Estimate set of active frequency bins
        ratio = 0.35
        average = np.abs(np.mean(np.mean(X, axis=2), axis=0))
        k = np.int_(average.shape[0] * ratio)
        S = np.sort(np.argpartition(average, -k)[-k:])
        # Run SparseAuxIva
        Y = pra.bss.sparseauxiva(X, S, n_iter=30, proj_back=True,
                                 callback=convergence_callback)

    t_end = time.perf_counter()
    print("Time for BSS: {:.2f} s".format(t_end - t_begin))
    
    ## STFT Synthesis
    y = pra.transform.synthesis(Y, L, hop, win=win_s)

    ## Compare SDR and SIR
    y = y[L-hop:, :].T
    m = np.minimum(y.shape[1], ref.shape[1])
    sdr, sir, sar, perm = bss_eval_sources(ref[:, :m, 0], y[:, :m])
    print('SDR:', sdr)
    print('SIR:', sir)

    ## PLOT RESULTS