pitch
Overview
pitch
is determined by its position on the chromatic scale, which is a system of 12 notes that repeat in octaves. The distance between each pitch on the chromatic scale is a semitone, and each pitch represents a specific frequency measured in hertz (Hz).
pitch
is an interval
with a base frequency of 8.1757989156437
Hz that correspond to MIDI note 0 (which is an octave below F#0). pitch
is represented by the MIDI value. Therefore, only positive values are valid.
pitch
includes construction from frequency
as well as numeric values representing the absolute position in the chromatic scale from the base frequency. pitch
also includes conversions to frequency
.
Conversions to and from frequency
utilize fast log2
and pow2
computations using fast math functions.
Declaration
struct pitch : interval
{
constexpr static auto base_frequency = frequency{8.1757989156437};
constexpr pitch();
explicit pitch(frequency f);
constexpr bool valid() const;
// These operations do not make sense and are not allowed.
pitch& operator+=(pitch) = delete;
pitch& operator-=(pitch) = delete;
};
// Free functions
frequency as_frequency(pitch n);
float as_float(pitch n);
double as_double(pitch n);
constexpr pitch round(pitch n);
constexpr pitch ceil(pitch n);
constexpr pitch floor(pitch n);
// These operations do not make sense and are not allowed.
pitch operator+(pitch, pitch) = delete;
pitch operator-(pitch, pitch) = delete;
Expressions
In addition to valid expressions for interval
, pitch
allows these expressions.
Constructors
Expression | Semantics |
---|---|
|
Construct a |
|
Default construct a |
C++ brace initialization may also be used. |
Conversions
Expression | Semantics | Return Type |
---|---|---|
|
Convert |
|
|
Convert |
|
|
Convert |
|
Functions
Expression | Semantics | Return Type |
---|---|---|
|
Returns |
|
|
Rounds |
|
|
Returns the smallest non-fractional
pitch that is greater than or equal
|
|
|
Returns the largest non-fractional
pitch that is less than or equal
|
|