Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for recorded source/mic directivities from DIRPAT database (#259) #302

Open
wants to merge 60 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
54ac420
Support for recorded source/mic directivities from DIRPAT database (#…
prerak23 Feb 2, 2023
63d13f8
merge with master
fakufaku Feb 6, 2023
4274ec2
remove deprecated np.float type alias from numpy. run black
fakufaku Feb 6, 2023
8853437
isort
fakufaku Feb 6, 2023
02af651
isort
fakufaku Feb 8, 2023
76f8b96
Adds download functions for the SOFA files from DIRPAT. Adds tests fo…
fakufaku Feb 9, 2023
88e1c5b
Adds workaround to CI for windows and py3.7
fakufaku Feb 9, 2023
a2e1080
Changes the EM32 sofa file url to official url
fakufaku Feb 10, 2023
2c04a8c
open_sofa_interpolate.py: vectorizes fibonnaci computations, use sphe…
fakufaku Feb 13, 2023
910e5b5
Fixes the weights in the weighted pseudo-inverse used in the interpol…
fakufaku Feb 13, 2023
1a45b7c
Moves SOFA open function out of the DIRPATInterpolate class.
fakufaku Feb 14, 2023
70a562e
Separates the spherical interpolation from the DIRPAT and SOFA classe…
fakufaku Feb 14, 2023
b662934
Merge branch 'master' into dev/dirpat
fakufaku Feb 14, 2023
683b498
Vectorizes the spherical harmonics computation function for spherical…
fakufaku Feb 14, 2023
7507118
Moves the regular grid detection function to doa.utils
fakufaku Feb 14, 2023
9f91a55
Changes the DIRPAT terminology to something more general to support m…
fakufaku Feb 15, 2023
079bb1e
black/isort
fakufaku Feb 15, 2023
5958ce0
black/sort
fakufaku Feb 15, 2023
b6ff1cb
Adds support sofe simple hrir sofa files
fakufaku Jun 3, 2023
f558bfc
Adds two SOFA files for MIT Kemar HRTF. Adds an example script for bi…
fakufaku Jun 3, 2023
f76ca8f
merge master
fakufaku Jun 5, 2023
bdb8309
Modularize the RIR building routines for ISM and RT
fakufaku Jun 10, 2023
32269ae
Fixing tests for sofa files
fakufaku Jun 12, 2023
92e4007
Adds simulation sub-package in list in setup.py
fakufaku Jun 12, 2023
9b38cca
Adds init file for simulation sub-package
fakufaku Jun 12, 2023
88a9c54
fix sofa test
fakufaku Jun 12, 2023
4922a0e
ray tracing: adds air absorption, linear interpolation of histogram
fakufaku Jun 14, 2023
5ffe18c
Fixes issue when histogram is all zeros
fakufaku Jun 14, 2023
0ab2ad9
Switch to using the origin pyroomacoustics fibonacci spherical grid f…
fakufaku Jun 16, 2023
46e30d1
moves is_dirpat check inside the open sofa file function
fakufaku Jul 4, 2023
b0d2b1d
modularize the element location parsing routine for sofa files
fakufaku Sep 29, 2023
b4abb9b
adds sofa database as attrdict
fakufaku Apr 23, 2024
3984eaa
black
fakufaku May 7, 2024
20e4106
merge master
fakufaku May 7, 2024
1c1ddc9
Improved SOFA api
fakufaku May 25, 2024
cf6802e
example
fakufaku May 25, 2024
0edebfb
Fixes the SOFA tests. Due to change of sampling algorithm (scipy.sign…
fakufaku May 25, 2024
bc016ad
lint
fakufaku May 26, 2024
e96f4ee
merge
fakufaku May 26, 2024
b6aa302
relocates the from directivities to simulation/ism
fakufaku May 26, 2024
9fb7ba7
fixes source_angle_shoebox test
fakufaku May 26, 2024
7874a01
refactors directivities sub-module and sofa sub-module into a single …
fakufaku May 26, 2024
ccacfed
fixes sofa db to include files that are present, but not in the json …
fakufaku May 26, 2024
65107c4
SOFA measurement labels are read from the database when available. Ma…
fakufaku May 26, 2024
26f4a32
removes unnecessary imports and lint
fakufaku May 26, 2024
b1a0357
Merge branch 'master' into dev/dirpat
fakufaku May 26, 2024
120ac43
CHANGELOG formatting for branch
fakufaku May 26, 2024
1d09fb8
merge
fakufaku May 27, 2024
f866eb8
Fixes the cardioid family formula in the corresponding object. Adds a…
fakufaku May 27, 2024
b3917a0
lint
fakufaku May 27, 2024
d8d79ea
changes the interface for cardioid family. Removes the enum, uses sep…
fakufaku May 27, 2024
d392bb6
lint
fakufaku May 27, 2024
d48a899
Changes the KDTree in MeasuredDirectivity from operating on spherical…
fakufaku May 27, 2024
e845041
Adds directivities (analytic and measured) to the documentation.
fakufaku May 28, 2024
f89e815
adds soxr to requirements for doc building
fakufaku May 28, 2024
8d24c10
Doc
fakufaku May 28, 2024
d7371a8
Disallow directivities for 2D rooms.
fakufaku May 28, 2024
5e1334f
Fixes directivities examples
fakufaku May 28, 2024
200e875
lint
fakufaku May 28, 2024
b6d9a6c
Fixes some docstrings
fakufaku May 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint with flake8
- name: Workaround for windows and python 3.7
if: matrix.os == 'windows-latest' && matrix.python-version == 3.7
run: |
pip install netCDF4<=1.5.8
# There is no binary package of netCF4>=1.6.0 for windows and python 3.7
# the largest supported version is 1.5.8
- name: Install dependencies
run: |
# pip install flake8
# stop the build if there are Python syntax errors or undefined names
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
pip install -r requirements.txt
- name: Build package
run: |
python -m pip install -e .
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ local_examples/
pyroomacoustics.egg-info/
pyroomacoustics/build_rir.c
pyroomacoustics/**/*.so
pyroomacoustics/directivities/tests/data/*.pdf
32 changes: 32 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,38 @@ The format is based on `Keep a
Changelog <http://keepachangelog.com/en/1.0.0/>`__ and this project
adheres to `Semantic Versioning <http://semver.org/spec/v2.0.0.html>`_.

dev/dirpat
----------

Added
~~~~~

- New global parameters to control the octave bands used for simulation.

- ``octave_bands_base_freq``: the base frequency used for the octave bands (default ``125``),
note that together with the sampling frequency this will determine the number of sub-bands
used in simulation.
- ``octave_bands_n_fft``: lengths of the octave band filters (current is default ``512``
but will be changed to ``128`` in the next release)
- ``octave_bands_keep_dc``: extends the lowest band to include the DC offset,
the current default is ``False`` to match past behavior, but will be changed to
``True`` in the next release because the filters have less oscillations this way.

- Simulation with measured directivity responses in SOFA format (limited file types) is
possible with the image source model.
- Adds `soxr <https://github.com/dofuuz/python-soxr>`_ as a dependency since resampling
can often be necessary when working with SOFA files.

Changed
~~~~~~~

- In ray tracing, the histograms are now linearly interpolated between
the bins to obtain smoother RIR
- Changed the API of ``CardioidFamily`` to take a float parameter.
New class wrappers for ``Cardioid``, ``Hypercardioid``, ``Supercardioid``,
``Bidirectional`` and ``Omnidirectional`` are added in the ``directivity``
sub-module. The enum of type ``DirectivityPattern`` has been removed.

`Unreleased`_
-------------

Expand Down
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Acoustic data for the simulation
include pyroomacoustics/data/materials.json
include pyroomacoustics/data/AKG_c480_c414_CUBE.sofa
include pyroomacoustics/data/EM32_Directivity.sofa
include pyroomacoustics/data/sofa/mit_kemar_large_pinna.sofa
include pyroomacoustics/data/sofa/mit_kemar_normal_pinna.sofa

# The header files for the compiled extension
include pyroomacoustics/libroom_src/*.h
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"mpl_toolkits.mplot3d",
"joblib",
"scipy.io",
"soxr",
]

try:
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Table of contents
contributing
changelog
pyroomacoustics.room
pyroomacoustics.directivities
pyroomacoustics.materials.database
pyroomacoustics.transform
pyroomacoustics.datasets
Expand Down
7 changes: 0 additions & 7 deletions docs/modules.rst

This file was deleted.

1 change: 1 addition & 0 deletions docs/pyroomacoustics.datasets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Datasets Available

pyroomacoustics.datasets.cmu_arctic
pyroomacoustics.datasets.google_speech_commands
pyroomacoustics.datasets.sofa
pyroomacoustics.datasets.timit

Tools and Helpers
Expand Down
5 changes: 5 additions & 0 deletions docs/pyroomacoustics.datasets.sofa.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SOFA Database
=============

.. automodule:: pyroomacoustics.datasets.sofa
:members:
72 changes: 70 additions & 2 deletions docs/pyroomacoustics.directivities.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,75 @@
pyroomacoustics.directivities module
====================================
Directional Sources and Microphones
===================================

.. automodule:: pyroomacoustics.directivities
:members:
:undoc-members:
:show-inheritance:

Analytic Directional Responses
------------------------------

.. automodule:: pyroomacoustics.directivities.analytic
:members:
:undoc-members:
:show-inheritance:

Measured Directivities
----------------------

.. automodule:: pyroomacoustics.directivities.measured
:members:
:undoc-members:
:show-inheritance:

Built-in SOFA Files Database
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. automodule:: pyroomacoustics.datasets.sofa
:members: SOFADatabase, get_sofa_db
:noindex:


Reading Other or Custom File Types
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It is possible to read other file types by providing a custom reader function to
:py:class:`~pyroomacoustics.directivities.measured.MeasuredDirectivityFile` with the
argument ``file_reader_callback``.
The function should have the same signature as :py:func:`~pyroomacoustics.directivities.sofa.open_sofa_file`.


SOFA File Readers
.................

.. automodule:: pyroomacoustics.directivities.sofa
:members:
:show-inheritance:

Direction of the Patterns
-------------------------

.. automodule:: pyroomacoustics.directivities.direction
:members:
:show-inheritance:


Creating New Types of Directivities
-----------------------------------

.. automodule:: pyroomacoustics.directivities.base
:members:
:undoc-members:
:show-inheritance:

Spherical Interpolation
-----------------------

.. automodule:: pyroomacoustics.directivities.interp
:members: spherical_interpolation

Numerical Spherical Integral
----------------------------

.. automodule:: pyroomacoustics.directivities.integration
:members: spherical_integral
7 changes: 0 additions & 7 deletions docs/pyroomacoustics.libroom.rst

This file was deleted.

1 change: 1 addition & 0 deletions docs/pyroomacoustics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Submodules
pyroomacoustics.parameters
pyroomacoustics.recognition
pyroomacoustics.room
pyroomacoustics.simulation
pyroomacoustics.soundsource
pyroomacoustics.stft
pyroomacoustics.sync
Expand Down
7 changes: 7 additions & 0 deletions docs/pyroomacoustics.simulation.ism.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pyroomacoustics.simulation.ism module
=====================================

.. automodule:: pyroomacoustics.simulation.ism
:members:
:undoc-members:
:show-inheritance:
21 changes: 21 additions & 0 deletions docs/pyroomacoustics.simulation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Simulation Routines Sub-package
===============================

This sub-package contains some internal routines to simulate room acoustics.

Submodules
----------

.. toctree::
:maxdepth: 4

pyroomacoustics.simulation.ism
pyroomacoustics.simulation.rt

Module contents
---------------

.. automodule:: pyroomacoustics.simulation
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/pyroomacoustics.simulation.rt.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pyroomacoustics.simulation.rt module
====================================

.. automodule:: pyroomacoustics.simulation.rt
:members:
:undoc-members:
:show-inheritance:
7 changes: 0 additions & 7 deletions docs/pyroomacoustics.version.rst

This file was deleted.

4 changes: 2 additions & 2 deletions examples/directivities/cardioid_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
direction = spher2cart(azimuth=225, degrees=True)

# compute response
resp = cardioid_func(x=cart, direction=direction, coef=0.5, magnitude=True)
resp = cardioid_func(x=cart, direction=direction, p=0.5, magnitude=True)
resp_db = dB(np.array(resp))

# plot
Expand All @@ -33,7 +33,7 @@
direction = spher2cart(azimuth=0, colatitude=45, degrees=True)

# compute response
resp = cardioid_func(x=cart, direction=direction, coef=0.25, magnitude=True)
resp = cardioid_func(x=cart, direction=direction, p=0.25, magnitude=True)

# plot (surface plot)
fig = plt.figure()
Expand Down
9 changes: 2 additions & 7 deletions examples/directivities/circular_mic_array.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import matplotlib.pyplot as plt

import pyroomacoustics as pra
from pyroomacoustics.directivities import (
CardioidFamily,
DirectionVector,
DirectivityPattern,
)
from pyroomacoustics.directivities import Cardioid, DirectionVector

three_dim = True # 2D or 3D

Expand All @@ -28,9 +24,8 @@
room.add_source(source_loc)

# add circular microphone array
pattern = DirectivityPattern.CARDIOID
orientation = DirectionVector(azimuth=mic_rotation, colatitude=colatitude, degrees=True)
directivity = CardioidFamily(orientation=orientation, pattern_enum=pattern)
directivity = Cardioid(orientation=orientation)
mic_array = pra.beamforming.circular_microphone_array_xyplane(
center=center,
M=7,
Expand Down
9 changes: 2 additions & 7 deletions examples/directivities/mic_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@
import numpy as np

import pyroomacoustics as pra
from pyroomacoustics.directivities import (
CardioidFamily,
DirectionVector,
DirectivityPattern,
)
from pyroomacoustics.directivities import DirectionVector, HyperCardioid

pattern = DirectivityPattern.HYPERCARDIOID
orientation = DirectionVector(azimuth=0, colatitude=0, degrees=True)

# create room
Expand All @@ -26,7 +21,7 @@
M = 3
R = pra.linear_2D_array(center=[5, 5], M=M, phi=0, d=0.7)
R = np.concatenate((R, np.ones((1, M))))
directivity = CardioidFamily(orientation=orientation, pattern_enum=pattern)
directivity = HyperCardioid(orientation=orientation)
room.add_microphone_array(R, directivity=directivity)

# plot room
Expand Down
15 changes: 4 additions & 11 deletions examples/directivities/mic_array_diff_directivities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,17 @@
import numpy as np

import pyroomacoustics as pra
from pyroomacoustics.directivities import (
CardioidFamily,
DirectionVector,
DirectivityPattern,
)
from pyroomacoustics.directivities import Cardioid, DirectionVector, HyperCardioid

dir_1 = CardioidFamily(
dir_1 = Cardioid(
orientation=DirectionVector(azimuth=180, colatitude=30, degrees=True),
pattern_enum=DirectivityPattern.HYPERCARDIOID,
)
dir_2 = CardioidFamily(
dir_2 = HyperCardioid(
orientation=DirectionVector(azimuth=0, colatitude=30, degrees=True),
pattern_enum=DirectivityPattern.HYPERCARDIOID,
)
# source_dir = None
source_dir = CardioidFamily(
source_dir = HyperCardioid(
orientation=DirectionVector(azimuth=45, colatitude=90, degrees=True),
pattern_enum=DirectivityPattern.CARDIOID,
)

# create room
Expand Down
12 changes: 7 additions & 5 deletions examples/directivities/plot_directivity_2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

from pyroomacoustics import dB
from pyroomacoustics.directivities import (
CardioidFamily,
Cardioid,
DirectionVector,
DirectivityPattern,
FigureEight,
HyperCardioid,
SubCardioid,
)

orientation = DirectionVector(azimuth=0, colatitude=90, degrees=True)
Expand All @@ -18,11 +20,11 @@
# plot each pattern
fig = plt.figure()
ax = plt.subplot(111, projection="polar")
for pattern in DirectivityPattern:
dir_obj = CardioidFamily(orientation=orientation, pattern_enum=pattern)
for obj in [SubCardioid, Cardioid, HyperCardioid, FigureEight]:
dir_obj = obj(orientation=orientation)
resp = dir_obj.get_response(azimuth=angles, magnitude=True, degrees=False)
resp_db = dB(np.array(resp))
ax.plot(angles, resp_db, label=pattern.name)
ax.plot(angles, resp_db, label=dir_obj.directivity_pattern)

plt.legend(bbox_to_anchor=(1, 1))
plt.ylim([lower_gain, 0])
Expand Down
9 changes: 2 additions & 7 deletions examples/directivities/plot_directivity_3D.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import matplotlib.pyplot as plt
import numpy as np

from pyroomacoustics.directivities import (
CardioidFamily,
DirectionVector,
DirectivityPattern,
)
from pyroomacoustics.directivities import DirectionVector, HyperCardioid

pattern = DirectivityPattern.HYPERCARDIOID
orientation = DirectionVector(azimuth=0, colatitude=45, degrees=True)

# create cardioid object
dir_obj = CardioidFamily(orientation=orientation, pattern_enum=pattern)
dir_obj = HyperCardioid(orientation=orientation)

# plot
azimuth = np.linspace(start=0, stop=360, num=361, endpoint=True)
Copy link
Collaborator

@prerak23 prerak23 Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For colatitude, shouldn't the "num" be equal to 181?

Expand Down
Loading
Loading