spaudiopy.io
Input Output (IO) helpers.
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['axes.grid'] = True
import spaudiopy as spa
Functions
|
Creates the default HRIRs loaded by load_hrirs() by inverse SHT. |
|
Load mono and multichannel audio from files. |
|
Convenience function to load 'HRIRs.mat'. |
|
Load loudspeaker layout from json configuration file. |
|
Convenience function to load 'SDM.mat'. |
|
Load .sofa file into python dictionary that contains the data in numpy arrays. |
|
Load SOFA file containing HRIRs. |
|
Save signal to audio file. |
|
Save loudspeaker layout to json configuration file. |
|
Load and transform SOFA IRs to the Spherical Harmonic Domain. |
|
Write binaural room impulse responses (BRIRs) and save as wav file. |
|
Write binaural room impulse responses (BRIRs) and save as wav file. |
- spaudiopy.io.load_audio(filenames, fs=None)[source]
Load mono and multichannel audio from files.
- Parameters:
filenames (string or list of strings) – Audio files.
- Returns:
sig (sig.MonoSignal or sig.MultiSignal) – Audio signal.
- spaudiopy.io.save_audio(signal, filename, fs=None, subtype='FLOAT')[source]
Save signal to audio file.
- Parameters:
signal (sig. MonoSignal, sig.MultiSignal or np.ndarray) – Audio Signal, forwarded to sf.write(); (frames x channels).
filename (string) – Audio file name.
fs (int) – fs(t).
subtype (optional)
- spaudiopy.io.load_hrirs(fs, filename=None, jobs_count=None)[source]
Convenience function to load ‘HRIRs.mat’. The file contains [‘hrir_l’, ‘hrir_r’, ‘fs’, ‘azi’, ‘zen’].
- Parameters:
fs (int) – fs(t).
filename (string, optional) – HRTF.mat file or default set, or ‘dummy’ for debugging.
jobs_count (int or None, optional) – Number of parallel jobs for resample_hrirs() in get_default_hrirs(), ‘None’ employs ‘cpu_count’.
- Returns:
HRIRs (sig.HRIRs instance) –
- left(g, h) numpy.ndarray
h(t) for grid position g.
- right(g, h) numpy.ndarray
h(t) for grid position g.
- azi(g,) array_like
grid azimuth.
- zen(g,) array_like
grid zenith / colatitude.
- fsint
fs(t).
- spaudiopy.io.get_default_hrirs(grid_azi=None, grid_zen=None, jobs_count=None)[source]
Creates the default HRIRs loaded by load_hrirs() by inverse SHT. By default it renders onto a gauss grid of order N=35, and additionally resamples fs to 48kHz.
- Parameters:
grid_azi (array_like, optional)
grid_zen (array_like, optional)
jobs_count (int or None, optional) – Number of parallel jobs for resample_hrirs(), ‘None’ employs ‘cpu_count’.
Notes
HRTFs in SH domain obtained from http://dx.doi.org/10.14279/depositonce-5718.5
- spaudiopy.io.load_sofa_data(filename)[source]
Load .sofa file into python dictionary that contains the data in numpy arrays.
- spaudiopy.io.load_sofa_hrirs(filename)[source]
Load SOFA file containing HRIRs.
- Parameters:
filename (string) – SOFA filepath.
- Returns:
HRIRs (sig.HRIRs instance) –
- left(g, h) numpy.ndarray
h(t) for grid position g.
- right(g, h) numpy.ndarray
h(t) for grid position g.
- azi(g,) array_like
grid azimuth.
- zen(g,) array_like
grid zenith / colatitude.
- fsint
fs(t).
- spaudiopy.io.sofa_to_sh(filename, N_sph, sh_type='real')[source]
Load and transform SOFA IRs to the Spherical Harmonic Domain.
- Parameters:
filename (string) – SOFA file name.
N_sph (int) – Spherical Harmonic Transform order.
sh_type (‘real’ (default) or ‘complex’ spherical harmonics.)
- Returns:
IRs_nm ((2, (N_sph+1)**2, S) numpy.ndarray) – Left and right (stacked) SH coefficients.
fs (int)
- spaudiopy.io.load_sdm(filename, init_nan=True)[source]
Convenience function to load ‘SDM.mat’. The file contains [‘h_ref’ or ‘p’, ‘sdm_azi’ or ‘sdm_phi’, ‘sdm_zen’ or ‘sdm_theta’, ‘fs’].
- Parameters:
filename (string) – SDM.mat file
init_nan (bool, optional) – Initialize nan to [0, pi/2].
- Returns:
h ((n,) array_like) – p(t).
sdm_azi ((n,) array_like) – Azimuth angle.
sdm_zen ((n,) array_like) – Colatitude angle.
fs (int) – fs(t).
- spaudiopy.io.write_ssr_brirs_loudspeaker(filename, ls_irs, hull, fs, subtype='FLOAT', hrirs=None, jobs_count=1)[source]
Write binaural room impulse responses (BRIRs) and save as wav file.
The azimuth resolution is one degree. The channels are interleaved and directly compatible to the SoundScape Renderer (SSR) ssr-brs.
- Parameters:
filename (string)
ls_irs ((L, S) np.ndarray) – Impulse responses of L loudspeakers, e.g. by hull.loudspeaker_signals().
hull (decoder.LoudspeakerSetup)
fs (int)
subtype (forwarded to sf.write(), optional)
hrirs (sig.HRIRs, optional)
jobs_count (int, optional) – [CPU Cores], Number of Processes, switches implementation for n > 1.
- spaudiopy.io.write_ssr_brirs_sdm(filename, sdm_p, sdm_phi, sdm_theta, fs, subtype='FLOAT', hrirs=None)[source]
Write binaural room impulse responses (BRIRs) and save as wav file.
The azimuth resolution is one degree. The channels are interleaved and directly compatible to the SoundScape Renderer (SSR) ssr-brs.
- Parameters:
filename (string)
sdm_p ((n,) array_like) – Pressure p(t).
sdm_phi ((n,) array_like) – Azimuth phi(t).
sdm_theta ((n,) array_like) – Colatitude theta(t).
fs (int)
subtype (forwarded to sf.write(), optional)
hrirs (sig.HRIRs, optional)