1 #pragma once
2 
3 #include <cstddef>
4 #include <climits>
5 
6 #include "util/math.h"
7 
8 // Signed integer type for POT array indices, sizes and pointer
9 // arithmetic. Its size (32-/64-bit) depends on the CPU architecture.
10 // This should be used for all CSAMLE operations since it is fast and
11 // allows compiler auto vectorizing. For Qt container operations use
12 // just int as before.
13 typedef std::ptrdiff_t SINT;
14 
15 // 16-bit integer sample data within the asymmetric
16 // range [SHRT_MIN, SHRT_MAX].
17 typedef short int SAMPLE;
18 constexpr SAMPLE SAMPLE_ZERO = 0;
19 constexpr SAMPLE SAMPLE_MINIMUM = SHRT_MIN;
20 constexpr SAMPLE SAMPLE_MAXIMUM = SHRT_MAX;
21 
22 
23 // 32-bit single precision floating-point sample data
24 // normalized within the range [-1.0, 1.0] with a peak
25 // amplitude of 1.0. No min/max constants here to
26 // emphasize the symmetric value range of CSAMPLE
27 // data!
28 typedef float CSAMPLE;
29 constexpr CSAMPLE CSAMPLE_ZERO = 0.0f;
30 constexpr CSAMPLE CSAMPLE_ONE = 1.0f;
31 constexpr CSAMPLE CSAMPLE_PEAK = CSAMPLE_ONE;
32 
33 // Limits the range of a CSAMPLE value to [-CSAMPLE_PEAK, CSAMPLE_PEAK].
34 inline
CSAMPLE_clamp(CSAMPLE in)35 CSAMPLE CSAMPLE_clamp(CSAMPLE in) {
36     return math_clamp(in, -CSAMPLE_PEAK, CSAMPLE_PEAK);
37 }
38 
39 // Gain values for weighted calculations of CSAMPLE
40 // data in the range [0.0, 1.0]. Same data type as
41 // CSAMPLE to avoid type conversions in calculations.
42 typedef CSAMPLE CSAMPLE_GAIN;
43 constexpr float CSAMPLE_GAIN_ZERO = CSAMPLE_ZERO;
44 constexpr float CSAMPLE_GAIN_ONE = CSAMPLE_ONE;
45 constexpr float CSAMPLE_GAIN_MIN = CSAMPLE_GAIN_ZERO;
46 constexpr float CSAMPLE_GAIN_MAX = CSAMPLE_GAIN_ONE;
47 
48 // Limits the range of a CSAMPLE_GAIN value to [CSAMPLE_GAIN_MIN, CSAMPLE_GAIN_MAX].
49 inline
CSAMPLE_GAIN_clamp(CSAMPLE_GAIN in)50 CSAMPLE_GAIN CSAMPLE_GAIN_clamp(CSAMPLE_GAIN in) {
51     return math_clamp(in, CSAMPLE_GAIN_MIN, CSAMPLE_GAIN_MAX);
52 }
53