From c4c9e2731afa4625101d6a68d310c63e874d4583 Mon Sep 17 00:00:00 2001 From: Robin Scheibler Date: Sun, 27 Oct 2024 23:39:15 +0900 Subject: [PATCH] Reflecting Prerak's review (PR #302). --- examples/directivities/plot_directivity_3D.py | 3 +- .../simulation_with_measured_directivity.py | 121 ++++++++---------- pyroomacoustics/acoustics.py | 3 +- 3 files changed, 53 insertions(+), 74 deletions(-) diff --git a/examples/directivities/plot_directivity_3D.py b/examples/directivities/plot_directivity_3D.py index 5086222a..8d3e3688 100644 --- a/examples/directivities/plot_directivity_3D.py +++ b/examples/directivities/plot_directivity_3D.py @@ -1,6 +1,5 @@ import matplotlib.pyplot as plt import numpy as np - from pyroomacoustics.directivities import DirectionVector, HyperCardioid orientation = DirectionVector(azimuth=0, colatitude=45, degrees=True) @@ -10,7 +9,7 @@ # plot azimuth = np.linspace(start=0, stop=360, num=361, endpoint=True) -colatitude = np.linspace(start=0, stop=180, num=180, endpoint=True) +colatitude = np.linspace(start=0, stop=180, num=181, endpoint=True) # colatitude = None # for 2D plot dir_obj.plot_response(azimuth=azimuth, colatitude=colatitude, degrees=True) plt.show() diff --git a/examples/directivities/simulation_with_measured_directivity.py b/examples/directivities/simulation_with_measured_directivity.py index 523f934f..55d4d416 100644 --- a/examples/directivities/simulation_with_measured_directivity.py +++ b/examples/directivities/simulation_with_measured_directivity.py @@ -1,74 +1,55 @@ +# 2022 (c) Prerak SRIVASTAVA +# 2024/11/27 Modified by Robin Scheibler """ -Simulating RIRs with measured directivity pattern from DIRPAT +Simulating RIRs with measured directivity patterns from DIRPAT ============================================================== -In this example, we show how we can apply and use class DIRPATRir to open measured -directivity files from the DIRPAT dataset. - -The created objects can be directly used to generate RIRs - -With DIRPATRir object we can generate RIRs with mics and source having either -frequency independent CARDIOID patterns or -freqeuncy dependent patterns from DIRPAT dataset. - -Parameters --------------------------------------- - orientation : - class DirectionVector - path : (string) - Path towards the DIRPAT sofa file, the ending name of the file should be the same as specified in the DIRPAT dataset - - DIRPAT_pattern_enum : (string) - Only used to choose the directivity patterns available in the specific files in the DIRPAT dataset - - # AKG_c480_c414_CUBE.sofa DIRPAT file include mic patterns for CARDIOID ,FIGURE_EIGHT,HYPERCARDIOID ,OMNI,SUBCARDIOID - a)AKG_c480 - b)AKG_c414K - c)AKG_c414N - d)AKG_c414S - e)AKG_c414A - - Eigenmic directivity pattern file "EM32_Directivity.sofa", specify mic name at the end to retrive directivity pattern for that particular mic from the eigenmike - a)EM_32_* : where * \in [0,31] - For example EM_32_9 : Will retrive pattern of mic number "10" from the eigenmic. - - # LSPs_HATS_GuitarCabinets_Akustikmessplatz.sofa DIRPAT file include source patterns - a)Genelec_8020 - b)Lambda_labs_CX-1A - c)HATS_4128C - d)Tannoy_System_1200 - e)Neumann_KH120A - f)Yamaha_DXR8 - g)BM_1x12inch_driver_closed_cabinet - h)BM_1x12inch_driver_open_cabinet - i)BM_open_stacked_on_closed_withCrossoverNetwork - j)BM_open_stacked_on_closed_fullrange - k)Palmer_1x12inch - l)Vibrolux_2x10inch - - fs : (int) - Sampling frequency of the filters for interpolation. - Should be same as the simulator frequency and less than 44100 kHz - no_points_on_fibo_sphere : (int) - Number of points on the interpolated Fibonacci sphere. - if "0" no interpolation will happen. - - -This implementation shows how we can use both DIRPAT object and frequency independent directivity class CardioidFamily together. -We can also use the objects separately. - -~ Prerak SRIVASTAVA, 8/11/2022 +In this example, we show how we can use measured directivity patterns +from the DIRPAT dataset in a simulation. + +The procedure to use the directivity patterns is as follows. + +1. Read the files potentially containing multiple measurements. +2. Get a directivity object from the file object with desired orientation. + The directivities can be accessed by index or label (if existing). + The same pattern can be used multiple times with different orientations. +3. Provide the directivity pattern object to the microphone object. + +The DIRPAT database has three different files. + +The ``AKG_c480_c414_CUBE.sofa`` DIRPAT file include mic patterns for CARDIOID, +FIGURE_EIGHT, HYPERCARDIOID, OMNI, SUBCARDIOID. + +a)AKG_c480 +b)AKG_c414K +c)AKG_c414N +d)AKG_c414S +e)AKG_c414A + +The Eigenmic directivity pattern file ``EM32_Directivity.sofa``, specify mic +name at the end to retrive directivity pattern for that particular mic from the +eigenmike. This file contains 32 patterns of the form ``EM_32_*``, where ``*`` +is one of 0, 1, ..., 31. For example, ``EM_32_9`` will retrive pattern of mic +number "10" from the eigenmic. + +The ``LSPs_HATS_GuitarCabinets_Akustikmessplatz.sofa`` DIRPAT file includes +some source patterns. + +a) Genelec_8020 +b) Lambda_labs_CX-1A +c) HATS_4128C +d) Tannoy_System_1200 +e) Neumann_KH120A +f) Yamaha_DXR8 +g) BM_1x12inch_driver_closed_cabinet +h) BM_1x12inch_driver_open_cabinet +i) BM_open_stacked_on_closed_withCrossoverNetwork +j) BM_open_stacked_on_closed_fullrange +k) Palmer_1x12inch +l) Vibrolux_2x10inch """ -import os - import matplotlib.pyplot as plt -import numpy as np -from scipy import signal -from scipy.fft import fft, fftfreq -from scipy.io import wavfile -from scipy.signal import fftconvolve - import pyroomacoustics as pra from pyroomacoustics.directivities import ( Cardioid, @@ -78,19 +59,22 @@ class DirectionVector Rotation3D, ) +# Reads the file containing the Eigenmike's directivity measurements eigenmike = MeasuredDirectivityFile("EM32_Directivity", fs=16000) +# Reads the file containing the directivity measurements of another microphones akg = MeasuredDirectivityFile("AKG_c480_c414_CUBE", fs=16000) +# Create a rotation object to orient the microphones. rot_54_73 = Rotation3D([73, 54], "yz", degrees=True) +# Get the directivity objects from the two files dir_obj_Dmic = akg.get_mic_directivity("AKG_c414K", orientation=rot_54_73) dir_obj_Emic = eigenmike.get_mic_directivity("EM_32_9", orientation=rot_54_73) +# Create two analytical directivities for comparison dir_obj_Cmic = FigureEight( orientation=DirectionVector(azimuth=90, colatitude=123, degrees=True), ) - - dir_obj_Csrc = Cardioid( orientation=DirectionVector(azimuth=56, colatitude=123, degrees=True), ) @@ -177,9 +161,6 @@ class DirectionVector break ax = fig.add_subplot(5, 10, idx + 1, projection="3d") dir_mic.plot(freq_bin=fb, ax=ax, depth=True) - # ax.set_xticks([]) - # ax.set_yticks([]) - # ax.set_zticks([]) ax.set_title(idx) plt.show() diff --git a/pyroomacoustics/acoustics.py b/pyroomacoustics/acoustics.py index 7a5b36ab..26bc176f 100644 --- a/pyroomacoustics/acoustics.py +++ b/pyroomacoustics/acoustics.py @@ -29,10 +29,9 @@ import math import numpy as np -from scipy import signal from scipy.fftpack import dct from scipy.interpolate import interp1d -from scipy.signal import butter, fftconvolve, hilbert, sosfiltfilt +from scipy.signal import butter, fftconvolve from .parameters import constants from .transform import stft