|
frequency 1.2.1
Type-safe frequency handling library modeled after std::chrono
|
Frequency types and utilities. More...
Classes | |
| class | frequency |
| A frequency value with a representation and precision. More... | |
| struct | is_frequency |
| Trait to detect frequency specializations. More... | |
| struct | is_frequency< frequency< Rep, Precision > > |
Typedefs | |
| using | millihertz = frequency< int64_t, std::milli > |
| Frequency with 0.001 Hz (millihertz) precision. | |
| using | hertz = frequency< int64_t > |
| Frequency with 1 Hz precision. | |
| using | kilohertz = frequency< int64_t, std::kilo > |
| Frequency with 1000 Hz (kilohertz) precision. | |
| using | megahertz = frequency< int64_t, std::mega > |
| Frequency with 1,000,000 Hz (megahertz) precision. | |
| using | gigahertz = frequency< int64_t, std::giga > |
| Frequency with 1,000,000,000 Hz (gigahertz) precision. | |
| using | terahertz = frequency< int64_t, std::tera > |
| Frequency with 1,000,000,000,000 Hz (terahertz) precision. | |
Variables | |
| template<typename T > | |
| constexpr bool | is_frequency_v = is_frequency<T>::value |
Frequency types and utilities.
This library provides type-safe frequency handling with support for multiple precisions (mHz, Hz, kHz, MHz, GHz, THz), following the design of std::chrono::duration.
The library provides standard integer-based frequency types:
For fractional precision (e.g., musical tuning, scientific measurements), use floating-point representations:
Conversions between integer and floating-point follow the same rules as precision conversions (implicit when lossless, explicit when lossy).
Returns the absolute value of a frequency.
| Rep | Representation type. |
| Precision | Precision type. |
| f | The frequency. |
Definition at line 977 of file frequency.hpp.
References frequency_cast(), and freq::frequency< Rep, Precision >::zero().
Referenced by beat().
|
constexpr |
Calculates the beat frequency between two frequencies.
In acoustics and signal processing, the beat frequency is the absolute difference between two frequencies. When two sound waves of slightly different frequencies interfere, they produce a beating pattern at this frequency.
This is a convenience function equivalent to abs(f1 - f2).
| Rep1 | First frequency representation type. |
| Precision1 | First frequency precision. |
| Rep2 | Second frequency representation type. |
| Precision2 | Second frequency precision. |
| f1 | The first frequency. |
| f2 | The second frequency. |
Definition at line 955 of file frequency.hpp.
References abs(), and frequency_cast().
Converts a frequency to the target type, rounding toward positive infinity.
This function performs a frequency conversion with ceiling rounding semantics. When converting to a coarser precision, values are rounded up.
| ToFreq | The target frequency type. |
| Rep | Source representation type. |
| Precision | Source precision. |
| f | The frequency to convert. |
Definition at line 859 of file frequency.hpp.
References frequency_cast().
Converts a frequency to the target type, rounding toward negative infinity.
This function performs a frequency conversion with floor rounding semantics. When converting to a coarser precision, values are rounded down.
| ToFreq | The target frequency type. |
| Rep | Source representation type. |
| Precision | Source precision. |
| f | The frequency to convert. |
Definition at line 826 of file frequency.hpp.
References frequency_cast().
|
constexpr |
Converts a frequency to a different precision or representation.
For integer-to-integer conversions, this function uses wider intermediate types (128-bit when available) to minimize overflow risk during ratio arithmetic.
| ToFreq | The target frequency type. |
| Rep | Source representation type. |
| Precision | Source precision. |
| f | The frequency to convert. |
Definition at line 750 of file frequency.hpp.
References frequency_cast().
Referenced by abs(), beat(), ceil(), floor(), frequency_cast(), freq::frequency< Rep, Precision >::harmonic(), freq::frequency< Rep, Precision >::octave_shift(), freq::frequency< Rep, Precision >::octaves_from(), operator%(), operator%(), freq::frequency< Rep, Precision >::operator%=(), freq::frequency< Rep, Precision >::operator%=(), operator*(), operator*(), freq::frequency< Rep, Precision >::operator*=(), operator+(), freq::frequency< Rep, Precision >::operator+=(), operator-(), freq::frequency< Rep, Precision >::operator-=(), operator/(), operator/(), freq::frequency< Rep, Precision >::operator/=(), operator<=>(), operator==(), freq::frequency< Rep, Precision >::period(), round(), freq::frequency< Rep, Precision >::semitone_shift(), freq::frequency< Rep, Precision >::semitones_from(), freq::frequency< Rep, Precision >::subharmonic(), to_string(), freq::frequency< Rep, Precision >::wavelength(), and freq::frequency< Rep, Precision >::wavelength().
|
constexpr |
Returns the remainder of dividing a frequency by a scalar.
Definition at line 1035 of file frequency.hpp.
References frequency_cast().
|
constexpr |
Returns the remainder of dividing two frequencies.
Definition at line 1044 of file frequency.hpp.
References frequency_cast().
|
constexpr |
Multiplies a frequency by a scalar.
Definition at line 1000 of file frequency.hpp.
References frequency_cast().
|
constexpr |
Multiplies a scalar by a frequency.
Definition at line 1009 of file frequency.hpp.
References frequency_cast().
|
constexpr |
Returns the sum of two frequencies.
Definition at line 983 of file frequency.hpp.
References frequency_cast().
|
constexpr |
Returns the difference of two frequencies.
Definition at line 991 of file frequency.hpp.
References frequency_cast().
|
constexpr |
Divides a frequency by a scalar.
Definition at line 1017 of file frequency.hpp.
References frequency_cast().
|
constexpr |
Divides two frequencies, returning a scalar.
Definition at line 1025 of file frequency.hpp.
References freq::frequency< Rep, Precision >::count(), and frequency_cast().
|
constexpr |
Definition at line 1058 of file frequency.hpp.
References freq::frequency< Rep, Precision >::count(), and frequency_cast().
|
constexpr |
Definition at line 1051 of file frequency.hpp.
References freq::frequency< Rep, Precision >::count(), and frequency_cast().
Converts a frequency to the target type, rounding to nearest (ties to even).
This function performs a frequency conversion with round-to-nearest rounding semantics. When converting to a coarser precision, values are rounded to the nearest representable value, with ties rounded to even.
| ToFreq | The target frequency type. |
| Rep | Source representation type. |
| Precision | Source precision. |
| f | The frequency to convert. |
Definition at line 895 of file frequency.hpp.
References frequency_cast().
Renders a frequency as its exact count with a precision-qualified unit, e.g.
to_string(kilohertz(433)) == "433kHz".
Definition at line 1187 of file frequency.hpp.
References frequency_cast().
Definition at line 105 of file frequency.hpp.