arduino-audio-tools
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
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 <Q1_14.h>

Public Member Functions

 q1_14_t ()=default
 
 q1_14_t (const q1_14_t &in)=default
 
 q1_14_t (double in)
 
 q1_14_t (float in)
 
 q1_14_t (int in)
 
 operator float () const
 
 operator int () const
 truncates toward zero, like (int)someFloat – integer-only, no FPU
 
bool operator!= (float o) const
 
bool operator!= (q1_14_t o) const
 
q1_14_t operator* (float o) const
 
q1_14_t operator* (q1_14_t o) const
 
q1_14_toperator*= (q1_14_t o)
 
q1_14_t operator+ (float o) const
 
q1_14_t operator+ (q1_14_t o) const
 
q1_14_toperator+= (q1_14_t o)
 
q1_14_t operator- () const
 
q1_14_t operator- (float o) const
 
q1_14_t operator- (q1_14_t o) const
 
q1_14_toperator-= (q1_14_t o)
 
q1_14_t operator/ (float o) const
 
q1_14_t operator/ (q1_14_t o) const
 
q1_14_toperator/= (q1_14_t o)
 
bool operator< (float o) const
 
bool operator< (q1_14_t o) const
 
bool operator<= (float o) const
 
bool operator<= (q1_14_t o) const
 
q1_14_toperator= (const q1_14_t &other)=default
 
q1_14_toperator= (float other)
 
bool operator== (float o) const
 
bool operator== (q1_14_t o) const
 
bool operator> (float o) const
 
bool operator> (q1_14_t o) const
 
bool operator>= (float o) const
 
bool operator>= (q1_14_t o) const
 
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
 
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
 
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)
 
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 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 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
 

Static Protected Member Functions

static int16_t clamp (int32_t v)
 
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 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/5]

q1_14_t ( )
default

◆ q1_14_t() [2/5]

q1_14_t ( const q1_14_t in)
default

◆ q1_14_t() [3/5]

q1_14_t ( float  in)
inline

◆ q1_14_t() [4/5]

q1_14_t ( double  in)
inline

◆ q1_14_t() [5/5]

q1_14_t ( int  in)
inline

Member Function Documentation

◆ clamp()

static int16_t clamp ( int32_t  v)
inlinestaticprotected

◆ clampRange32()

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

◆ clampRange64()

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

◆ fromFloat()

static int16_t fromFloat ( float  in)
inlinestaticprotected

◆ fromInt16()

static q1_14_t fromInt16 ( int16_t  sample)
inlinestatic

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

◆ fromInt24()

static q1_14_t fromInt24 ( int24_t  sample)
inlinestatic

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

◆ fromInt32()

static q1_14_t fromInt32 ( int32_t  sample)
inlinestatic

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

◆ fromRaw()

static q1_14_t fromRaw ( int16_t  raw)
inlinestatic

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

◆ operator float()

operator float ( ) const
inline

◆ operator int()

operator int ( ) const
inlineexplicit

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

◆ operator!=() [1/2]

bool operator!= ( float  o) const
inline

◆ operator!=() [2/2]

bool operator!= ( q1_14_t  o) const
inline

◆ operator*() [1/2]

q1_14_t operator* ( float  o) const
inline

◆ operator*() [2/2]

q1_14_t operator* ( q1_14_t  o) const
inline

◆ operator*=()

q1_14_t & operator*= ( q1_14_t  o)
inline

◆ operator+() [1/2]

q1_14_t operator+ ( float  o) const
inline

◆ operator+() [2/2]

q1_14_t operator+ ( q1_14_t  o) const
inline

◆ operator+=()

q1_14_t & operator+= ( q1_14_t  o)
inline

◆ operator-() [1/3]

q1_14_t operator- ( ) const
inline

◆ operator-() [2/3]

q1_14_t operator- ( float  o) const
inline

◆ operator-() [3/3]

q1_14_t operator- ( q1_14_t  o) const
inline

◆ operator-=()

q1_14_t & operator-= ( q1_14_t  o)
inline

◆ operator/() [1/2]

q1_14_t operator/ ( float  o) const
inline

◆ operator/() [2/2]

q1_14_t operator/ ( q1_14_t  o) const
inline

◆ operator/=()

q1_14_t & operator/= ( q1_14_t  o)
inline

◆ operator<() [1/2]

bool operator< ( float  o) const
inline

◆ operator<() [2/2]

bool operator< ( q1_14_t  o) const
inline

◆ operator<=() [1/2]

bool operator<= ( float  o) const
inline

◆ operator<=() [2/2]

bool operator<= ( q1_14_t  o) const
inline

◆ operator=() [1/2]

q1_14_t & operator= ( const q1_14_t other)
default

◆ operator=() [2/2]

q1_14_t & operator= ( float  other)
inline

◆ operator==() [1/2]

bool operator== ( float  o) const
inline

◆ operator==() [2/2]

bool operator== ( q1_14_t  o) const
inline

◆ operator>() [1/2]

bool operator> ( float  o) const
inline

◆ operator>() [2/2]

bool operator> ( q1_14_t  o) const
inline

◆ operator>=() [1/2]

bool operator>= ( float  o) const
inline

◆ operator>=() [2/2]

bool operator>= ( q1_14_t  o) const
inline

◆ raw()

int16_t raw ( ) const
inline

raw underlying Q1.14 representation

◆ scale() [1/3]

int16_t scale ( int16_t  sample) const
inline

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

◆ scale() [2/3]

int24_t scale ( int24_t  sample) const
inline

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

◆ scale() [3/3]

int32_t scale ( int32_t  sample) const
inline

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

◆ toFloat()

float toFloat ( ) const
inlineprotected

◆ toInt16()

int16_t toInt16 ( ) const
inline

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

◆ toInt24()

int24_t toInt24 ( ) const
inline

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

◆ toInt32()

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 file: