How to use the spaudiopy.decoder function in spaudiopy

To help you get started, we’ve selected a few spaudiopy 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 chris-hld / spaudiopy / tests / test_parallel.py View on Github external
def test_vbap(test_jobs):
    vecs = spa.grids.load_t_design(degree=5)
    hull = spa.decoder.LoudspeakerSetup(*vecs.T)
    src = np.random.randn(1000, 3)
    gains_r = spa.decoder.vbap(src, hull, jobs_count=1)
    gains_t = spa.decoder.vbap(src, hull, jobs_count=test_jobs)
    assert_allclose(gains_t, gains_r)
github chris-hld / spaudiopy / tests / test_parallel.py View on Github external
def test_allrap2(test_jobs):
    vecs = spa.grids.load_t_design(degree=5)
    hull = spa.decoder.LoudspeakerSetup(*vecs.T)
    hull.ambisonics_setup(update_hull=False)
    src = np.random.randn(1000, 3)
    gains_r = spa.decoder.allrap2(src, hull, jobs_count=1)
    gains_t = spa.decoder.allrap2(src, hull, jobs_count=test_jobs)
    assert_allclose(gains_t, gains_r)
github chris-hld / spaudiopy / examples / Loudspeaker_decoder.py View on Github external
listener_position = [0, 0, 0]


if setupname == "frontal_partial":
    ls_dirs = np.array([[-80, -45, 0, 45, 80, -60, -30, 30, 60],
                        [0, 0, 0, 0, 0, 60, 60, 60, 60]])
    ls_dirs[1, :] = 90 - ls_dirs[1, :]
    ls_x, ls_y, ls_z = utils.sph2cart(utils.deg2rad(ls_dirs[0, :]),
                                      utils.deg2rad(ls_dirs[1, :]))

    normal_limit = 85
    aperture_limit = 90
    opening_limit = 150
    blacklist = None

    ls_setup = decoder.LoudspeakerSetup(ls_x, ls_y, ls_z, listener_position)
    ls_setup.pop_triangles(normal_limit, aperture_limit, opening_limit,
                           blacklist)

elif setupname == "graz":
    normal_limit = 85
    aperture_limit = 90
    opening_limit = 135
    blacklist = None
    ls_setup = IO.load_layout("../data/ls_layouts/Graz.json",
                              listener_position=listener_position)
    ls_setup.pop_triangles(normal_limit, aperture_limit, opening_limit,
                           blacklist)

else:
    raise ValueError
github chris-hld / spaudiopy / examples / SDM.py View on Github external
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import numpy as np

from spaudiopy import IO, sig, sdm, plots, utils, decoder

LISTEN = True

# 5.0+4 Setup
ls_dirs = np.array([[0, -30, 30, 110, -110, -30, 30, 110, -110],
                    [0, 0, 0, 0, 0, 45, 45, 45, 45]])
ls_x, ls_y, ls_z = utils.sph2cart(utils.deg2rad(ls_dirs[0, :]),
                                  utils.deg2rad(90 - ls_dirs[1, :]))

ls_setup = decoder.LoudspeakerSetup(ls_x, ls_y, ls_z)
ls_setup.show()

# Load SH impulse response
ambi_ir = sig.MultiSignal.from_file('../data/IR_Gewandhaus_SH1.wav')
# convert to B-format
ambi_ir = sig.AmbiBSignal.sh_to_b(ambi_ir)

fs = ambi_ir.fs

# - SDM Encoding:
sdm_p = ambi_ir.W
sdm_azi, sdm_colat, _ = sdm.pseudo_intensity(ambi_ir, f_bp=(100, 5000))

# Show first 10000 samples DOA
plots.doa(sdm_azi[:10000], sdm_colat[:10000], fs, p=sdm_p[:10000])
github chris-hld / spaudiopy / spaudiopy / IO.py View on Github external
warn('Additional gain handling not implemented.')
    except KeyError as e:
        warn('KeyError : {}, will return empty!'.format(e))
        gain = []
    try:
        isImaginary = np.array([ls['IsImaginary'] for ls in ls_data])
    except KeyError as e:
        warn('KeyError : {}, will return all False!'.format(e))
        isImaginary = np.full_like(azi, False, dtype=bool)

    # first extract real loudspeakers
    ls_x, ls_y, ls_z = utils.sph2cart(utils.deg2rad(azi[~isImaginary]),
                                      utils.deg2rad(90-ele[~isImaginary]),
                                      r[~isImaginary])

    ls_layout = decoder.LoudspeakerSetup(ls_x, ls_y, ls_z,
                                         listener_position=listener_position)
    # then add imaginary loudspeakers to ambisonics setup
    imag_x, imag_y, imag_z = utils.sph2cart(utils.deg2rad(azi[isImaginary]),
                                            utils.deg2rad(90-ele[isImaginary]),
                                            r[isImaginary])
    imag_pos = np.c_[imag_x, imag_y, imag_z]
    ls_layout.ambisonics_setup(N_kernel=N_kernel, update_hull=True,
                               imaginary_ls=imag_pos)
    return ls_layout
github chris-hld / spaudiopy / spaudiopy / plots.py View on Github external
For renderer_type='VBAP', 'VBIP', 'ALLRAP' or 'NLS', kwargs forwarded.

    Zotter, F., & Frank, M. (2019). Ambisonics.
    Springer Topics in Signal Processing.
    """
    azi_steps = np.deg2rad(azi_steps)
    ele_steps = np.deg2rad(ele_steps)
    phi_vec = np.arange(-np.pi, np.pi + 2*azi_steps, azi_steps)
    theta_vec = np.arange(0., np.pi + 2*ele_steps, ele_steps)
    phi_plot, theta_plot = np.meshgrid(phi_vec, theta_vec)
    _grid_x, _grid_y, grid_z = utils.sph2cart(phi_plot.ravel(),
                                              theta_plot.ravel())

    # Switch renderer
    if renderer_type.lower() == 'vbap':
        G = decoder.vbap(np.c_[_grid_x, _grid_y, grid_z], hull, **kwargs)
    elif renderer_type.lower() == 'vbip':
        G = decoder.vbip(np.c_[_grid_x, _grid_y, grid_z], hull, **kwargs)
    elif renderer_type.lower() == 'allrap':
        G = decoder.allrap(np.c_[_grid_x, _grid_y, grid_z], hull,
                           **kwargs)
    elif renderer_type.lower() == 'allrap2':
        G = decoder.allrap2(np.c_[_grid_x, _grid_y, grid_z], hull,
                            **kwargs)
    elif renderer_type.lower() == 'nls':
        G = decoder.nearest_loudspeaker(np.c_[_grid_x, _grid_y, grid_z], hull,
                                        **kwargs)
    else:
        raise ValueError('Unknown renderer_type')

    # Measures
    E = np.sum(G**2, axis=1)  # * (4 * np.pi / G.shape[1])  # (eq. 15)
github chris-hld / spaudiopy / spaudiopy / plots.py View on Github external
Zotter, F., & Frank, M. (2019). Ambisonics.
    Springer Topics in Signal Processing.
    """
    azi_steps = np.deg2rad(azi_steps)
    ele_steps = np.deg2rad(ele_steps)
    phi_vec = np.arange(-np.pi, np.pi + 2*azi_steps, azi_steps)
    theta_vec = np.arange(0., np.pi + 2*ele_steps, ele_steps)
    phi_plot, theta_plot = np.meshgrid(phi_vec, theta_vec)
    _grid_x, _grid_y, grid_z = utils.sph2cart(phi_plot.ravel(),
                                              theta_plot.ravel())

    # Switch renderer
    if renderer_type.lower() == 'vbap':
        G = decoder.vbap(np.c_[_grid_x, _grid_y, grid_z], hull, **kwargs)
    elif renderer_type.lower() == 'vbip':
        G = decoder.vbip(np.c_[_grid_x, _grid_y, grid_z], hull, **kwargs)
    elif renderer_type.lower() == 'allrap':
        G = decoder.allrap(np.c_[_grid_x, _grid_y, grid_z], hull,
                           **kwargs)
    elif renderer_type.lower() == 'allrap2':
        G = decoder.allrap2(np.c_[_grid_x, _grid_y, grid_z], hull,
                            **kwargs)
    elif renderer_type.lower() == 'nls':
        G = decoder.nearest_loudspeaker(np.c_[_grid_x, _grid_y, grid_z], hull,
                                        **kwargs)
    else:
        raise ValueError('Unknown renderer_type')

    # Measures
    E = np.sum(G**2, axis=1)  # * (4 * np.pi / G.shape[1])  # (eq. 15)
    # project points onto unit sphere
    ls_points = hull.points / hull.d[:, np.newaxis]
