Skip to content

Commit

Permalink
Reflecting Prerak's review (PR #302).
Browse files Browse the repository at this point in the history
  • Loading branch information
fakufaku committed Oct 27, 2024
1 parent b6d9a6c commit c4c9e27
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 74 deletions.
3 changes: 1 addition & 2 deletions examples/directivities/plot_directivity_3D.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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()
121 changes: 51 additions & 70 deletions examples/directivities/simulation_with_measured_directivity.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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),
)
Expand Down Expand Up @@ -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()

Expand Down
3 changes: 1 addition & 2 deletions pyroomacoustics/acoustics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c4c9e27

Please sign in to comment.