arduino-audio-tools
Loading...
Searching...
No Matches
q1_14_t Class Reference

Fixed-point Q1.14 number: a plain 16-bit signed integer holding 1 integer bit and 14 fractional bits (value = raw / 16384.0). Covers the range [-2.0, 1.99993896484375] with a resolution of ~6.1e-5, using only integer add/sub/mul/div – no hardware floating-point instructions. More...

#include <CodecOpusOgg.h>

Public Member Functions

 q1_14_t ()=default
 q1_14_t ()=default
 q1_14_t (const q1_14_t &in)=default
 q1_14_t (const q1_14_t &in)=default
 q1_14_t (double in)
 q1_14_t (double in)
 q1_14_t (float in)
 q1_14_t (float in)
 q1_14_t (int in)
 q1_14_t (int in)
 operator float () const
 operator float () const
 operator int () const
 truncates toward zero, like (int)someFloat – integer-only, no FPU
 operator int () const
 truncates toward zero, like (int)someFloat – integer-only, no FPU
bool operator!= (float o) const
bool operator!= (float o) const
bool operator!= (q1_14_t o) const
bool operator!= (q1_14_t o) const
q1_14_t operator* (float o) const
q1_14_t operator* (float o) const
q1_14_t operator* (q1_14_t o) const
q1_14_t operator* (q1_14_t o) const
q1_14_t & operator*= (q1_14_t o)
q1_14_t & operator*= (q1_14_t o)
q1_14_t operator+ (float o) const
q1_14_t operator+ (float o) const
q1_14_t operator+ (q1_14_t o) const
q1_14_t operator+ (q1_14_t o) const
q1_14_t & operator+= (q1_14_t o)
q1_14_t & operator+= (q1_14_t o)
q1_14_t operator- () const
q1_14_t operator- () const
q1_14_t operator- (float o) const
q1_14_t operator- (float o) const
q1_14_t operator- (q1_14_t o) const
q1_14_t operator- (q1_14_t o) const
q1_14_t & operator-= (q1_14_t o)
q1_14_t & operator-= (q1_14_t o)
q1_14_t operator/ (float o) const
q1_14_t operator/ (float o) const
q1_14_t operator/ (q1_14_t o) const
q1_14_t operator/ (q1_14_t o) const
q1_14_t & operator/= (q1_14_t o)
q1_14_t & operator/= (q1_14_t o)
bool operator< (float o) const
bool operator< (float o) const
bool operator< (q1_14_t o) const
bool operator< (q1_14_t o) const
bool operator<= (float o) const
bool operator<= (float o) const
bool operator<= (q1_14_t o) const
bool operator<= (q1_14_t o) const
q1_14_t & operator= (const q1_14_t &other)=default
q1_14_t & operator= (const q1_14_t &other)=default
q1_14_t & operator= (float other)
q1_14_t & operator= (float other)
bool operator== (float o) const
bool operator== (float o) const
bool operator== (q1_14_t o) const
bool operator== (q1_14_t o) const
bool operator> (float o) const
bool operator> (float o) const
bool operator> (q1_14_t o) const
bool operator> (q1_14_t o) const
bool operator>= (float o) const
bool operator>= (float o) const
bool operator>= (q1_14_t o) const
bool operator>= (q1_14_t o) const
int16_t raw () const
 raw underlying Q1.14 representation
int16_t raw () const
 raw underlying Q1.14 representation
int16_t scale (int16_t sample) const
 scales a 16-bit PCM sample by this Q1.14 factor
int16_t scale (int16_t sample) const
 scales a 16-bit PCM sample by this Q1.14 factor
int24_t scale (int24_t sample) const
 scales a 24-bit PCM sample by this Q1.14 factor
int24_t scale (int24_t sample) const
 scales a 24-bit PCM sample by this Q1.14 factor
int32_t scale (int32_t sample) const
 scales a 32-bit PCM sample by this Q1.14 factor
int32_t scale (int32_t sample) const
 scales a 32-bit PCM sample by this Q1.14 factor
int16_t toInt16 () const
 converts to a 16-bit PCM sample (-32768..32767)
int16_t toInt16 () const
 converts to a 16-bit PCM sample (-32768..32767)
int24_t toInt24 () const
 converts to a 24-bit PCM sample (-8388608..8388607)
int24_t toInt24 () const
 converts to a 24-bit PCM sample (-8388608..8388607)
int32_t toInt32 () const
 converts to a 32-bit PCM sample (-2147483648..2147483647)
int32_t toInt32 () const
 converts to a 32-bit PCM sample (-2147483648..2147483647)

Static Public Member Functions

static q1_14_t fromInt16 (int16_t sample)
 builds a q1_14_t from a 16-bit PCM sample (-32768..32767)
static q1_14_t fromInt16 (int16_t sample)
 builds a q1_14_t from a 16-bit PCM sample (-32768..32767)
static q1_14_t fromInt24 (int24_t sample)
 builds a q1_14_t from a 24-bit PCM sample (-8388608..8388607)
static q1_14_t fromInt24 (int24_t sample)
 builds a q1_14_t from a 24-bit PCM sample (-8388608..8388607)
static q1_14_t fromInt32 (int32_t sample)
 builds a q1_14_t from a 32-bit PCM sample (-2147483648..2147483647)
static q1_14_t fromInt32 (int32_t sample)
 builds a q1_14_t from a 32-bit PCM sample (-2147483648..2147483647)
static q1_14_t fromRaw (int16_t raw)
 builds a q1_14_t directly from a raw Q1.14 value (no scaling)
static q1_14_t fromRaw (int16_t raw)
 builds a q1_14_t directly from a raw Q1.14 value (no scaling)

Static Public Attributes

static constexpr int kFractionalBits = 14
static constexpr int32_t kScale = 1 << kFractionalBits

Protected Member Functions

float toFloat () const
float toFloat () const

Static Protected Member Functions

static int16_t clamp (int32_t v)
static int16_t clamp (int32_t v)
static int32_t clampRange32 (int32_t v, int32_t lo, int32_t hi)
static int32_t clampRange32 (int32_t v, int32_t lo, int32_t hi)
static int64_t clampRange64 (int64_t v, int64_t lo, int64_t hi)
static int64_t clampRange64 (int64_t v, int64_t lo, int64_t hi)
static int16_t fromFloat (float in)
static int16_t fromFloat (float in)

Protected Attributes

int16_t value = 0

Detailed Description

Fixed-point Q1.14 number: a plain 16-bit signed integer holding 1 integer bit and 14 fractional bits (value = raw / 16384.0). Covers the range [-2.0, 1.99993896484375] with a resolution of ~6.1e-5, using only integer add/sub/mul/div – no hardware floating-point instructions.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ q1_14_t() [1/10]

q1_14_t ( )
default

◆ q1_14_t() [2/10]

q1_14_t ( const q1_14_t & in)
default

◆ q1_14_t() [3/10]

q1_14_t ( float in)
inline

◆ q1_14_t() [4/10]

q1_14_t ( double in)
inline

◆ q1_14_t() [5/10]

q1_14_t ( int in)
inline

◆ q1_14_t() [6/10]

q1_14_t ( )
default

◆ q1_14_t() [7/10]

q1_14_t ( const q1_14_t & in)
default

◆ q1_14_t() [8/10]

q1_14_t ( float in)
inline

◆ q1_14_t() [9/10]

q1_14_t ( double in)
inline

◆ q1_14_t() [10/10]

q1_14_t ( int in)
inline

Member Function Documentation

◆ clamp() [1/2]

int16_t clamp ( int32_t v)
inlinestaticprotected

◆ clamp() [2/2]

int16_t clamp ( int32_t v)
inlinestaticprotected

◆ clampRange32() [1/2]

int32_t clampRange32 ( int32_t v,
int32_t lo,
int32_t hi )
inlinestaticprotected

◆ clampRange32() [2/2]

int32_t clampRange32 ( int32_t v,
int32_t lo,
int32_t hi )
inlinestaticprotected

◆ clampRange64() [1/2]

int64_t clampRange64 ( int64_t v,
int64_t lo,
int64_t hi )
inlinestaticprotected

◆ clampRange64() [2/2]

int64_t clampRange64 ( int64_t v,
int64_t lo,
int64_t hi )
inlinestaticprotected

◆ fromFloat() [1/2]

int16_t fromFloat ( float in)
inlinestaticprotected

◆ fromFloat() [2/2]

int16_t fromFloat ( float in)
inlinestaticprotected

◆ fromInt16() [1/2]

q1_14_t fromInt16 ( int16_t sample)
inlinestatic

builds a q1_14_t from a 16-bit PCM sample (-32768..32767)