github chris-hld / spaudiopy / examples / SDM.py View on Github external
# - SDM Encoding:
sdm_p = ambi_ir.W
sdm_azi, sdm_colat, _ = sdm.pseudo_intensity(ambi_ir, f_bp=(100, 5000))

# Show first 10000 samples DOA
plots.doa(sdm_azi[:10000], sdm_colat[:10000], fs, p=sdm_p[:10000])


# - SDM Decoding:
# very quick stereo SDM decoding. This is only for testing!
ir_st_l, ir_st_r = sdm.render_stereo_sdm(sdm_p, sdm_azi, sdm_colat)

# Loudspeaker decoding
s_pos = np.array(utils.sph2cart(sdm_azi, sdm_colat)).T
ls_gains = decoder.nearest_loudspeaker(s_pos, ls_setup)
assert len(ls_gains) == len(sdm_p)
ir_ls_l, ir_ls_r = sdm.render_binaural_loudspeaker_sdm(sdm_p, ls_gains,
                                                       ls_setup, fs)

# Render some examples
s_in = sig.MonoSignal.from_file('../data/piano_mono.flac', fs)
s_in.trim(2.6, 6)

# Convolve with the omnidirectional IR
s_out_p = s_in.copy()
s_out_p.conv(sdm_p)

# Convolve with the stereo SDM IR
s_out_SDM_stereo = sig.MultiSignal([s_in.signal, s_in.signal], fs=fs)
s_out_SDM_stereo.conv([ir_st_l, ir_st_r])
github chris-hld / spaudiopy / examples / Loudspeaker_decoder.py View on Github external
# %% Ambisonic decoding
# Ambisonic setup
N_e = ls_setup.get_characteristic_order()
ls_setup.ambisonics_setup(update_hull=True, N_kernel=20)

# Show ALLRAP hulls
plots.hull(ls_setup.ambisonics_hull, title='Ambisonic hull')
plots.hull(ls_setup.kernel_hull, mark_invalid=False, title='Kernel hull')

# ALLRAP
gains_allrap = decoder.allrap(src, ls_setup, N_sph=N_e)
# ALLRAP2
gains_allrap2 = decoder.allrap2(src, ls_setup, N_sph=N_e)
# ALLRAD
input_F_nm = sph.sh_matrix(N_e, src_azi, src_colat, 'real').T  # SH dirac
out_allrad = decoder.allrad(input_F_nm, ls_setup, N_sph=N_e)
out_allrad2 = decoder.allrad2(input_F_nm, ls_setup, N_sph=N_e)


utils.test_diff(gains_allrap, out_allrad, msg="ALLRAD and ALLRAP:")
utils.test_diff(gains_allrap2, out_allrad2, msg="ALLRAD2 and ALLRAP2:")

# Nearest Loudspeaker
gains_nls = decoder.nearest_loudspeaker(src, ls_setup)

# %% test multiple sources
_grid, _weights = grids.load_Fliege_Maier_nodes(10)
G_vbap = decoder.vbap(_grid, ls_setup)
G_allrap = decoder.allrap(_grid, ls_setup)
G_allrap2 = decoder.allrap2(_grid, ls_setup)
G_vbip = decoder.vbip(_grid, ls_setup)