clarity.enhancer.gha.gainrule_camfit module

clarity.enhancer.gha.gainrule_camfit.compute_proportion_overlap(a1: float, a2: float, b1: float, b2: float) float[source]

Compute proportion of overlap of two ranges.

For ranges (a1, a2) and (b1, b2), express the extent of the overlap in the range as a proportion of the extent of range (b1, b2)

e.g (4, 9) and (6, 15) -> overlap (6,9), so proportion is (9-6)/(15-6)

clarity.enhancer.gha.gainrule_camfit.gainrule_camfit_compr(audiogram_left: Audiogram, audiogram_right: Audiogram, sFitmodel: FittingParams, noisegatelevels: float | ndarray = 45.0, noisegateslope: float | ndarray = 1.0, level: float = 0.0, max_output_level: float = 100.0) tuple[ndarray, ndarray, ndarray][source]

Applies compressive Cambridge rule for hearing aid fittings ‘CAMFIT’.

Translation of OpenMHA gainrule_camfit_compr.m. Applies compressive Cambridge rule for hearing aid fittings ‘CAMFIT’. Computes gains for compression according to Moore et al. (1999) “Use of a loudness model for hearing aid fitting: II. Hearing aids with multi-channel compression.” Brit. J. Audiol. (33) 157-170

The gain rule limits the gains so that in each band 100 dB output level is not exceeded. This function assumes audiogram frequencies are identical for the two ears. In this implementation, any negative gains are set to 0 dB.

The original function is part of the HörTech Open Master Hearing Aid (openMHA) Copyright © 2007 2009 2011 2013 2015 2017 2018 HörTech gGmbH openMHA is free software: see licencing conditions at http://www.openmha.org/

Parameters:
  • audiogram_left (Audiogram) – the audiogram for the left ear

  • audiogram_right (Audiogram) – the audiogram for the right ear

  • sFitmodel (dict) – contains the center frequencies for the amplification bands and input levels in SPL for which to compute the gains

  • noisegatelevels (ndarray) – compression threshold levels for each frequency band (default: 45)

  • noisegateslope (int) – determines slope of gains below compression threshold

  • level (int) – input level in each band for compression rate calculation (default: 0 for variable level depending on insertion gains)

  • max_output_level (int) – maximum output level in dB

Returns:

containing gain table, noise gate, and noise

gate expansion slope

Return type:

tuple

clarity.enhancer.gha.gainrule_camfit.gainrule_camfit_linear(audiogram_left: Audiogram, audiogram_right: Audiogram, sFitmodel: FittingParams, noisegatelevels: float | ndarray = 45.0, noisegateslope: float | ndarray = 1.0, max_output_level: float = 100.0) tuple[ndarray, ndarray, ndarray, ndarray][source]

Apply linear Cambridge rule for hearing aid fittings ‘CAMFIT’.

Based on OpenMHA gainrule_camfit_linear.m. Applies linear Cambridge rule for hearing aid fittings ‘CAMFIT’. Implemented as described in B. Moore and B. Glasberg (1998), “Use of a loudness model for hearing-aid fitting. I. Linear hearing aids” Brit. J. Audiol. (32) 317-335.

The gain rule limits the gains so that in each band 100 dB output level is not exceeded. The Cambridge formula defines intercepts only up to 5 kHz. Because the intercepts do not vary much between 1kHz and 5kHz anyway (these are all within 0dB +/- 1dB), we extend the last intercept of +1dB at 5kHz to all higher frequencies. This function assumes audiogram frequencies are identical for two ears.

The original function is part of the HörTech Open Master Hearing Aid (openMHA) Copyright © 2007 2009 2011 2013 2015 2017 2018 HörTech gGmbH openMHA is free software: see licencing conditions at http://www.openmha.org/

Parameters:
  • sAud (dict) – contains the subject-specific hearing threshold levels in dB HL for the left and right ears, and the audiogram frequencies

  • sFitmodel (dict) – contains the center frequencies for the amplification bands and input levels in SPL for which to compute the gains

  • noisegatelevels (ndarray) – compression threshold levels for each frequency band (default: 45)

  • noisegateslope (int) – determines slope of gains below compression threshold (default: 1)

Returns:

containing gain table, noise gate, and noise

gate expansion slope

Return type:

tuple

clarity.enhancer.gha.gainrule_camfit.gains(compr_thr_inputs: ndarray, compr_thr_gains: ndarray, compression_ratios: ndarray, levels: ndarray) ndarray[source]

Based on OpenMHA gains subfunction of gainrule_camfit_compr.

Parameters:
  • compr_thr_inputs (ndarray) – levels for speech in dynamic compression (dc) bands minus minima distance (38 dB)

  • compr_thr_gains (ndarray) – interpolated audiogram levels plus conversion factors of HL thresholds to SPL thresholds (output of isothr) minus compr_thr_inputs

  • compression_ratios (ndarray) – compression ratios according to CAMFIT compressive

  • levels (ndarray) – set of levels over which to calculate gains e.g. -10:110 dB

Returns:

set of uncorrected gains as 2-d numpy array

Return type:

ndarray

clarity.enhancer.gha.gainrule_camfit.isothr(vsDesF: list[int] | ndarray) ndarray[source]

Calculate conversion factors of HL thresholds to SPL thresholds.

Translation of OpenMHA isothr.m. Calculates conversion factors of HL thresholds to SPL thresholds. Values from 20 Hz to 12500 Hz are taken from ISO 226:2003(E). Values from 14000 Hz to 18000 Hz are taken from ISO 389-7:2005 (reference thresholds of hearing for free field listening). Values at 0 and 20000 Hz are not taken from the ISO Threshold contour.

Parameters:

vsDesF (list) – centre frequencies for the amplification bands as 177, 297, 500, 841, 1414, 2378, 4000, 6727, 11314 Hz

Returns:

conversion factors

Return type:

ndarray