Table of Contents

Class SynthMath

Namespace
NAudio.Dsp
Assembly
NAudio.Core.dll

Conversions between the musical / MIDI domain and the DSP domain that a sampler or synthesiser needs: note numbers, frequencies, cents, timecents and centibels. These are the units SoundFont generators and SFZ opcodes are expressed in, but the helpers are deliberately format-neutral so any instrument can share them.

public static class SynthMath
Inheritance
SynthMath
Inherited Members

Fields

MidiNote0Frequency

Frequency in Hz of MIDI note 0 (C-1), i.e. the reference used by the SoundFont "absolute cents" pitch scale. Equal to 440 * 2^((0-69)/12).

public const double MidiNote0Frequency = 8.175798915643707

Field Value

double

Methods

AbsoluteCentsToHertz(double)

Converts a SoundFont "absolute cents" value to a frequency in Hz. Used for filter cutoff and LFO/envelope-to-pitch destinations. 6900 absolute cents = 440 Hz.

public static double AbsoluteCentsToHertz(double absoluteCents)

Parameters

absoluteCents double

Returns

double

AttenuationCentibelsToGain(double)

Converts a SoundFont attenuation in centibels to a linear gain multiplier. Attenuation reduces level, so 0 cB = unity gain and larger values are quieter (gain = 10^(-cB/200)).

public static double AttenuationCentibelsToGain(double centibels)

Parameters

centibels double

Returns

double

CentibelsToGain(double)

Converts a level expressed in centibels (1/10th of a decibel) to a linear gain multiplier, where positive centibels mean louder.

public static double CentibelsToGain(double centibels)

Parameters

centibels double

Returns

double

CentsToRatio(double)

Converts a pitch offset in cents (1/100th of a semitone) to a linear frequency ratio. 1200 cents = one octave = a ratio of 2.

public static double CentsToRatio(double cents)

Parameters

cents double

Returns

double

DecibelsToGain(double)

Converts a level in decibels to a linear gain multiplier.

public static double DecibelsToGain(double decibels)

Parameters

decibels double

Returns

double

FrequencyToMidiNote(double)

Converts a frequency in Hz to a (fractional) MIDI note number.

public static double FrequencyToMidiNote(double frequency)

Parameters

frequency double

Returns

double

GainToDecibels(double)

Converts a linear gain multiplier to decibels.

public static double GainToDecibels(double gain)

Parameters

gain double

Returns

double

HertzToAbsoluteCents(double)

Converts a frequency in Hz to SoundFont "absolute cents".

public static double HertzToAbsoluteCents(double hertz)

Parameters

hertz double

Returns

double

MidiNoteToFrequency(double)

Converts a MIDI note number to a frequency in Hz (A4 = note 69 = 440 Hz). The note may be fractional to express detuning.

public static double MidiNoteToFrequency(double midiNote)

Parameters

midiNote double

Returns

double

RatioToCents(double)

Converts a frequency ratio to a pitch offset in cents.

public static double RatioToCents(double ratio)

Parameters

ratio double

Returns

double

ResonanceCentibelsToQ(double)

Converts a SoundFont filter resonance (initialFilterQ) in centibels to a linear biquad Q value. The input is clamped to the spec range of 0..960 cB (SF2.04 §8.1.2 gen 8) so malformed values cannot reach float infinity. 0 cB means a flat, non-resonant response, so the mapping subtracts 3.01 dB before converting — Q = 10^((cB/10 - 3.01)/20) — giving the Butterworth Q of ~0.707 at 0 cB (the convention FluidSynth also documents for this generator).

public static double ResonanceCentibelsToQ(double centibels)

Parameters

centibels double

Returns

double

SecondsToTimecents(double)

Converts a duration in seconds to timecents.

public static double SecondsToTimecents(double seconds)

Parameters

seconds double

Returns

double

TimecentsToSeconds(double)

Converts a duration expressed in timecents to seconds. Timecents are the units SoundFont envelope stages (delay/attack/hold/decay/release) use: seconds = 2^(timecents/1200), so 0 timecents = 1 second.

public static double TimecentsToSeconds(double timecents)

Parameters

timecents double

Returns

double