Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_realSH(expected_Ynm):
vecs = spa.grids.load_t_design(2*N)
dirs = spa.utils.vecs2dirs(vecs)
Y_nm = spa.sph.sh_matrix(N, dirs[:, 0], dirs[:, 1], SH_type='real')
assert(np.allclose(Y_nm, expected_Ynm))
def test_tDesign(expected_dirs):
vecs = spa.grids.load_t_design(2*N)
dirs = spa.utils.vecs2dirs(vecs)
assert(np.allclose(dirs, expected_dirs))
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)
# version: 3.6.8
# ---
# %%
import numpy as np
import matplotlib.pyplot as plt
from spaudiopy import utils, IO, sph, plots, grids
# %% Spherical Harmonics Order
N = 1
# %%
# Grids
t = grids.load_t_design(2)
t_az, t_colat, t_r = utils.cart2sph(t[:, 0], t[:, 1], t[:, 2])
azi = t_az
colat = t_colat
# %%
# First, check condition number to which SH order the SHT is stable
# Tetraeder is not suited for SHT N>1:
sph.check_cond_sht(3, t_az, t_colat, 'real')
# %% Real and Complex SHs
Y_nm_c = sph.sh_matrix(N, azi, colat, 'complex')
Y_nm_r = sph.sh_matrix(N, azi, colat, 'real')
# %%
# Look at some SHTs
sig = np.array([1, 1, 1, 1])
if N_kernel is None:
print('Setting Ambisonics order =', self.characteristic_order)
N_kernel = self.characteristic_order
ls = self.points
imaginary_loudspeaker_coordinates = find_imaginary_loudspeaker(self)
# add imaginary speaker to hull
new_ls = np.vstack([ls, imaginary_loudspeaker_coordinates])
# This new triangulation is now the rendering setup
ambisonics_hull = LoudspeakerSetup(new_ls[:, 0],
new_ls[:, 1],
new_ls[:, 2])
# mark imaginary speaker (last one)
ambisonics_hull.imaginary_speaker = new_ls.shape[0] - 1
# virtual optimal loudspeaker arrangement
virtual_speakers = grids.load_t_design(2 * N_kernel + 1)
kernel_hull = LoudspeakerSetup(virtual_speakers[:, 0],
virtual_speakers[:, 1],
virtual_speakers[:, 2])
del ambisonics_hull.ambisonics_hull
del ambisonics_hull.kernel_hull
self.ambisonics_hull = ambisonics_hull
del kernel_hull.ambisonics_hull
del kernel_hull.kernel_hull
self.kernel_hull = kernel_hull
# 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)
# %% Look at some performance measures
plots.decoder_performance(ls_setup, 'NLS')
plots.decoder_performance(ls_setup, 'VBAP')
plots.decoder_performance(ls_setup, 'VBAP', retain_outside=True)
plt.suptitle('VBAP with imaginary loudspeaker')
plots.decoder_performance(ls_setup, 'VBIP', retain_outside=True)
plt.suptitle('VBIP with imaginary loudspeaker')
plots.decoder_performance(ls_setup, 'ALLRAP')
plots.decoder_performance(ls_setup, 'ALLRAP2')
# %% Binauralize