SoundFontInfoLib  2.21.6
Library for parsing and rendering SF2 files
SF2::DSP Namespace Reference

Collection of general-purpose constants and routines involved in audio rendering. More...

Namespaces

 Interpolation
 
 Tables
 Namespace for compile-time generated tables.
 

Functions

Float centsToSeconds (Float value)
 Convert cents value into seconds, where There are 1200 cents per power of 2. More...
 
Float centsToPower2 (Float value)
 Convert cents value into a power of 2. More...
 
Float absoluteCentsToFrequency (Float value)
 Convert cents to frequency, with 0 being 8.175798 Hz. More...
 
Float centibelsToAttenuation (Float centibels)
 Convert centiBels to attenuation, where 60 corresponds to a drop of 6dB or 0.5 reduction of audio samples. More...
 
Float clampFilterCutoff (Float value)
 Restrict lowpass filter cutoff value to be between 1500 and 13500, inclusive. More...
 
Float tenthPercentage (Float value)
 Convert integer from integer [0-1000] into [0.0-1.0]. More...
 
Float unipolarToBipolar (Float modulator)
 Translate value in range [0, +1] into one in range [-1, +1]. More...
 
Float bipolarToUnipolar (Float modulator)
 Translate value in range [-1, +1] into one in range [0, +1]. More...
 
Float unipolarModulate (Float modulator, Float minValue, Float maxValue)
 Perform linear translation from a value in range [0.0, 1.0] into one in [minValue, maxValue]. More...
 
Float bipolarModulate (Float modulator, Float minValue, Float maxValue)
 Perform linear translation from a value in range [-1.0, 1.0] into one in [minValue, maxValue]. More...
 
constexpr Float parabolicSine (Float angle)
 Estimate sin() value from a radian angle between -PI and PI. More...
 
void panLookup (Float pan, Float &left, Float &right)
 Calculate the amount of left and right signal gain in [0.0-1.0] for the given pan value which is in range [-500-+500]. More...
 
Float sineLookup (Float radians)
 Obtain approximate sine value from table. More...
 
Float centsToFrequencyMultiplier (int cent)
 Convert given cents value into a frequency multiplier. More...
 
Float centsToFrequency (Float value)
 Quickly convert cent value into a frequency using a table lookup. More...
 
Float centibelsToAttenuation (int centibels)
 Convert centibels [0-1441] into an attenuation value from [1.0-0.0]. More...
 
Float centibelsToGain (Float centibels)
 Convert centibels [0-1441] into a gain value [0.0-1.0]. More...
 

Variables

constexpr Float PI = M_PI
 
constexpr Float TwoPI = 2.0 * PI
 
constexpr Float HalfPI = PI / 2.0
 
constexpr Float QuarterPI = PI / 4.0
 
constexpr Float ReferenceNoteFrequency = 440.0
 
constexpr Float ReferenceNoteMIDI = 69.0
 
constexpr Float ReferenceNoteSemi = ReferenceNoteMIDI * 100
 
constexpr int CentsPerSemitone = 100
 
constexpr int SemitonePerOctave = 12
 
constexpr int CentsPerOctave = 1200
 
constexpr Float CentibelsPerDecade = 200.0
 
constexpr Float CentsToFrequencyMin = -16000
 
constexpr Float CentsToFrequencyMax = 4500
 
constexpr Float LowestNoteFrequency = 8.17579891564370697665253828745335
 
constexpr Float HalfSquareRoot2 = M_SQRT2 / 2.0
 
constexpr Float InterNoteMultiplier = 1.05946309435929530984310531493975
 

Detailed Description

Collection of general-purpose constants and routines involved in audio rendering.

Function Documentation

◆ absoluteCentsToFrequency()

Float SF2::DSP::absoluteCentsToFrequency ( Float  value)
inline

Convert cents to frequency, with 0 being 8.175798 Hz.

Values are clamped to [-16000, 4500].

Parameters
valuethe value to convert
Returns
frequency in Hz

References CentsToFrequencyMax, CentsToFrequencyMin, centsToPower2(), ReferenceNoteFrequency, and ReferenceNoteSemi.

