How to use the pyroomacoustics.Room.from_corners 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 LCAV / pyroomacoustics / examples / raytracing.py View on Github external
absor = 0.1
    else:
        raise ValueError("The absorption parameter can only take values ['low', 'medium', 'high']")
    
    if size=='large':
        size_coef = 5.
    elif size=='medium':
        size_coef = 2.5
    elif size=='small':
        size_coef = 1.
    else:
        raise ValueError("The size parameter can only take values ['small', 'medium', 'large']")
        
        
    pol = size_coef * np.array([[0,0], [0,4], [3,2], [3,0]]).T
    room = pra.Room.from_corners(pol, fs=32000, max_order=2, absorption=absor, ray_tracing=True)

    # Create the 3D room by extruding the 2D by a specific height
    room.extrude(size_coef * 2.5, absorption=absor)

    # Adding the source
    room.add_source(size_coef * np.array([1.8, 0.4, 1.6]), signal=audio_anechoic)

    # Adding the microphone
    R = size_coef * np.array([[0.5],[1.2],[0.5]])
    room.add_microphone_array(pra.MicrophoneArray(R, room.fs))

    # Compute the RIR using the hybrid method
    s = time.perf_counter()
    room.image_source_model()
    room.ray_tracing()
    room.compute_rir()
github LCAV / pyroomacoustics / examples / room_L_shape_3d.py View on Github external
one source and two microphones in the room and compute the room impulse
responses.

In this example, we also compare the speed of the C extension module to
that of the pure python code.
'''
from __future__ import print_function

import numpy as np
import matplotlib.pyplot as plt
import time
import pyroomacoustics as pra

# Create the 2D L-shaped room from the floor polygon
pol = 4 * np.array([[0,0], [0,1], [2,1], [2,0.5], [1,0.5], [1,0]]).T
room = pra.Room.from_corners(pol, fs=16000, max_order=12, absorption=0.15)

# Create the 3D room by extruding the 2D by 3 meters
room.extrude(3.)

# Add a source somewhere in the room
room.add_source([1.5, 1.2, 0.5])

# Create a linear array beamformer with 4 microphones
# Place an array of two microphones
R = np.array([[3.,   2.2], 
              [2.25, 2.1], 
              [0.6,  0.55]])
room.add_microphone_array(pra.MicrophoneArray(R, room.fs))

room.image_source_model(use_libroom=True)
github LCAV / pyroomacoustics / examples / room_L_shape_2d.py View on Github external
import matplotlib.pyplot as plt
import time
import pyroomacoustics as pra

room_ll = [-1,-1]
room_ur = [1,1]
src_pos = [0,0]
mic_pos = [0.5, 0.1]

max_order = 10

# Store the corners of the room floor in an array
pol = 3 * np.array([[0,0], [0,1], [2,1], [2,0.5], [1,0.5], [1,0]]).T

# Create the room from its corners
room = pra.Room.from_corners(pol, fs=16000, max_order=max_order, absorption=0.1)

# Add two sources in the room
room.add_source([1.5, 1.2])
room.add_source([5.1, 2.5])

# Place an array of four microphones
R = np.array([[1.1, 1.9, 3., 4.2], [2., 1.9, 2.25, 2.1]])
room.add_microphone_array(pra.MicrophoneArray(R, room.fs))

room.compute_rir()

# plot the room and resulting beamformer
room.plot(img_order=6)

# Display a subset of the room impulse responses
plt.figure()
github LCAV / pyroomacoustics / examples / room_L_shape_3d_rt.py View on Github external
In this example, we also compare the speed of the C extension module to
that of the pure python code.
'''
from __future__ import print_function

import numpy as np
import matplotlib.pyplot as plt
import time
import pyroomacoustics as pra
from scipy.io import wavfile

# Create the 2D L-shaped room from the floor polygon
pol = np.array([[0,0], [0,10], [10,7.5], [7.5,6], [5,6], [5,0]]).T
r_absor = 0.1
room = pra.Room.from_corners(
        pol,
        fs=16000,
        absorption=r_absor,
        materials=pra.Material.make_freq_flat(0.3, 0.2),
        max_order=3,
        ray_tracing=True,
        air_absorption=True,
        )
room.set_ray_tracing(receiver_radius=0.5, energy_thres=1e-5)

# # Create the 3D room by extruding the 2D by 10 meters
height = 10.
room.extrude(height, absorption=r_absor)

# # Add a source somewhere in the room
fs, audio_anechoic = wavfile.read('examples/input_samples/cmu_arctic_us_aew_a0001.wav')