pyroomacoustics.acoustics module

class pyroomacoustics.acoustics.OctaveBandsFactory(base_frequency=125.0, fs=16000, n_fft=512)

Bases: object

A class to process uniformly all properties that are defined on octave bands.

Each property is stored for an octave band.

base_freq

The center frequency of the first octave band

Type

float

fs

The target sampling frequency

Type

float

n_bands

The number of octave bands needed to cover from base_freq to fs / 2 (i.e. floor(log2(fs / base_freq)))

Type

int

bands

The list of bin boundaries for the octave bands

Type

list of tuple

centers

The list of band centers

all_materials

The list of all Material objects created by the factory

Type

list of Material

Parameters
  • base_frequency (float, optional) – The center frequency of the first octave band (default: 125 Hz)

  • fs (float, optional) – The sampling frequency used (default: 16000 Hz)

  • third_octave (bool, optional) – Use third octave bands if True (default: False)

analysis(x, band=None)

Process a signal x through the filter bank

Parameters

x (ndarray (n_samples)) – The input signal

Returns

The input signal filters through all the bands

Return type

ndarray (n_samples, n_bands)

get_bw()

Returns the bandwidth of the bands

pyroomacoustics.acoustics.bandpass_filterbank(bands, fs=1.0, order=8, output='sos')

Create a bank of Butterworth bandpass filters

Parameters
  • bands (array_like, shape == (n, 2)) – The list of bands [[flo1, fup1], [flo2, fup2], ...]

  • fs (float, optional) – Sampling frequency (default 1.)

  • order (int, optional) – The order of the IIR filters (default: 8)

  • output ({'ba', 'zpk', 'sos'}) – Type of output: numerator/denominator (‘ba’), pole-zero (‘zpk’), or second-order sections (‘sos’). Default is ‘ba’.

Returns

  • b, a (ndarray, ndarray) – Numerator (b) and denominator (a) polynomials of the IIR filter. Only returned if output=’ba’.

  • z, p, k (ndarray, ndarray, float) – Zeros, poles, and system gain of the IIR filter transfer function. Only returned if output=’zpk’.

  • sos (ndarray) – Second-order sections representation of the IIR filter. Only returned if output==’sos’.

pyroomacoustics.acoustics.bands_hz2s(bands_hz, Fs, N, transform='dft')

Converts bands given in Hertz to samples with respect to a given sampling frequency Fs and a transform size N an optional transform type is used to handle DCT case.

pyroomacoustics.acoustics.binning(S, bands)

This function computes the sum of all columns of S in the subbands enumerated in bands

pyroomacoustics.acoustics.critical_bands()

Compute the Critical bands as defined in the book: Psychoacoustics by Zwicker and Fastl. Table 6.1 p. 159

pyroomacoustics.acoustics.inverse_sabine(rt60, room_dim, c=None)

Given the desired reverberation time (RT60, i.e. the time for the energy to drop by 60 dB), the dimensions of a rectangular room (shoebox), and sound speed, computes the energy absorption coefficient and maximum image source order needed. The speed of sound used is the package wide default (in constants).

Parameters
  • rt60 (float) – desired RT60 (time it takes to go from full amplitude to 60 db decay) in seconds

  • room_dim (list of floats) – list of length 2 or 3 of the room side lengths

  • c (float) – speed of sound

Returns

  • absorption (float) – the energy absorption coefficient to be passed to room constructor

  • max_order (int) – the maximum image source order necessary to achieve the desired RT60

pyroomacoustics.acoustics.invmelscale(b)

Converts from melscale to frequency in Hertz according to Huang-Acero-Hon (6.143)

pyroomacoustics.acoustics.melfilterbank(M, N, fs=1, fl=0.0, fh=0.5)

Returns a filter bank of triangular filters spaced according to mel scale

We follow Huang-Acera-Hon 6.5.2

Parameters
  • M ((int)) – The number of filters in the bank

  • N ((int)) – The length of the DFT

  • fs ((float) optional) – The sampling frequency (default 8000)

  • fl ((float)) – Lowest frequency in filter bank as a fraction of fs (default 0.)

  • fh ((float)) – Highest frequency in filter bank as a fraction of fs (default 0.5)

Return type

An M times int(N/2)+1 ndarray that contains one filter per row

pyroomacoustics.acoustics.melscale(f)

Converts f (in Hertz) to the melscale defined according to Huang-Acero-Hon (2.6)

pyroomacoustics.acoustics.mfcc(x, L=128, hop=64, M=14, fs=8000, fl=0.0, fh=0.5)

Computes the Mel-Frequency Cepstrum Coefficients (MFCC) according to the description by Huang-Acera-Hon 6.5.2 (2001) The MFCC are features mimicing the human perception usually used for some learning task.

This function will first split the signal into frames, overlapping or not, and then compute the MFCC for each frame.

Parameters
  • x ((nd-array)) – Input signal

  • L ((int)) – Frame size (default 128)

  • hop ((int)) – Number of samples to skip between two frames (default 64)

  • M ((int)) – Number of mel-frequency filters (default 14)

  • fs ((int)) – Sampling frequency (default 8000)

  • fl ((float)) – Lowest frequency in filter bank as a fraction of fs (default 0.)

  • fh ((float)) – Highest frequency in filter bank as a fraction of fs (default 0.5)

Return type

The MFCC of the input signal

pyroomacoustics.acoustics.octave_bands(fc=1000, third=False, start=0.0, n=8)

Create a bank of octave bands

Parameters
  • fc (float, optional) – The center frequency

  • third (bool, optional) – Use third octave bands (default False)

  • start (float, optional) – Starting frequency for octave bands in Hz (default 0.)

  • n (int, optional) – Number of frequency bands (default 8)

pyroomacoustics.acoustics.rt60_eyring(S, V, a, m, c)

This is the Eyring formula for estimation of the reverberation time.

Parameters
  • S – the total surface of the room walls in m^2

  • V – the volume of the room in m^3

  • a (float) – the equivalent absorption coefficient sum(a_w * S_w) / S where a_w and S_w are the absorption and surface of wall w, respectively.

  • m (float) – attenuation constant of air

  • c (float) – speed of sound in m/s

Returns

The estimated reverberation time (RT60)

Return type

float

pyroomacoustics.acoustics.rt60_sabine(S, V, a, m, c)

This is the Eyring formula for estimation of the reverberation time.

Parameters
  • S – the total surface of the room walls in m^2

  • V – the volume of the room in m^3

  • a (float) – the equivalent absorption coefficient sum(a_w * S_w) / S where a_w and S_w are the absorption and surface of wall w, respectively.

  • m (float) – attenuation constant of air

  • c (float) – speed of sound in m/s

Returns

The estimated reverberation time (RT60)

Return type

float