chenlh
2026-03-26 36e42207da4c088b5bfd96f2cfc8944f890440d7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#pragma once
 
#include <cmath>
 
/**
 * Struct wrapping inline functions for manipulating Audio Buffer sample levels.
 */
template <typename SampleType>
struct GainUtilities
{
    /**
     * @brief Converts linear gain values to decibels
     * 
     * @param gainValue Linear gain value
     */
    static inline SampleType gainToDecibels(SampleType gainValue)
    {
        return 20.0 * log10(gainValue);
    };
 
    /**
     * @brief Converts decibel values to linear gain
     * 
     * @param dbValue Decibel value
     */
    static inline SampleType decibelsToGain(SampleType dbValue)
    {
        return pow(10.0, dbValue / 20.0);
    };
};