|
DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
|
Adaptive equalizer toward a balanced loudness shape. More...
#include <TonalBalance.h>
Public Types | |
| enum class | Reference { FlatLoudness , EvenPower } |
| What a balanced programme is (setReference()). FlatLoudness, the default: the same loudness in every band of the ear's scale. EvenPower: the loudness, band by band, of a programme with the same power in every band at this programme's level, read through the same model; it already falls where the ear's threshold climbs and follows the level (a quiet programme is not asked for the low end only a loud one can show). More... | |
| enum class | Response { ByBand , Common } |
| How the analysis follows the programme in time (setResponse()). ByBand, the default: two smoothings with the same time per band, longer in the low end (200 ms at 1 kHz, 400 ms at 100 Hz). Common: a short integration per band (a few periods of its centre, 8 to 100 ms) and then one response time for every band (setResponseTime()), so the whole curve moves together. More... | |
| enum class | Quality { Realtime , Render } |
| How often the two readings run (setQuality(); it applies at the next prepare()). Realtime, the default: the model every sixteenth of its transform, the long windows of the detail in turns. Render: the model twice as often and every window at every hop. The latency is the same in both. More... | |
Public Member Functions | |
| void | prepare (const AudioSpec &spec) |
| Allocates for a rate and a layout (an invalid spec is ignored). | |
| void | reset () noexcept |
| Clears the analysis, the corrections and the filter. | |
| void | setBalance (T amount) noexcept |
| How far the trend moves toward the reference shape, 0 to 1 (default 0.5). | |
| void | setFillDips (T amount) noexcept |
| How much dips (a detail under both of its sides, a sixth of an octave or wider) are raised, 0 to 1 (default 0.3). | |
| void | setTrimPeaks (T amount) noexcept |
| How much peaks (a detail over both of its sides) are lowered, 0 to 1 (default 0.5). | |
| void | setTilt (T dbPerOctave) noexcept |
| Tilt of the reference shape in dB per octave around 1 kHz, -6 to +6 (default 0: flat loudness per Bark); it acts through setBalance(). | |
| void | setRange (T db) noexcept |
| Largest correction of a band, 0 to 24 dB (default 6). | |
| void | setKnee (T db) noexcept |
| Knee of the balance, 0.1 to 12 dB (default 3); the dips and peaks have setContrastKnee(). | |
| void | setBalanceAsymmetry (T amount) noexcept |
| How differently the balance lifts what is lacking and lowers what is in excess, -1 to 1 (default 0: alike). Toward 1 the bands under the reference are lifted by up to twice the share setBalance() gives and those over it lowered by less, down to nothing; toward -1 the other way. The loudness is kept as always, so what changes is the shape: with a positive asymmetry a hole in the balance is filled more than a hump is cut. State key "balanceAsymmetry". | |
| void | setBalanceBias (T db) noexcept |
| Moves the point the balance tells lacking from excess at, -6 to +6 dB (default 0: the programme's own mean). Up, more of the bands count as lacking; down, more as in excess. With an asymmetry (setBalanceAsymmetry()) it decides how much of the programme is lifted and how much lowered; with the balance alike on both sides the offset that keeps the loudness takes it back but for what the knee bends. Past the range (setRange()) the corrections only meet their limits. State key "balanceBias". | |
| void | setContrastKnee (T db) noexcept |
| Knee of the dips and peaks, 0.1 to 12 dB (default 3): smaller and the ripple of a noisy programme is followed, larger and only what stands well out is touched. | |
| void | setDetail (T octaves) noexcept |
| The detail: how finely the peaks and the dips (these no finer than a sixth, so that the space between partials is not raised) are read, played and drawn over the whole band, an octave to 1/24 (default 1/4). It moves while playing, at the same latency; the balance and the loudness go by the 72 bands of the ear whatever it is. The finer, the more the trim takes single partials, and what keeps the loudness then lifts the space between them with the rest. | |
| void | setRangeKnee (T db) noexcept |
| Rounds the approach to the range, 0 to 6 dB (0, the default, is the hard limit): a correction that grows (a dip that deepens) bends into the range through a second knee and settles on it, with no corner. | |
| void | setFloor (T db) noexcept |
| How far under its loudest band (in the model's level) a band may lie and still be given back by the balance, 10 to 120 dB (default 30). What lies further down is the floor of a recording or the end of the content: the balance leaves it where it is, and it takes no part in keeping the loudness. The last 10 dB over the floor fade in. A dip between two sides that sound is filled whatever its depth. | |
| void | setFrequencyRange (T loHz, T hiHz) noexcept |
| Frequencies the corrections act on, with edges one Bark wide (default 40 Hz to 16 kHz: the ends of the band, where the threshold in quiet climbs, are left alone). | |
| void | setReference (Reference r) noexcept |
| The shape the programme is compared against (see Reference; out-of-range values read as FlatLoudness). | |
| void | setQuality (Quality q) noexcept |
| Realtime or Render (see Quality; applies at the next prepare()). | |
| void | setQualityFollowsRender (bool on) noexcept |
| With it on, a prepare() made while the host renders offline (setOfflineRendering(true)) takes the Render quality whatever setQuality() says (off by default). | |
| void | setOfflineRendering (bool on) noexcept |
| Tells the processor whether the host renders offline (read by the next prepare()). | |
| void | setResponse (Response r) noexcept |
| How the analysis follows the programme in time (see Response; out-of-range values read as ByBand). | |
| void | setResponseTime (T ms) noexcept |
| The response time of Response::Common, 10 to 2000 ms (default 60). | |
| void | setListeningCompensation (T db) noexcept |
| Compensates a listening level this many dB lower than the one the programme is balanced at, -30 to +30 (default 0). The ear loses the two ends first as the level falls (their loudness grows faster with level), so each band is raised by the level times one minus the ratio of the mid exponent to its own: with 20 dB, 4.7 dB at 50 Hz and 3.3 dB at 12 kHz against 1.2 dB at 1 kHz, before the offset that keeps the total loudness (the volume does not change). Negative values compensate a louder listening. Limited by setRange() like every correction. | |
| void | setLevelCompensation (bool on) noexcept |
| Loudness to decibels with each band's exponent (default off: one exponent). | |
| void | setLocalSlope (bool on) noexcept |
| Loudness to decibels with the slope of the loudness curve at each band's own level (default off): what a band lacks or has in excess is read with that slope, and so is the offset that keeps the loudness. Well over the threshold in quiet that slope is the band's exponent; near it a band's loudness grows faster with its power (the slope is twice the exponent 10 dB over the threshold, 1.45 times 20 dB over), and a fixed exponent overstates what the band lacks: the ends of a quiet programme are asked for less. | |
| void | setTimeFocus (bool on) noexcept |
| Reads each band through a stretch of the analysis window of its own, shorter as frequency rises (SpectralFocus; default off: the whole window at every frequency). The low end keeps its resolution in frequency and the top reads a change of the programme from a stretch of a couple of milliseconds, which shows with a short response (Response::Common at 10 ms: a turn from dark to bright is followed at 8 kHz in 20 ms in place of 28). On a steady programme the corrections are the same (within 0.03 dB). | |
| void | setReferenceLevel (T dbSpl) noexcept |
| The SPL a full-scale sine stands for, 60 to 130 dB (default 100). | |
| T | getBalance () const noexcept |
| T | getFillDips () const noexcept |
| T | getTrimPeaks () const noexcept |
| T | getTilt () const noexcept |
| T | getRange () const noexcept |
| T | getKnee () const noexcept |
| T | getBalanceAsymmetry () const noexcept |
| T | getBalanceBias () const noexcept |
| T | getContrastKnee () const noexcept |
| T | getDetail () const noexcept |
| T | getRangeKnee () const noexcept |
| T | getFloor () const noexcept |
| T | getLowFrequency () const noexcept |
| T | getHighFrequency () const noexcept |
| bool | getLevelCompensation () const noexcept |
| bool | getLocalSlope () const noexcept |
| bool | getTimeFocus () const noexcept |
| Reference | getReference () const noexcept |
| Response | getResponse () const noexcept |
| Quality | getQuality () const noexcept |
| bool | getQualityFollowsRender () const noexcept |
| Quality | getQualityInUse () const noexcept |
| T | getResponseTime () const noexcept |
| T | getListeningCompensation () const noexcept |
| T | getReferenceLevel () const noexcept |
| int | getLatency () const noexcept |
| double | getBandCentre (int band) const noexcept |
| T | getCorrection (int band) const noexcept |
| T | getDisplayCorrection (int point) const noexcept |
| T | getLoudnessChange () const noexcept |
| T | getLoudnessRaised () const noexcept |
| T | getLoudnessLowered () const noexcept |
| T | getLoudness () const noexcept |
| T | getCentroidShift () const noexcept |
| double | getResponse (double hz) const noexcept |
| void | processBlock (AudioBufferView< T > buffer) noexcept |
| Analyses and equalizes the programme in place. | |
| void | processBlock (AudioBufferView< T > buffer, AudioBufferView< T > key) noexcept |
| Equalizes the programme by the analysis of a key (same channels or one). | |
| std::vector< uint8_t > | getState () const |
| bool | setState (const uint8_t *data, size_t size) |
| Restores the settings. A blob of the first version gives the default detail, or a third, a sixth or a twelfth of an octave when it saved one of three steps. | |
Static Public Member Functions | |
| static constexpr int | getNumBands () noexcept |
| static double | getDisplayFrequency (int point) noexcept |
Static Public Attributes | |
| static constexpr int | kBands = 72 |
| Bands of the loudness model. | |
| static constexpr int | kMaxChannels = 2 |
| Channels analysed (the others take the same curve). | |
| static constexpr int | kDisplayPoints = SpectralReadout<T>::kPoints |
| Points of the display curve, evenly in log frequency from 20 Hz to 20 kHz. | |
Adaptive equalizer toward a balanced loudness shape.
| T | Sample type (float or double). |
Definition at line 125 of file TonalBalance.h.
|
strong |
How often the two readings run (setQuality(); it applies at the next prepare()). Realtime, the default: the model every sixteenth of its transform, the long windows of the detail in turns. Render: the model twice as often and every window at every hop. The latency is the same in both.
| Enumerator | |
|---|---|
| Realtime | |
| Render | |
Definition at line 158 of file TonalBalance.h.
|
strong |
What a balanced programme is (setReference()). FlatLoudness, the default: the same loudness in every band of the ear's scale. EvenPower: the loudness, band by band, of a programme with the same power in every band at this programme's level, read through the same model; it already falls where the ear's threshold climbs and follows the level (a quiet programme is not asked for the low end only a loud one can show).
| Enumerator | |
|---|---|
| FlatLoudness | |
| EvenPower | |
Definition at line 139 of file TonalBalance.h.
|
strong |
How the analysis follows the programme in time (setResponse()). ByBand, the default: two smoothings with the same time per band, longer in the low end (200 ms at 1 kHz, 400 ms at 100 Hz). Common: a short integration per band (a few periods of its centre, 8 to 100 ms) and then one response time for every band (setResponseTime()), so the whole curve moves together.
| Enumerator | |
|---|---|
| ByBand | |
| Common | |
Definition at line 149 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 381 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 387 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 388 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 413 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 447 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 389 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 419 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 390 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 428 of file TonalBalance.h.
|
inlinestaticnoexcept |
Definition at line 426 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 382 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 394 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 396 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 386 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 411 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 397 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 407 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 398 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 445 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 435 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 443 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 441 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 395 of file TonalBalance.h.
|
inlinestaticconstexprnoexcept |
Definition at line 392 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 402 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 403 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 405 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 385 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 393 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 400 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 408 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 401 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 449 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 406 of file TonalBalance.h.
|
inline |
Definition at line 471 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 384 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 399 of file TonalBalance.h.
|
inlinenoexcept |
Definition at line 383 of file TonalBalance.h.
|
inline |
Allocates for a rate and a layout (an invalid spec is ignored).
Definition at line 162 of file TonalBalance.h.
|
inlinenoexcept |
Analyses and equalizes the programme in place.
Definition at line 461 of file TonalBalance.h.
|
inlinenoexcept |
Equalizes the programme by the analysis of a key (same channels or one).
Definition at line 464 of file TonalBalance.h.
|
inlinenoexcept |
Clears the analysis, the corrections and the filter.
Definition at line 220 of file TonalBalance.h.
|
inlinenoexcept |
How far the trend moves toward the reference shape, 0 to 1 (default 0.5).
Definition at line 241 of file TonalBalance.h.
|
inlinenoexcept |
How differently the balance lifts what is lacking and lowers what is in excess, -1 to 1 (default 0: alike). Toward 1 the bands under the reference are lifted by up to twice the share setBalance() gives and those over it lowered by less, down to nothing; toward -1 the other way. The loudness is kept as always, so what changes is the shape: with a positive asymmetry a hole in the balance is filled more than a hump is cut. State key "balanceAsymmetry".
Definition at line 261 of file TonalBalance.h.
|
inlinenoexcept |
Moves the point the balance tells lacking from excess at, -6 to +6 dB (default 0: the programme's own mean). Up, more of the bands count as lacking; down, more as in excess. With an asymmetry (setBalanceAsymmetry()) it decides how much of the programme is lifted and how much lowered; with the balance alike on both sides the offset that keeps the loudness takes it back but for what the knee bends. Past the range (setRange()) the corrections only meet their limits. State key "balanceBias".
Definition at line 272 of file TonalBalance.h.
|
inlinenoexcept |
Knee of the dips and peaks, 0.1 to 12 dB (default 3): smaller and the ripple of a noisy programme is followed, larger and only what stands well out is touched.
Definition at line 278 of file TonalBalance.h.
|
inlinenoexcept |
The detail: how finely the peaks and the dips (these no finer than a sixth, so that the space between partials is not raised) are read, played and drawn over the whole band, an octave to 1/24 (default 1/4). It moves while playing, at the same latency; the balance and the loudness go by the 72 bands of the ear whatever it is. The finer, the more the trim takes single partials, and what keeps the loudness then lifts the space between them with the rest.
Definition at line 289 of file TonalBalance.h.
|
inlinenoexcept |
How much dips (a detail under both of its sides, a sixth of an octave or wider) are raised, 0 to 1 (default 0.3).
Definition at line 243 of file TonalBalance.h.
|
inlinenoexcept |
How far under its loudest band (in the model's level) a band may lie and still be given back by the balance, 10 to 120 dB (default 30). What lies further down is the floor of a recording or the end of the content: the balance leaves it where it is, and it takes no part in keeping the loudness. The last 10 dB over the floor fade in. A dip between two sides that sound is filled whatever its depth.
Definition at line 309 of file TonalBalance.h.
|
inlinenoexcept |
Frequencies the corrections act on, with edges one Bark wide (default 40 Hz to 16 kHz: the ends of the band, where the threshold in quiet climbs, are left alone).
Definition at line 311 of file TonalBalance.h.
|
inlinenoexcept |
Knee of the balance, 0.1 to 12 dB (default 3); the dips and peaks have setContrastKnee().
Definition at line 251 of file TonalBalance.h.
|
inlinenoexcept |
Loudness to decibels with each band's exponent (default off: one exponent).
Definition at line 353 of file TonalBalance.h.
|
inlinenoexcept |
Compensates a listening level this many dB lower than the one the programme is balanced at, -30 to +30 (default 0). The ear loses the two ends first as the level falls (their loudness grows faster with level), so each band is raised by the level times one minus the ratio of the mid exponent to its own: with 20 dB, 4.7 dB at 50 Hz and 3.3 dB at 12 kHz against 1.2 dB at 1 kHz, before the offset that keeps the total loudness (the volume does not change). Negative values compensate a louder listening. Limited by setRange() like every correction.
Definition at line 351 of file TonalBalance.h.
|
inlinenoexcept |
Loudness to decibels with the slope of the loudness curve at each band's own level (default off): what a band lacks or has in excess is read with that slope, and so is the offset that keeps the loudness. Well over the threshold in quiet that slope is the band's exponent; near it a band's loudness grows faster with its power (the slope is twice the exponent 10 dB over the threshold, 1.45 times 20 dB over), and a fixed exponent overstates what the band lacks: the ends of a quiet programme are asked for less.
Definition at line 365 of file TonalBalance.h.
|
inlinenoexcept |
Tells the processor whether the host renders offline (read by the next prepare()).
Definition at line 332 of file TonalBalance.h.
|
inlinenoexcept |
Realtime or Render (see Quality; applies at the next prepare()).
Definition at line 324 of file TonalBalance.h.
|
inlinenoexcept |
With it on, a prepare() made while the host renders offline (setOfflineRendering(true)) takes the Render quality whatever setQuality() says (off by default).
Definition at line 330 of file TonalBalance.h.
|
inlinenoexcept |
Largest correction of a band, 0 to 24 dB (default 6).
Definition at line 249 of file TonalBalance.h.
|
inlinenoexcept |
Rounds the approach to the range, 0 to 6 dB (0, the default, is the hard limit): a correction that grows (a dip that deepens) bends into the range through a second knee and settles on it, with no corner.
Definition at line 299 of file TonalBalance.h.
|
inlinenoexcept |
The shape the programme is compared against (see Reference; out-of-range values read as FlatLoudness).
Definition at line 319 of file TonalBalance.h.
|
inlinenoexcept |
The SPL a full-scale sine stands for, 60 to 130 dB (default 100).
Definition at line 379 of file TonalBalance.h.
|
inlinenoexcept |
How the analysis follows the programme in time (see Response; out-of-range values read as ByBand).
Definition at line 334 of file TonalBalance.h.
|
inlinenoexcept |
The response time of Response::Common, 10 to 2000 ms (default 60).
Definition at line 339 of file TonalBalance.h.
|
inline |
Restores the settings. A blob of the first version gives the default detail, or a third, a sixth or a twelfth of an octave when it saved one of three steps.
Definition at line 506 of file TonalBalance.h.
|
inlinenoexcept |
Tilt of the reference shape in dB per octave around 1 kHz, -6 to +6 (default 0: flat loudness per Bark); it acts through setBalance().
Definition at line 247 of file TonalBalance.h.
|
inlinenoexcept |
Reads each band through a stretch of the analysis window of its own, shorter as frequency rises (SpectralFocus; default off: the whole window at every frequency). The low end keeps its resolution in frequency and the top reads a change of the programme from a stretch of a couple of milliseconds, which shows with a short response (Response::Common at 10 ms: a turn from dark to bright is followed at 8 kHz in 20 ms in place of 28). On a steady programme the corrections are the same (within 0.03 dB).
Definition at line 377 of file TonalBalance.h.
|
inlinenoexcept |
How much peaks (a detail over both of its sides) are lowered, 0 to 1 (default 0.5).
Definition at line 245 of file TonalBalance.h.
|
staticconstexpr |
Bands of the loudness model.
Definition at line 128 of file TonalBalance.h.
|
staticconstexpr |
Points of the display curve, evenly in log frequency from 20 Hz to 20 kHz.
Definition at line 424 of file TonalBalance.h.
|
staticconstexpr |
Channels analysed (the others take the same curve).
Definition at line 159 of file TonalBalance.h.