Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from unittest import TestCase
import numpy as np
import pyroomacoustics as pra
room = pra.Room.shoeBox2D([0,0],[4,4],0)
s1 = [[0, 4], [2, 2]]
s2 = [[2, 2], [0, 4]]
s3 = [[4, 4], [0, 4]]
s4 = [[4, 4], [0, 4]]
s5 = [[0, 2], [2, 2]]
print('===ORIENTATION===')
print('orientation : ',room.ccw3p(np.array([[6, 4, 2], [0, 2, 0]])))
print('===ORIENTATION===')
print('orientation : ',room.ccw3p(np.array([[2, 4, 6], [0, 2, 0]])))
print('===INTERSECTION (0)===')
print('intersects : ',room.intersects(np.array(s4), np.array(s5)))
print('===INTERSECTION (1)===')
the_mesh = mesh.Mesh.from_file(args.file)
ntriang, nvec, npts = the_mesh.vectors.shape
size_reduc_factor = 500. # to get a realistic room size (not 3km)
# create one wall per triangle
walls = []
for w in range(ntriang):
walls.append(
pra.wall_factory(
the_mesh.vectors[w].T / size_reduc_factor,
material.absorption["coeffs"],
material.scattering["coeffs"],
)
)
room = pra.Room(
walls,
fs=16000,
max_order=3,
ray_tracing=True,
air_absorption=True,
)
# Set options for the ray tracer
room.set_ray_tracing(n_rays=30000, receiver_radius=0.5)
room.add_source([-2.0, 2.0, 1.8])
room.add_microphone_array(
pra.MicrophoneArray(
np.array([[-6.5, 8.5, 3+0.1], [-6.5, 8.1, 3+0.1]]).T, room.fs)
)
# compute the rir
t0 = 1./(fs*np.pi*1e-2)
absorption = 0.80
max_order_sim = 30
sigma2_n = 5e-7
room_dim = [5, 4, 6]
shoebox = pra.ShoeBox(
room_dim,
absorption=absorption,
fs=fs,
t0=t0,
max_order=max_order_sim,
sigma2_awgn=sigma2_n
)
room = pra.Room(
shoebox.walls,
fs=fs,
t0=t0,
max_order=max_order_sim,
sigma2_awgn=sigma2_n
)
source_loc = [2, 3.5, 2]
mic_loc = np.array([[2, 1.5, 2]]).T
shoebox.addSource(source_loc)
room.addSource(source_loc)
room.addMicrophoneArray(pra.MicrophoneArray(mic_loc, fs))
shoebox.addMicrophoneArray(pra.MicrophoneArray(mic_loc, fs))
then = time.time()
Some information about the images is returned (including visibility at a certain point)
"""
# Simulation parameters
fs = 8000
t0 = 1./(fs*np.pi*1e-2)
absorption = 0.90
max_order_sim = 3
sigma2_n = 5e-7
pVis = [1,1] # this point is where we check visibility (warning : put 3 coordinates for 3D)
# Create the rooms
rooms = []
rooms.append(pra.Room.fromCorners(np.array([[0,5,5,3,3,2,2,0], [0,0,5,5,2,2,5,5]]),absorption,fs,t0,max_order_sim,sigma2_n))
rooms.append(pra.Room.shoeBox2D([0,0],[4, 4],absorption,fs,t0,max_order_sim,sigma2_n))
rooms.append(pra.Room.shoeBox3D([0,0,0],[6, 6, 6],absorption,fs,t0,max_order_sim,sigma2_n))
# Select an id corresponding to the room we want to show
# 0 = 2D "U room"
# 1 = 2D shoe box
# 2 = 3D shoe box
roomId = 1 # change this id to select a different room
room = rooms[roomId]
# Add a source to the room
sourcePos = [2,1] # position of the sound source (warning : put 3 coordinates for 3D)
room.addSource(sourcePos, None, 0)
# Simulation parameters
fs = 8000
t0 = 1./(fs*np.pi*1e-2)
absorption = 0.90
max_order_sim = 3
sigma2_n = 5e-7
pVis = [1,1] # this point is where we check visibility (warning : put 3 coordinates for 3D)
# Create the rooms
rooms = []
rooms.append(pra.Room.fromCorners(np.array([[0,5,5,3,3,2,2,0], [0,0,5,5,2,2,5,5]]),absorption,fs,t0,max_order_sim,sigma2_n))
rooms.append(pra.Room.shoeBox2D([0,0],[4, 4],absorption,fs,t0,max_order_sim,sigma2_n))
rooms.append(pra.Room.shoeBox3D([0,0,0],[6, 6, 6],absorption,fs,t0,max_order_sim,sigma2_n))
# Select an id corresponding to the room we want to show
# 0 = 2D "U room"
# 1 = 2D shoe box
# 2 = 3D shoe box
roomId = 1 # change this id to select a different room
room = rooms[roomId]
# Add a source to the room
sourcePos = [2,1] # position of the sound source (warning : put 3 coordinates for 3D)
room.addSource(sourcePos, None, 0)
# Plotting the result