Skip to content

Commit 38871cc

Browse files
fakufakuprerak23prerak23
authored
Support for recorded source/mic directivities from DIRPAT database (#259) (#302)
* Support for measured source/mic directivities from DIRPAT database and other SOFA format files (#259) * This is a pretty big commit that includes loading recorded directivity files and using them in the simulation * Supports source/receiver for shoebox rooms * Interpolation in spherical harmonic domain * Adds option for using minimum phase filters See the CHANGELOG for more details. --------- Co-authored-by: prerak23 <[email protected]> * Adds download functions for the SOFA files from DIRPAT. Adds tests for the SOFA directivities. Adds samples some pre-generated samples for the tests. Removes some print statements from room.py. * open_sofa_interpolate.py: vectorizes fibonnaci computations, use spherical/cartesian conversion functions from doa sub-package. Adds a generalized pinv computation function. Adds a new plotting function. Moves doa sub-package fibonacci mapping to a dedicated function to make it available everywhere. * Adds two SOFA files for MIT Kemar HRTF. Adds an example script for binaural simulation * Modularize the RIR building routines for ISM and RT * adds soxr to requirements for doc building * Disallow directivities for 2D rooms. --------- Co-authored-by: prerak23 <[email protected]> Co-authored-by: prerak23 <[email protected]>
1 parent 890fc37 commit 38871cc

File tree

107 files changed

+4958
-797
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+4958
-797
lines changed

.github/workflows/pythonpackage.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,17 @@ jobs:
3535
uses: actions/setup-python@v4
3636
with:
3737
python-version: ${{ matrix.python-version }}
38-
- name: Install dependencies
38+
- name: Upgrade pip
3939
run: |
4040
python -m pip install --upgrade pip
41+
- name: Workaround for windows and python 3.8
42+
if: matrix.os == 'windows-2019' && matrix.python-version == 3.8
43+
run: |
44+
pip install netCDF4<=1.5.8
45+
# There is no binary package of netCF4>=1.6.0 for windows and python 3.7
46+
# the largest supported version is 1.5.8
47+
- name: Install dependencies
48+
run: |
4149
pip install -r requirements.txt
4250
- name: Build package
4351
run: |

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ local_examples/
1515
pyroomacoustics.egg-info/
1616
pyroomacoustics/build_rir.c
1717
pyroomacoustics/**/*.so
18+
pyroomacoustics/directivities/tests/data/*.pdf

CHANGELOG.rst

+49-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,55 @@ adheres to `Semantic Versioning <http://semver.org/spec/v2.0.0.html>`_.
1111
`Unreleased`_
1212
-------------
1313

14-
Nothing yet
14+
This new version introduces some major changes. In particular, it introduces
15+
the use of measured microphone and source directivities. This new feature
16+
allows to simulate more accurately real recording equipments. See the
17+
`documentation
18+
<https://pyroomacoustics.readthedocs.io/en/latest/pyroomacoustics.directivities.html>`_
19+
for more details.
20+
21+
Added
22+
~~~~~
23+
24+
- New global parameters to control the octave bands used for simulation.
25+
26+
- ``octave_bands_base_freq``: the base frequency used for the octave bands (default ``125``),
27+
note that together with the sampling frequency this will determine the number of sub-bands
28+
used in simulation.
29+
- ``octave_bands_n_fft``: lengths of the octave band filters (current is default ``512``
30+
but will be changed to ``128`` in the next release)
31+
- ``octave_bands_keep_dc``: extends the lowest band to include the DC offset,
32+
the current default is ``False`` to match past behavior, but will be changed to
33+
``True`` in the next release because the filters have less oscillations this way.
34+
35+
- New parameter ``min_phase`` of class ``Room``. If set to ``True``, the band-pass
36+
filters are designed as minimum phase filters.
37+
38+
- Simulation with measured directivity responses in SOFA format (limited file types) is
39+
possible with the image source model.
40+
41+
- A flexible and extensible SOFA file reader with optional spherical interpolation.
42+
- A small database of files is bundled, including the `DIRPAT database
43+
<https://aes2.org/publications/elibrary-page/?id=19538>`_, collected by
44+
Manuel Brandner, Matthias Frank, and Daniel Rudrich University of Music and
45+
Performing Arts Graz, Graz. The file also include two HRTF of the
46+
`MIT KEMAR dummy head <https://sound.media.mit.edu/resources/KEMAR/README>`_.
47+
48+
- Introduces a new class ``pyroomacoustics.directivities.Rotation3D`` to specify
49+
the orientation of sources and receivers in 3D.
50+
51+
- Adds `soxr <https://github.com/dofuuz/python-soxr>`_ as a dependency since resampling
52+
can often be necessary when working with SOFA files.
53+
54+
Changed
55+
~~~~~~~
56+
57+
- In ray tracing, the histograms are now linearly interpolated between
58+
the bins to obtain smoother RIR
59+
- Changed the API of ``CardioidFamily`` to take a float parameter.
60+
New class wrappers for ``Cardioid``, ``Hypercardioid``, ``Supercardioid``,
61+
``Bidirectional`` and ``Omnidirectional`` are added in the ``directivity``
62+
sub-module. The enum of type ``DirectivityPattern`` has been removed.
1563

1664
`0.7.7`_ - 2024-09-09
1765
---------------------

MANIFEST.in

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Acoustic data for the simulation
22
include pyroomacoustics/data/materials.json
3+
include pyroomacoustics/data/sofa_files.json
4+
include pyroomacoustics/data/sofa/AKG_c480_c414_CUBE.sofa
5+
include pyroomacoustics/data/sofa/EM32_Directivity.sofa
6+
include pyroomacoustics/data/sofa/mit_kemar_large_pinna.sofa
7+
include pyroomacoustics/data/sofa/mit_kemar_normal_pinna.sofa
38

49
# The header files for the compiled extension
510
include pyroomacoustics/libroom_src/*.h
@@ -19,9 +24,12 @@ graft pyroomacoustics/tests
1924
graft pyroomacoustics/adaptive/tests
2025
graft pyroomacoustics/bss/tests
2126
graft pyroomacoustics/datasets/tests
27+
graft pyroomacoustics/denoise/tests
28+
graft pyroomacoustics/directivities/tests
2229
graft pyroomacoustics/doa/tests
2330
graft pyroomacoustics/experimental/tests
2431
graft pyroomacoustics/libroom_src/tests
32+
graft pyroomacoustics/phase/tests
2533
graft pyroomacoustics/transform/tests
2634

2735
global-exclude *.py[co]

docs/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"mpl_toolkits.mplot3d",
5353
"joblib",
5454
"scipy.io",
55+
"soxr",
5556
]
5657

5758
try:

docs/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Table of contents
1414
contributing
1515
changelog
1616
pyroomacoustics.room
17+
pyroomacoustics.directivities
1718
pyroomacoustics.materials.database
1819
pyroomacoustics.transform
1920
pyroomacoustics.datasets

docs/modules.rst

-7
This file was deleted.

docs/pyroomacoustics.datasets.rst

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Datasets Available
1616

1717
pyroomacoustics.datasets.cmu_arctic
1818
pyroomacoustics.datasets.google_speech_commands
19+
pyroomacoustics.datasets.sofa
1920
pyroomacoustics.datasets.timit
2021

2122
Tools and Helpers
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SOFA Database
2+
=============
3+
4+
.. automodule:: pyroomacoustics.datasets.sofa
5+
:members:
+70-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,75 @@
1-
pyroomacoustics.directivities module
2-
====================================
1+
Directional Sources and Microphones
2+
===================================
33

44
.. automodule:: pyroomacoustics.directivities
55
:members:
66
:undoc-members:
77
:show-inheritance:
8+
9+
Analytic Directional Responses
10+
------------------------------
11+
12+
.. automodule:: pyroomacoustics.directivities.analytic
13+
:members:
14+
:undoc-members:
15+
:show-inheritance:
16+
17+
Measured Directivities
18+
----------------------
19+
20+
.. automodule:: pyroomacoustics.directivities.measured
21+
:members:
22+
:undoc-members:
23+
:show-inheritance:
24+
25+
Built-in SOFA Files Database
26+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27+
28+
.. automodule:: pyroomacoustics.datasets.sofa
29+
:members: SOFADatabase, get_sofa_db
30+
:noindex:
31+
32+
33+
Reading Other or Custom File Types
34+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35+
36+
It is possible to read other file types by providing a custom reader function to
37+
:py:class:`~pyroomacoustics.directivities.measured.MeasuredDirectivityFile` with the
38+
argument ``file_reader_callback``.
39+
The function should have the same signature as :py:func:`~pyroomacoustics.directivities.sofa.open_sofa_file`.
40+
41+
42+
SOFA File Readers
43+
.................
44+
45+
.. automodule:: pyroomacoustics.directivities.sofa
46+
:members:
47+
:show-inheritance:
48+
49+
Direction of the Patterns
50+
-------------------------
51+
52+
.. automodule:: pyroomacoustics.directivities.direction
53+
:members:
54+
:show-inheritance:
55+
56+
57+
Creating New Types of Directivities
58+
-----------------------------------
59+
60+
.. automodule:: pyroomacoustics.directivities.base
61+
:members:
62+
:undoc-members:
63+
:show-inheritance:
64+
65+
Spherical Interpolation
66+
-----------------------
67+
68+
.. automodule:: pyroomacoustics.directivities.interp
69+
:members: spherical_interpolation
70+
71+
Numerical Spherical Integral
72+
----------------------------
73+
74+
.. automodule:: pyroomacoustics.directivities.integration
75+
:members: spherical_integral

docs/pyroomacoustics.libroom.rst

-7
This file was deleted.

docs/pyroomacoustics.rst

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Submodules
2929
pyroomacoustics.parameters
3030
pyroomacoustics.recognition
3131
pyroomacoustics.room
32+
pyroomacoustics.simulation
3233
pyroomacoustics.soundsource
3334
pyroomacoustics.stft
3435
pyroomacoustics.sync
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pyroomacoustics.simulation.ism module
2+
=====================================
3+
4+
.. automodule:: pyroomacoustics.simulation.ism
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

docs/pyroomacoustics.simulation.rst

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Simulation Routines Sub-package
2+
===============================
3+
4+
This sub-package contains some internal routines to simulate room acoustics.
5+
6+
Submodules
7+
----------
8+
9+
.. toctree::
10+
:maxdepth: 4
11+
12+
pyroomacoustics.simulation.ism
13+
pyroomacoustics.simulation.rt
14+
15+
Module contents
16+
---------------
17+
18+
.. automodule:: pyroomacoustics.simulation
19+
:members:
20+
:undoc-members:
21+
:show-inheritance:
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pyroomacoustics.simulation.rt module
2+
====================================
3+
4+
.. automodule:: pyroomacoustics.simulation.rt
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

docs/pyroomacoustics.version.rst

-7
This file was deleted.

examples/directivities/cardioid_function.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
direction = spher2cart(azimuth=225, degrees=True)
1616

1717
# compute response
18-
resp = cardioid_func(x=cart, direction=direction, coef=0.5, magnitude=True)
18+
resp = cardioid_func(x=cart, direction=direction, p=0.5, magnitude=True)
1919
resp_db = dB(np.array(resp))
2020

2121
# plot
@@ -33,7 +33,7 @@
3333
direction = spher2cart(azimuth=0, colatitude=45, degrees=True)
3434

3535
# compute response
36-
resp = cardioid_func(x=cart, direction=direction, coef=0.25, magnitude=True)
36+
resp = cardioid_func(x=cart, direction=direction, p=0.25, magnitude=True)
3737

3838
# plot (surface plot)
3939
fig = plt.figure()

examples/directivities/circular_mic_array.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import matplotlib.pyplot as plt
22

33
import pyroomacoustics as pra
4-
from pyroomacoustics.directivities import (
5-
CardioidFamily,
6-
DirectionVector,
7-
DirectivityPattern,
8-
)
4+
from pyroomacoustics.directivities import Cardioid, DirectionVector
95

106
three_dim = True # 2D or 3D
117

@@ -28,9 +24,8 @@
2824
room.add_source(source_loc)
2925

3026
# add circular microphone array
31-
pattern = DirectivityPattern.CARDIOID
3227
orientation = DirectionVector(azimuth=mic_rotation, colatitude=colatitude, degrees=True)
33-
directivity = CardioidFamily(orientation=orientation, pattern_enum=pattern)
28+
directivity = Cardioid(orientation=orientation)
3429
mic_array = pra.beamforming.circular_microphone_array_xyplane(
3530
center=center,
3631
M=7,

examples/directivities/mic_array.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@
22
import numpy as np
33

44
import pyroomacoustics as pra
5-
from pyroomacoustics.directivities import (
6-
CardioidFamily,
7-
DirectionVector,
8-
DirectivityPattern,
9-
)
5+
from pyroomacoustics.directivities import DirectionVector, HyperCardioid
106

11-
pattern = DirectivityPattern.HYPERCARDIOID
127
orientation = DirectionVector(azimuth=0, colatitude=0, degrees=True)
138

149
# create room
@@ -26,7 +21,7 @@
2621
M = 3
2722
R = pra.linear_2D_array(center=[5, 5], M=M, phi=0, d=0.7)
2823
R = np.concatenate((R, np.ones((1, M))))
29-
directivity = CardioidFamily(orientation=orientation, pattern_enum=pattern)
24+
directivity = HyperCardioid(orientation=orientation)
3025
room.add_microphone_array(R, directivity=directivity)
3126

3227
# plot room

examples/directivities/mic_array_diff_directivities.py

+4-11
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,17 @@
22
import numpy as np
33

44
import pyroomacoustics as pra
5-
from pyroomacoustics.directivities import (
6-
CardioidFamily,
7-
DirectionVector,
8-
DirectivityPattern,
9-
)
5+
from pyroomacoustics.directivities import Cardioid, DirectionVector, HyperCardioid
106

11-
dir_1 = CardioidFamily(
7+
dir_1 = Cardioid(
128
orientation=DirectionVector(azimuth=180, colatitude=30, degrees=True),
13-
pattern_enum=DirectivityPattern.HYPERCARDIOID,
149
)
15-
dir_2 = CardioidFamily(
10+
dir_2 = HyperCardioid(
1611
orientation=DirectionVector(azimuth=0, colatitude=30, degrees=True),
17-
pattern_enum=DirectivityPattern.HYPERCARDIOID,
1812
)
1913
# source_dir = None
20-
source_dir = CardioidFamily(
14+
source_dir = HyperCardioid(
2115
orientation=DirectionVector(azimuth=45, colatitude=90, degrees=True),
22-
pattern_enum=DirectivityPattern.CARDIOID,
2316
)
2417

2518
# create room

0 commit comments

Comments
 (0)