◆ bipolarModulate()

Float SF2::DSP::bipolarModulate ( Float  modulator,
Float  minValue,
Float  maxValue 
)
inline

Perform linear translation from a value in range [-1.0, 1.0] into one in [minValue, maxValue].

Parameters
modulatorthe value to translate
minValuethe lowest value to return when modulator is -1
maxValuethe highest value to return when modulator is +1
Returns
value in range [minValue, maxValue]

◆ bipolarToUnipolar()

Float SF2::DSP::bipolarToUnipolar ( Float  modulator)
inline

Translate value in range [-1, +1] into one in range [0, +1].

Parameters
modulatorthe value to translate
Returns
value in range [0, +1]

◆ centibelsToAttenuation() [1/2]

Float SF2::DSP::centibelsToAttenuation ( Float  centibels)
inline

Convert centiBels to attenuation, where 60 corresponds to a drop of 6dB or 0.5 reduction of audio samples.

Note that for raw generator values in an SF2 file, better to use the centibelsToAttenuation(int) value below.

Parameters
centibelsthe value to convert
Returns
attenuation amount

References CentibelsPerDecade.

◆ centibelsToAttenuation() [2/2]

Float SF2::DSP::centibelsToAttenuation ( int  centibels)
inline

Convert centibels [0-1441] into an attenuation value from [1.0-0.0].

Zero indicates no attenuation (1.0), 60 is 0.5, and every 200 is a reduction by 10 (0.1, 0.001, etc.)

Parameters
centibelsvalue to convert
Returns
gain value

References SF2::DSP::Tables::AttenuationLookup::convert().

◆ centibelsToGain()

Float SF2::DSP::centibelsToGain ( Float  centibels)
inline

Convert centibels [0-1441] into a gain value [0.0-1.0].

This is the inverse of the above.

Parameters
centibelsvalue to convert
Returns
gain value

References SF2::DSP::Tables::GainLookup::convert().

◆ centsToFrequency()

Float SF2::DSP::centsToFrequency ( Float  value)
inline

Quickly convert cent value into a frequency using a table lookup.

These calculations are taken from the Fluid Synth fluid_conv.c file, in particular the fluid_ct2hz_real function. Uses CentPartialLookup above to convert values from 0 - 1199 into the proper multiplier.

References SF2::DSP::Tables::CentsPartialLookup::convert().

Referenced by SF2::Entity::Generator::Definition::convertedValueOf().

◆ centsToFrequencyMultiplier()

Float SF2::DSP::centsToFrequencyMultiplier ( int  cent)
inline

Convert given cents value into a frequency multiplier.

Parameters
centthe value to convert
Returns
multiplier for a frequency that will change the frequency by the given cent value

References SF2::DSP::Tables::CentsFrequencyLookup::convert().

◆ centsToPower2()

Float SF2::DSP::centsToPower2 ( Float  value)
inline

Convert cents value into a power of 2.

There are 1200 cents per power of 2.

Parameters
valuethe value to convert
Returns
power of 2 value

References CentsPerOctave.

Referenced by absoluteCentsToFrequency().

◆ centsToSeconds()

Float SF2::DSP::centsToSeconds ( Float  value)
inline

Convert cents value into seconds, where There are 1200 cents per power of 2.

Parameters
valuethe number to convert

Referenced by SF2::Entity::Generator::Definition::convertedValueOf(), SF2::Render::Envelope::Generator::Modulator(), and SF2::Render::Envelope::Generator::Volume().

◆ clampFilterCutoff()

Float SF2::DSP::clampFilterCutoff ( Float  value)
inline

Restrict lowpass filter cutoff value to be between 1500 and 13500, inclusive.

Parameters
valuecutoff value
Returns
clamped cutoff value

◆ panLookup()

void SF2::DSP::panLookup ( Float  pan,
Float left,
Float right 
)
inline

Calculate the amount of left and right signal gain in [0.0-1.0] for the given pan value which is in range [-500-+500].

A pan of -500 is only left, and +500 is only right. A pan of 0 should result in ~0.7078 for both.

Parameters
panthe value to convert
leftreference to storage for the left gain
rightreference to storage for the right gain

References SF2::DSP::Tables::PanLookup::lookup().

◆ parabolicSine()

constexpr Float SF2::DSP::parabolicSine ( Float  angle)
constexpr

Estimate sin() value from a radian angle between -PI and PI.

Derived from code in "Designing Audio Effect Plugins in C++" by Will C. Pirkle (2019) As can be seen in the unit test testParabolicSineAccuracy, the worst-case deviation from std::sin is ~0.0011.

Parameters
anglevalue between -PI and PI
Returns
approximate sin value

◆ sineLookup()

Float SF2::DSP::sineLookup ( Float  radians)
inline

Obtain approximate sine value from table.

Parameters
radiansthe value to use for theta
Returns
the sine approximation

References SF2::DSP::Tables::SineLookup::sine().

◆ tenthPercentage()

Float SF2::DSP::tenthPercentage ( Float  value)
inline

Convert integer from integer [0-1000] into [0.0-1.0].

Parameters
valuepercentage value expressed as tenths
Returns
normalized value between 0 and 1.

◆ unipolarModulate()

Float SF2::DSP::unipolarModulate ( Float  modulator,
Float  minValue,
Float  maxValue 
)
inline

Perform linear translation from a value in range [0.0, 1.0] into one in [minValue, maxValue].

Parameters
modulatorthe value to translate
minValuethe lowest value to return when modulator is 0
maxValuethe highest value to return when modulator is +1
Returns
value in range [minValue, maxValue]

◆ unipolarToBipolar()

Float SF2::DSP::unipolarToBipolar ( Float  modulator)
inline

Translate value in range [0, +1] into one in range [-1, +1].

Parameters
modulatorthe value to translate
Returns
value in range [-1, +1]

Referenced by SF2::DSP::Tables::Generator::generateTransform().

Variable Documentation

◆ CentibelsPerDecade

constexpr Float SF2::DSP::CentibelsPerDecade = 200.0
inlineconstexpr

Referenced by centibelsToAttenuation().

◆ CentsPerOctave

constexpr int SF2::DSP::CentsPerOctave = 1200
inlineconstexpr

Referenced by centsToPower2().

◆ CentsPerSemitone

constexpr int SF2::DSP::CentsPerSemitone = 100
inlineconstexpr

◆ CentsToFrequencyMax

constexpr Float SF2::DSP::CentsToFrequencyMax = 4500
inlineconstexpr

◆ CentsToFrequencyMin

constexpr Float SF2::DSP::CentsToFrequencyMin = -16000
inlineconstexpr

◆ HalfPI

constexpr Float SF2::DSP::HalfPI = PI / 2.0
inlineconstexpr

◆ HalfSquareRoot2

constexpr Float SF2::DSP::HalfSquareRoot2 = M_SQRT2 / 2.0
inlineconstexpr

◆ InterNoteMultiplier

constexpr Float SF2::DSP::InterNoteMultiplier = 1.05946309435929530984310531493975
inlineconstexpr

◆ LowestNoteFrequency

constexpr Float SF2::DSP::LowestNoteFrequency = 8.17579891564370697665253828745335
inlineconstexpr

◆ PI

constexpr Float SF2::DSP::PI = M_PI
inlineconstexpr

◆ QuarterPI

constexpr Float SF2::DSP::QuarterPI = PI / 4.0
inlineconstexpr

◆ ReferenceNoteFrequency

constexpr Float SF2::DSP::ReferenceNoteFrequency = 440.0
inlineconstexpr

◆ ReferenceNoteMIDI

constexpr Float SF2::DSP::ReferenceNoteMIDI = 69.0
inlineconstexpr

◆ ReferenceNoteSemi

constexpr Float SF2::DSP::ReferenceNoteSemi = ReferenceNoteMIDI * 100
inlineconstexpr

◆ SemitonePerOctave

constexpr int SF2::DSP::SemitonePerOctave = 12
inlineconstexpr

◆ TwoPI

constexpr Float SF2::DSP::TwoPI = 2.0 * PI
inlineconstexpr