arduino-audio-tools
Loading...
Searching...
No Matches
FloatAudio.h
Go to the documentation of this file.
1#pragma once
2#include "AudioToolsConfig.h"
3
4namespace audio_tools {
5
12 public:
13 FloatAudio() = default;
14 FloatAudio(float in) { this->value = in; }
15
16 inline operator float() { return value; }
17
18 explicit inline operator int8_t() { return value * 127; }
19
20 explicit inline operator int16_t() { return value * 32767; }
21
22 explicit inline operator int24_3bytes_t() {
23 return value * 8388607;
24 }
25
26 explicit inline operator int24_4bytes_t() {
27 return value * 8388607;
28 }
29
30 explicit inline operator int32_t() {
31 // 1.0f * 2147483647.0f is 2^31, which does not fit into an int32_t
32 if (value >= 1.0f) return 2147483647;
33 // -1.0f * 2147483647.0f is exactly INT32_MIN, anything below overflows
34 if (value <= -1.0f) return -2147483647 - 1;
35 return value * 2147483647.0f;
36 }
37
38 protected:
39 float value = 0.0f;
40};
41
42} // namespace audio_tools
43
44#ifdef USE_TYPETRAITS
45
46namespace std {
47template <>
48class numeric_limits<audio_tools::FloatAudio> {
49 public:
50 static audio_tools::FloatAudio lowest() {
51 return audio_tools::FloatAudio(-1.0f);
52 };
53 static audio_tools::FloatAudio min() {
54 return audio_tools::FloatAudio(-1.0f);
55 };
56 static audio_tools::FloatAudio max() {
57 return audio_tools::FloatAudio(1.0f);
58 };
59};
60} // namespace std
61
62#endif
Definition FloatAudio.h:11
float value
Definition FloatAudio.h:39
FloatAudio(float in)
Definition FloatAudio.h:14
24bit integer which is used for I2S sound processing. The values are really using 3 bytes....
Definition int24_3bytes_t.h:21
24bit integer which is used for I2S sound processing. The values are represented as int32_t,...
Definition int24_4bytes_t.h:22
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition LMSEchoCancellationStream.h:6
Definition InitializerList.h:7