arduino-audio-tools
FloatAudio.h
1 #pragma once
2 #include "AudioConfig.h"
3 
4 namespace audio_tools {
5 
6 /***
7  * A simple float number (in the range of -1.0 to 1.0) that supports the conversion to
8  * it's corresponding scaled int values.
9  */
10 
11 class FloatAudio {
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() { return value * 2147483647; }
31 
32  protected:
33  float value = 0.0f;
34 };
35 
36 } // namespace audio_tools
37 
38 #ifdef USE_TYPETRAITS
39 
40 namespace std {
41 template <>
42 class numeric_limits<audio_tools::FloatAudio> {
43  public:
44  static audio_tools::FloatAudio lowest() {
45  return audio_tools::FloatAudio(-1.0f);
46  };
47  static audio_tools::FloatAudio min() {
48  return audio_tools::FloatAudio(-1.0f);
49  };
50  static audio_tools::FloatAudio max() {
51  return audio_tools::FloatAudio(1.0f);
52  };
53 };
54 } // namespace std
55 
56 #endif
Definition: FloatAudio.h:11
24bit integer which is used for I2S sound processing. The values are really using 3 bytes....
Definition: Int24_3bytes_t.h:16
24bit integer which is used for I2S sound processing. The values are represented as int32_t,...
Definition: Int24_4bytes_t.h:16
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition: AudioConfig.h:859