◆ fromInt16() [2/2]

q1_14_t fromInt16 ( int16_t sample)
inlinestatic

builds a q1_14_t from a 16-bit PCM sample (-32768..32767)

◆ fromInt24() [1/2]

q1_14_t fromInt24 ( int24_t sample)
inlinestatic

builds a q1_14_t from a 24-bit PCM sample (-8388608..8388607)

◆ fromInt24() [2/2]

q1_14_t fromInt24 ( int24_t sample)
inlinestatic

builds a q1_14_t from a 24-bit PCM sample (-8388608..8388607)

◆ fromInt32() [1/2]

q1_14_t fromInt32 ( int32_t sample)
inlinestatic

builds a q1_14_t from a 32-bit PCM sample (-2147483648..2147483647)

◆ fromInt32() [2/2]

q1_14_t fromInt32 ( int32_t sample)
inlinestatic

builds a q1_14_t from a 32-bit PCM sample (-2147483648..2147483647)

◆ fromRaw() [1/2]

q1_14_t fromRaw ( int16_t raw)
inlinestatic

builds a q1_14_t directly from a raw Q1.14 value (no scaling)

◆ fromRaw() [2/2]

q1_14_t fromRaw ( int16_t raw)
inlinestatic

builds a q1_14_t directly from a raw Q1.14 value (no scaling)

◆ operator float() [1/2]

operator float ( ) const
inline

◆ operator float() [2/2]

operator float ( ) const
inline

◆ operator int() [1/2]

operator int ( ) const
inlineexplicit

truncates toward zero, like (int)someFloat – integer-only, no FPU

◆ operator int() [2/2]

operator int ( ) const
inlineexplicit

truncates toward zero, like (int)someFloat – integer-only, no FPU

◆ operator!=() [1/4]

bool operator!= ( float o) const
inline

◆ operator!=() [2/4]

bool operator!= ( float o) const
inline

◆ operator!=() [3/4]

bool operator!= ( q1_14_t o) const
inline

◆ operator!=() [4/4]

bool operator!= ( q1_14_t o) const
inline

◆ operator*() [1/4]

q1_14_t operator* ( float o) const
inline

◆ operator*() [2/4]

q1_14_t operator* ( float o) const
inline

◆ operator*() [3/4]

q1_14_t operator* ( q1_14_t o) const
inline

◆ operator*() [4/4]

q1_14_t operator* ( q1_14_t o) const
inline

◆ operator*=() [1/2]

q1_14_t & operator*= ( q1_14_t o)
inline

◆ operator*=() [2/2]

q1_14_t & operator*= ( q1_14_t o)
inline

◆ operator+() [1/4]

q1_14_t operator+ ( float o) const
inline

◆ operator+() [2/4]

q1_14_t operator+ ( float o) const
inline

◆ operator+() [3/4]

q1_14_t operator+ ( q1_14_t o) const
inline

◆ operator+() [4/4]

q1_14_t operator+ ( q1_14_t o) const
inline

◆ operator+=() [1/2]

q1_14_t & operator+= ( q1_14_t o)
inline

◆ operator+=() [2/2]

q1_14_t & operator+= ( q1_14_t o)
inline

◆ operator-() [1/6]

q1_14_t operator- ( ) const
inline

◆ operator-() [2/6]

q1_14_t operator- ( ) const
inline

◆ operator-() [3/6]

q1_14_t operator- ( float o) const
inline

◆ operator-() [4/6]

q1_14_t operator- ( float o) const
inline

◆ operator-() [5/6]

q1_14_t operator- ( q1_14_t o) const
inline

◆ operator-() [6/6]

q1_14_t operator- ( q1_14_t o) const
inline

◆ operator-=() [1/2]

q1_14_t & operator-= ( q1_14_t o)
inline

◆ operator-=() [2/2]

q1_14_t & operator-= ( q1_14_t o)
inline

◆ operator/() [1/4]

q1_14_t operator/ ( float o) const
inline

◆ operator/() [2/4]

q1_14_t operator/ ( float o) const
inline

◆ operator/() [3/4]

q1_14_t operator/ ( q1_14_t o) const
inline

◆ operator/() [4/4]

q1_14_t operator/ ( q1_14_t o) const
inline

◆ operator/=() [1/2]

q1_14_t & operator/= ( q1_14_t o)
inline

◆ operator/=() [2/2]

q1_14_t & operator/= ( q1_14_t o)
inline

◆ operator<() [1/4]

bool operator< ( float o) const
inline

◆ operator<() [2/4]

bool operator< ( float o) const
inline

◆ operator<() [3/4]

bool operator< ( q1_14_t o) const
inline

◆ operator<() [4/4]

bool operator< ( q1_14_t o) const
inline

◆ operator<=() [1/4]

bool operator<= ( float o) const
inline

◆ operator<=() [2/4]

bool operator<= ( float o) const
inline

◆ operator<=() [3/4]

bool operator<= ( q1_14_t o) const
inline

◆ operator<=() [4/4]

bool operator<= ( q1_14_t o) const
inline

◆ operator=() [1/4]

q1_14_t & operator= ( const q1_14_t & other)
default

◆ operator=() [2/4]

q1_14_t & operator= ( const q1_14_t & other)
default

◆ operator=() [3/4]

q1_14_t & operator= ( float other)
inline

◆ operator=() [4/4]

q1_14_t & operator= ( float other)
inline

◆ operator==() [1/4]

bool operator== ( float o) const
inline

◆ operator==() [2/4]

bool operator== ( float o) const
inline

◆ operator==() [3/4]

bool operator== ( q1_14_t o) const
inline

◆ operator==() [4/4]

bool operator== ( q1_14_t o) const
inline

◆ operator>() [1/4]

bool operator> ( float o) const
inline

◆ operator>() [2/4]

bool operator> ( float o) const
inline

◆ operator>() [3/4]

bool operator> ( q1_14_t o) const
inline

◆ operator>() [4/4]

bool operator> ( q1_14_t o) const
inline

◆ operator>=() [1/4]

bool operator>= ( float o) const
inline

◆ operator>=() [2/4]

bool operator>= ( float o) const
inline

◆ operator>=() [3/4]

bool operator>= ( q1_14_t o) const
inline

◆ operator>=() [4/4]

bool operator>= ( q1_14_t o) const
inline

◆ raw() [1/2]

int16_t raw ( ) const
inline

raw underlying Q1.14 representation

◆ raw() [2/2]

int16_t raw ( ) const
inline

raw underlying Q1.14 representation

◆ scale() [1/6]

int16_t scale ( int16_t sample) const
inline

scales a 16-bit PCM sample by this Q1.14 factor

◆ scale() [2/6]

int16_t scale ( int16_t sample) const
inline

scales a 16-bit PCM sample by this Q1.14 factor

◆ scale() [3/6]

int24_t scale ( int24_t sample) const
inline

scales a 24-bit PCM sample by this Q1.14 factor

◆ scale() [4/6]

int24_t scale ( int24_t sample) const
inline

scales a 24-bit PCM sample by this Q1.14 factor

◆ scale() [5/6]

int32_t scale ( int32_t sample) const
inline

scales a 32-bit PCM sample by this Q1.14 factor

◆ scale() [6/6]

int32_t scale ( int32_t sample) const
inline

scales a 32-bit PCM sample by this Q1.14 factor

◆ toFloat() [1/2]

float toFloat ( ) const
inlineprotected

◆ toFloat() [2/2]

float toFloat ( ) const
inlineprotected

◆ toInt16() [1/2]

int16_t toInt16 ( ) const
inline

converts to a 16-bit PCM sample (-32768..32767)

◆ toInt16() [2/2]

int16_t toInt16 ( ) const
inline

converts to a 16-bit PCM sample (-32768..32767)

◆ toInt24() [1/2]

int24_t toInt24 ( ) const
inline

converts to a 24-bit PCM sample (-8388608..8388607)

◆ toInt24() [2/2]

int24_t toInt24 ( ) const
inline

converts to a 24-bit PCM sample (-8388608..8388607)

◆ toInt32() [1/2]

int32_t toInt32 ( ) const
inline

converts to a 32-bit PCM sample (-2147483648..2147483647)

◆ toInt32() [2/2]

int32_t toInt32 ( ) const
inline

converts to a 32-bit PCM sample (-2147483648..2147483647)

Member Data Documentation

◆ kFractionalBits

constexpr int kFractionalBits = 14
staticconstexpr

◆ kScale

constexpr int32_t kScale = 1 << kFractionalBits
staticconstexpr

◆ value

int16_t value = 0
protected

The documentation for this class was generated from the following files: