Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from spaudiopy import utils, IO, sig, decoder, sph, plots, grids
# %% User setup
setupname = "graz"
LISTEN = True
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",
def check_normals(hull, normal_limit=85, listener_position=None):
"""Return valid simplices that point towards listener."""
if listener_position is None:
listener_position = hull.listener_position
valid_simplices = []
for face, v_n, c in zip(hull.simplices, hull.face_normals,
hull.centroids):
if hull.is_simplex_valid(face):
if utils.angle_between(c, v_n, vi=listener_position) > \
utils.deg2rad(normal_limit):
print("Face not pointing towards listener: " + str(face))
else:
valid_simplices.append(face)
return np.array(valid_simplices)
#!/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))
try:
# not actually used, yet
gain = np.array([ls['Gain'] for ls in ls_data])
if np.any(gain != 1.):
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
def check_opening(hull, opening_limit=135):
"""Return valid simplices with all opening angles within simplex > limit.
"""
valid_simplices = []
for face in hull.valid_simplices:
# extract vertices face
v = hull.points[face, :]
a = utils.angle_between(v[1, :], v[2, :], vi=v[0, :])
b = utils.angle_between(v[0, :], v[2, :], vi=v[1, :])
c = utils.angle_between(v[0, :], v[1, :], vi=v[2, :])
if np.any(np.r_[a, b, c] > utils.deg2rad(opening_limit)):
print("Found large opening angle in face: " + str(face))
else:
valid_simplices.append(face)
return np.array(valid_simplices)
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
def check_aperture(hull, aperture_limit=90, listener_position=None):
"""Return valid simplices, where the aperture form the listener is small.
"""
if listener_position is None:
listener_position = hull.listener_position
valid_simplices = []
for face in hull.valid_simplices:
# extract vertices face
v = hull.points[face, :]
a = utils.angle_between(v[0, :], v[1, :], vi=listener_position)
b = utils.angle_between(v[1, :], v[2, :], vi=listener_position)
c = utils.angle_between(v[0, :], v[2, :], vi=listener_position)
if np.any(np.r_[a, b, c] > utils.deg2rad(aperture_limit)):
print("Face produces critically large aperture: " + str(face))
else:
valid_simplices.append(face)
return np.array(valid_simplices)
# not actually used, yet
gain = np.array([ls['Gain'] for ls in ls_data])
if np.any(gain != 1.):
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