1
#ifndef LIBDA_SAMPLE_HPP_INCLUDED
2
#define LIBDA_SAMPLE_HPP_INCLUDED
5
@file sample.hpp Sample format definition and format conversions.
7
Header-only, no need to link to LibDA.
13
// WARNING: changing this breaks binary compatibility on the library!
14
typedef float sample_t;
16
// The following conversions provide lossless conversions between floats
17
// and integers. Be sure to use only these conversions or otherwise the
18
// conversions may not be lossless, due to different scaling factors being
19
// used by different libraries.
21
// The negative minimum integer value produces sample_t value slightly
22
// more negative than -1.0 but this is necessary in order to prevent
23
// clipping in the float-to-int conversions. Now amplitude 1.0 in floating
24
// point produces -32767 .. 32767 symmetrical non-clipping range in s16.
25
const sample_t max_s16 = 32767.0;
26
const sample_t max_s24 = 8388607.0;
28
static inline sample_t conv_from_s16(int s) { return s / max_s16; }
29
static inline sample_t conv_from_s24(int s) { return s / max_s24; }
30
// The rounding is strictly not necessary, but it greatly improves
31
// the error tolerance if any floating point calculations are done.
32
static inline int conv_to_s16(sample_t s) { return int(roundf(s * max_s16)); }
33
static inline int conv_to_s24(sample_t s) { return int(roundf(s * max_s24)); }