Spherical Harmonics Room (shroom): a Python library for room acoustics simulation, Ambisonics processing, and spherical microphone array modelling.
Project description
shroom
Spherical Harmonics Room
A Python library for simulating room acoustics using Spherical Harmonics (Ambisonics). It provides tools for simulating room impulse responses (ARIR), microphone arrays, and binaural rendering.
Features
- Room Simulation: Image Source Method (ISM) adapted for Spherical Harmonics.
- Spatial Signals: Unified handling of Time, Frequency, Space, and Spherical Harmonics (SH) domains.
- Processors: Modular processing chain including:
ArrayDecoder: Simulates spherical microphone arrays.ASMEncoder: Encodes microphone signals to Ambisonics (ASM).BinauralDecoder: Decodes Ambisonics to Binaural audio using HRTFs.
- Rotation: Efficient rotation of sound fields and HRTFs using Wigner-D matrices, or via space domain grid rotation.
- Visualization: 2D and 3D plotting of room geometry, sources, and receiver orientation.
Installation
pip install shroom
For development (including tests):
pip install -e .[dev]
Quick Start
Basic Binaural Rendering
import numpy as np
from shroom.acoustics.room import Room
from shroom.paths import DEFAULT_WAV_PATH
# 1. Initialize Room
room = Room(
dimensions=[6.0, 5.0, 3.0],
absorption=0.8,
sh_order=3,
fs=48000
)
# 2. Add Source and Receiver
room.add_source([4.0, 2.0, 1.5], signal=DEFAULT_WAV_PATH)
room.set_receiver([2.0, 2.0, 1.5])
# 3. Compute Ambisonics Response
amb_signal = room.compute_amb()
# 4. Plot
room.plot(plot_3d=True)
Dynamic Head Rotation
import numpy as np
from scipy.spatial.transform import Rotation
from shroom.acoustics.room import Room
from shroom.acoustics.processors import BinauralDecoder
from shroom.utils.file_utils import load_file
from shroom.paths import DEFAULT_HRTF_PATH, DEFAULT_WAV_PATH
# 1. Initialize Room & Compute Ambisonics (Reference Frame)
room = Room(dimensions=[6.0, 5.0, 3.0], sh_order=3, fs=48000)
room.add_source([4.0, 2.0, 1.5], signal=DEFAULT_WAV_PATH)
room.set_receiver([2.0, 2.0, 1.5])
amb_ref = room.compute_amb()
# 2. Load HRTF
hrtf_base = load_file(DEFAULT_HRTF_PATH)
hrtf_base.toSH(N_sp=3)
# 3. Rotate Listener Orientation (Modal Rotation via Wigner-D)
rot = Rotation.from_euler("zyx", [45, 0, 0], degrees=True) # 45 deg Yaw
hrtf_rot = hrtf_base.copy()
hrtf_rot.rotate_sh_domain(rot)
# 4. Decode with Rotated HRTF
decoder = BinauralDecoder(hrtf_rot, sh_order=3)
binaural = decoder.process(amb_ref)
Complete ASM Processing Chain
from shroom.acoustics.processors import ProcessorChain, ArrayDecoder, ASMEncoder, BinauralDecoder
from shroom.encoders.asm import ASM
# 1. Setup Signal Chain: Room -> Array -> ASM Encoder -> Binaural Decoder
# Note: array_time_sh and asm_instance must be pre-configured
chain = ProcessorChain([
ArrayDecoder(array_time_sh), # Simulate mic recordings
ASMEncoder(asm_instance), # Encode mics to Ambisonics (ASM)
BinauralDecoder(hrtf, sh_order=1) # Render to binaural
])
# 2. Process Ambisonics through the Chain
binaural_output = chain.process(room.compute_amb())
Optimized Low-Order Rendering (MagLS)
from shroom.acoustics.hrtf_processing import magls_hrtf
from shroom.acoustics.processors import BinauralDecoder
# 1. Compute MagLS-optimized HRTF (Mitigates spectral artifacts at low SH orders)
hrtf_magls = magls_hrtf(original_hrtf, sh_order=1)
# 2. Decode using optimized modal weights
decoder = BinauralDecoder(hrtf_magls, sh_order=1)
binaural_output = decoder.process(room.compute_amb())
Dependencies
- numpy
- scipy
- matplotlib
- pyroomacoustics
- soundfile
- sounddevice
- sofar
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyshroom-0.1.0.tar.gz.
File metadata
- Download URL: pyshroom-0.1.0.tar.gz
- Upload date:
- Size: 2.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eaaf9fd2fd699bfaa13c730badb0407f939fb24dd2b872b45cf5a893ce34de01
|
|
| MD5 |
a7fae458ebb9c4e7830e4ed6c95a8ced
|
|
| BLAKE2b-256 |
c120b24f3a97dedff18d5d6a3ba47202d347549ede9d8fed7eef2afec227707d
|
File details
Details for the file pyshroom-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyshroom-0.1.0-py3-none-any.whl
- Upload date:
- Size: 2.7 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3298d55ad7b9b50216edcf181deab8bd4b60214495a83dcb49098e087cd87422
|
|
| MD5 |
aaa3486dbc9a700f0edc60568c7799dd
|
|
| BLAKE2b-256 |
84ba14ad265345fa80d6ff5845fdf1b2b2bfc04a42ffb3dadb0bf7b70e58aea2
|