| 1 | package Peta::Hearing; | ||||||||||||||
| 2 | # ABSTRACT: the Bark scale, the threshold in quiet, masking | ||||||||||||||
| 3 | |||||||||||||||
| 4 | # What the encoders' psychoacoustic models share: the Bark scale, the | ||||||||||||||
| 5 | # threshold of hearing in quiet, how far masking spreads, and how far below | ||||||||||||||
| 6 | # a masker noise stays unheard. | ||||||||||||||
| 7 | |||||||||||||||
| 8 | 2 | ▶ | use v5.36; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 2 | our $VERSION = '0.2610180'; | |||||||||||||
| 11 | |||||||||||||||
| 12 | # The offset for noise masking noise, in dB. ISO's model 2 has 6 dB; 2 dB | ||||||||||||||
| 13 | # more, as quantization rounds much of a noise band to nothing (energy | ||||||||||||||
| 14 | # lost, not noise added), which 8 dB keeps to about a dB. | ||||||||||||||
| 15 | 2 | ▶ | use constant NOISE_OFFSET => 8; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | |||||||||||||||
| 17 | # A frequency (Hz) on the Bark scale (Zwicker and Terhardt). | ||||||||||||||
| 18 | 5209 | ▶ | sub bark ($f) { | ||||||||||||
|
Subroutine
bark: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 19 | 5209 | return 13 * atan2(0.00076 * $f, 1) + 3.5 * atan2(($f / 7500)**2, 1); | |||||||||||||
| 20 | } | ||||||||||||||
| 21 | |||||||||||||||
| 22 | # The threshold of hearing in quiet at a frequency, in dB SPL (Terhardt); | ||||||||||||||
| 23 | # held below 20 Hz and above 16 kHz. | ||||||||||||||
| 24 | 13824 | ▶ | sub quiet ($f) { | ||||||||||||
|
Subroutine
quiet: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||
| 25 | 13824 | ▶ | my $k = ($f < 20 ? 20 : $f > 16000 ? 16000 : $f) / 1000; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 26 | 13824 | return 3.64 * $k**-0.8 - 6.5 * exp(-0.6 * ($k - 3.3)**2) + 0.001 * $k**4; | |||||||||||||
| 27 | } | ||||||||||||||
| 28 | |||||||||||||||
| 29 | # How much of a masker's energy reaches $dz Bark above it (below, for | ||||||||||||||
| 30 | # $dz < 0), as an energy factor: Schroeder's spreading function, nothing | ||||||||||||||
| 31 | # under -60 dB. | ||||||||||||||
| 32 | 12295 | ▶ | sub spreading ($dz) { | ||||||||||||
|
Subroutine
spreading: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 33 | 12295 | $dz += 0.474; | |||||||||||||
| 34 | 12295 | my $db = 15.81 + 7.5 * $dz - 17.5 * sqrt(1 + $dz * $dz); | |||||||||||||
| 35 | 12295 | ▶ | return $db < -60 ? 0.0 : 10**($db / 10); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 36 | } | ||||||||||||||
| 37 | |||||||||||||||
| 38 | # How far below a tone at $z Bark noise stays unheard, in dB: 14.5 plus the | ||||||||||||||
| 39 | # Bark, at most 25. | ||||||||||||||
| 40 | 625 | ▶ | sub tone_offset ($z) { | ||||||||||||
|
Subroutine
tone_offset: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 41 | 625 | my $db = 14.5 + $z; | |||||||||||||
| 42 | 625 | ▶ | return $db > 25 ? 25 : $db; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 43 | } | ||||||||||||||
| 44 | |||||||||||||||
| 45 | 2 | 1; | |||||||||||||
| 46 | |||||||||||||||
| 47 | __END__ | ||||||||||||||