recipes.cad1.task2.baseline.car_scene_acoustics module

A class for the car acoustic environment.

class recipes.cad1.task2.baseline.car_scene_acoustics.CarSceneAcoustics(track_duration: int, sample_rate: int, hrtf_dir: str, config_nalr: dict, config_compressor: dict, extend_noise: float = 0.2)[source]

Bases: object

A class for the car acoustic environment.

Constants:
ANECHOIC_HRTF_FOR_NOISE (dict): A dictionary containing the names of the
anechoic BRIRs for the following directions:
0 degrees: front
  • 000_left: The left channel of the BRIR for 0 degrees.

  • 000_right: The right channel of the BRIR for 0 degrees.

-90 degrees: left
  • m90_left: The left channel of the BRIR for -90 degrees.

  • m90_right: The right channel of the BRIR for -90 degrees.

90 degrees: right
  • p90_left: The left channel of the BRIR for 90 degrees.

  • p90_right: The right channel of the BRIR for 90 degrees.

ANECHOIC_HRTF_FOR_NOISE = {'000_left': 'HR36_E02_CH1_Left.wav', '000_right': 'HR36_E02_CH1_Right.wav', 'm90_left': 'HR0_E02_CH1_Left.wav', 'm90_right': 'HR0_E02_CH1_Right.wav', 'p90_left': 'HR72_E02_CH1_Left.wav', 'p90_right': 'HR72_E02_CH1_Right.wav'}
add_anechoic_hrtf_to_noise(noise_signal: ndarray) ndarray[source]

Adds the Anechoic HRTF to the noise signal. :param noise_signal: A numpy array representing the different components

of the car noise signal.

Returns:

The noise signal with the Anechoic HRTF applied.

Return type:

np.ndarray

add_hrtf_to_stereo_signal(signal: ndarray, hrir: dict, hrtf_type: str) ndarray[source]
Add a head rotation transfer function using binaural room impulse

response (BRIR) from eBrird.

Parameters:
  • signal (np.ndarray) – a numpy array of shape (2, n_samples) containing the stereo audio signal.

  • hrir – a dictionary containing the HRIR (head-related impulse response) filenames.

  • hrtf_type – the type of HRTF to use. Can be either “Anechoic” or “Car”.

Returns:

A numpy array of shape (2, n_samples) containing the stereo audio signal

with the BRIR added.

static add_two_signals(signal1: ndarray, signal2: ndarray) ndarray[source]

Adds two signals together.

Parameters:
  • signal1 (np.ndarray) – The first signal.

  • signal2 (np.ndarray) – The second signal.

Returns:

The sum of the two signals.

Return type:

np.ndarray

apply_car_acoustics_to_signal(enh_signal: ndarray, scene: dict, listener: Listener, hrtf: dict, audio_manager: AudioManager, config: DictConfig) ndarray[source]

Applies the car acoustics to the enhanced signal.

Parameters:
  • enh_signal (np.ndarray) – The enhanced signal to apply the car acoustics to.

  • scene (dict) – The scene dictionary with the acoustics parameters.

  • listener (Listener) – The listener characteristics.

  • hrtf (dict) – A dictionary containing the head-related transfer functions (HRTFs) for the listener being evaluated. This includes the left and right HRTFs for the car and the anechoic room.

  • audio_manager (AudioManager) – The audio manager object.

  • config (DictConfig) – The config object.

Returns:

The enhanced signal with the car acoustics applied. np.ndarray: The reference signal normalised to enhanced level.

Return type:

np.ndarray

apply_hearing_aid(signal: ndarray, audiogram: Audiogram) ndarray[source]

Applies the hearing aid: It consists in NALR prescription and Compressor

Parameters:
  • signal (np.ndarray) – The audio signal to be enhanced.

  • audiogram (Audiogram) – The audiogram of the listener.

Returns:

The enhanced audio signal.

Return type:

np.ndarray

equalise_level(signal: ndarray, reference_signal: ndarray, max_level: float = 20) ndarray[source]

Equalises the level of the target signal to the reference signal.

Parameters:
  • signal (np.ndarray) – The target signal to equalise.

  • reference_signal (np.ndarray) – The reference signal.

  • max_level (float) – The maximum level of the target signal. This to prevent clipping.

Returns:

The equalised target signal.

Return type:

np.ndarray

get_car_noise(car_noise_params: dict) ndarray[source]

Generates car noise.

Parameters:

car_noise_params (dict) – Car Noise Parameters as generated by Class CarNoiseParameterGenerator

Returns:

A numpy array representing the different components

of the car noise signal

Return type:

numpy.ndarray

preload_anechoic_hrtf(hrtf_dir: str) None[source]

Loads the Anechoic BRIRs from the eBrird database for the given directions. Using the following directions:

0 degrees: front -90 degrees: left 90 degrees: right

Parameters:

brird_dir (str) – The path to the directory containing the BRIR files.

scale_signal_to_snr(signal: np.ndarray, reference_signal: np.ndarray, snr: float | None = 0) np.ndarray[source]

Scales the target signal to the desired SNR. We transpose channel because pylodnorm operates on arrays with shape [n_samples, n_channels].

Parameters:
  • target_signal (np.ndarray) – The target signal to scale.

  • reference_signal (np.ndarray) – The reference signal.

  • snr (float) – The desired SNR gain in dB. If None, the target signal is scaled to the reference signal.

Returns:

The scaled target signal.

Return type:

np.ndarray