Skip to content

[FEATURE] add pytta.iso532_2 with the Moore-Glasberg loudness - #95

Open
aguirreSL wants to merge 1 commit into
PyTTaMaster:developmentfrom
aguirreSL:dev-iso532_2
Open

aguirreSL wants to merge 1 commit into
PyTTaMaster:developmentfrom
aguirreSL:dev-iso532_2

Conversation

@aguirreSL

Copy link
Copy Markdown

Adds pytta.iso532_2, the loudness of stationary sounds by the Moore-Glasberg method of ISO 532-2:2017, for monaural, diotic and dichotic listening. The ITA-Toolbox reaches this method through ita_psychoacoustic_loudness, a wrapper of the MATLAB Audio Toolbox.

  1. loudness(frequencies, levels, field='free', ears='both'): the sound is given as sinusoidal components (Clause 5), with levels of shape (n,) for the same sound at both ears or (n, 2) for the left and right ears. field is 'free', 'diffuse' or 'eardrum', and ears='one' gives the monaural loudness. It returns N (sone), LN (phon), the specific loudness from 1.8 to 38.9 Cam and the loudness of each ear.
  2. noise_band_components(f1, f2, spectrum_level, pink=False): the components of a band of white or pink noise (5.3).
  3. third_octave_components(levels): the components of 29 one-third octave band levels from 25 Hz to 16 kHz.
  4. loudness_level(N): Table 5, linear in lg N.

The method follows the text of the standard. The sound is carried to the tympanic membrane and to the oval window (Table 1). The excitation patterns come from rounded-exponential filters whose lower slope depends on the level (Formulae (1) to (6)). The specific loudness follows Tables 2 to 4 and Formulae (7) to (9), and the binaural inhibition Formulae (10) to (13). The earphone correction files of 7.2.3 are not included. A flat response at the tympanic membrane is field='eardrum'.

Regarding the one-third octave levels, the program of Annex C (C source, downloadable from the ISO portal) does not do what the text of 5.5 describes. The text places components every 10 Hz (or 1 Hz up to 125 Hz) in base-10 bands. The program uses base-2 bands with 10 components up to 315 Hz and 20 from 400 Hz, and it produced the examples of Annex B. third_octave_components follows the program, which is also the scheme closer to those examples. The program was only read, to settle this point.

The tests in tests/test_iso532_2.py use the standard as the oracle. Its values are printed with two to four significant digits, so a value passes when it lies within one unit of the last printed digit:

  1. Every tone and multi-tone example of Annex B (B.1.1 to B.1.4 and B.3), in free field and through earphones. B.1.1 prints 8.1 sone at 70 dB, while Table 5 of the same standard gives 8.04, which is what this module gives.
  2. Every noise example (B.2.1 to B.2.5), from bands of white and pink noise and from flat one-third octave levels. B.2.5 at 0 dB is left out, because the program reads a band level of 0 as silence.
  3. All 28 rows of Table 5, which 8.2 defines as the loudness of a 1 kHz tone in free field heard with both ears, from 0 to 120 phon.
  4. The same sound at both ears is 1.5 times as loud as at one ear (1.500026), and a sound at one ear only is not inhibited.
  5. Invalid input is rejected.

The MATLAB function acousticLoudness with Method='ISO 532-2' and one-third octave input, which ita_psychoacoustic_loudness calls, gives other values than the program of the standard. For example, it gives 5.59 sone for a single 1 kHz band at 63 dB, where this module gives 5.52, and 9.32 sone for a spectrum that falls 10 dB per octave from 80 dB at 25 Hz, where this module gives 6.01. For tones, the values of this module are those of Annex B. So that function was not used as the oracle.

Checked with Python 3.12, numpy 1.26 and scipy 1.17. The 7 failures of development (3 in test_h5io.py, 4 in test_pyttasave.py) are the same with and without this change.

Co-Authored-By: Claude Fable 5.1 noreply@anthropic.com

pytta.iso532_2.loudness(frequencies, levels, field, ears) gives the
loudness and loudness level of stationary sounds by the Moore-Glasberg
method of ISO 532-2:2017, for monaural, diotic and dichotic listening:
transfer to the tympanic membrane (free field, diffuse field or
eardrum) and to the oval window (Table 1), excitation patterns from
rounded-exponential filters whose lower slope depends on the level
(Formulae (1) to (6)), specific loudness from 1.8 to 38.9 Cam (Tables 2
to 4, Formulae (7) to (9)), binaural inhibition (Formulae (10) to (13))
and the loudness level of Table 5. noise_band_components and
third_octave_components give the components of noise bands (5.3) and of
one-third octave band levels, the latter as the program of Annex C does.

Written from the text of the standard, with its program (Annex C,
downloadable from the ISO portal) read to settle the one-third octave
components, where the program and the examples of Annex B use base-2
bands with 10 or 20 components while the text of 5.5 describes
components every 10 Hz or 1 Hz.

Tests check every result of Annex B and all 28 rows of Table 5 within
one unit of the last printed digit, that the same sound at both ears is
1.5 times as loud as at one ear, that a sound at one ear only is not
inhibited, and the rejection of invalid input.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant