arduino-audio-tools
Loading...
Searching...
No Matches
src
AudioTools
CoreAudio
AudioBasic
Int24_4bytes_t.h
Go to the documentation of this file.
1
#pragma once
2
#include "
AudioToolsConfig.h
"
3
#include <string.h>
// std::memcpy
4
#include <stdint.h>
// std::int32_t
5
#ifdef USE_TYPETRAITS
6
# include <limits>
7
#endif
8
9
#define INT24_MAX 0x7FFFFF
10
11
12
namespace
audio_tools
{
13
22
class
int24_4bytes_t
{
23
public
:
24
int24_4bytes_t
() {
25
value = 0;
26
}
27
28
int24_4bytes_t
(
void
*ptr) {
29
memcpy
(&value, ptr, 4);
30
}
31
32
int24_4bytes_t
(
const
int16_t
in) {
33
set
(in) ;
34
}
35
36
int24_4bytes_t
(
const
int32_t
in) {
37
set
(in);
38
}
39
40
int24_4bytes_t
(
const
int64_t
in) {
41
set
((
int32_t
)in) ;
42
}
43
44
int24_4bytes_t
(
const
int24_4bytes_t
&in) {
45
value = in.value;
46
}
47
48
int24_4bytes_t
(
const
float
in) {
49
set
((
int32_t
)in);
50
}
51
52
#if defined(USE_INT24_FROM_INT)
53
54
int24_4bytes_t
(
const
int
in) {
55
set
(in);
56
}
57
58
#endif
59
61
inline
void
set
(
const
int32_t
&in) {
62
if
(in>
INT24_MAX
){
63
value =
INT24_MAX
<< 8;
64
}
else
if
(in<-
INT24_MAX
){
65
value = -(
INT24_MAX
<< 8);
66
}
else
{
67
value = in << 8;
68
}
69
}
70
71
int24_4bytes_t
&
operator=
(
const
int24_4bytes_t
&
other
){
72
value =
other
.value;
73
return
*
this
;
74
}
75
76
int24_4bytes_t
&
operator=
(
const
float
&
other
){
77
set
(((
int32_t
)
other
));
78
return
*
this
;
79
}
80
81
operator
int
() {
82
return
toInt
();
83
}
84
85
explicit
operator
float
() {
86
return
toInt
();
87
}
88
89
explicit
operator
int64_t
() {
90
return
toInt
();
91
}
92
93
int24_4bytes_t
&
operator +=
(
int32_t
valueA
){
94
int32_t
temp
=
toInt
();
95
temp
+=
valueA
;
96
set
(
temp
);
97
return
*
this
;
98
}
99
100
int24_4bytes_t
&
operator -=
(
int32_t
valueA
){
101
int32_t
temp
=
toInt
();
102
temp
-=
valueA
;
103
set
(
temp
);
104
return
*
this
;
105
}
106
108
int
toInt
()
const
{
109
return
value >> 8;
110
}
111
113
float
toFloat
()
const
{
return
(
float
)
toInt
(); }
114
116
int16_t
scale16
()
const
{
117
return
static_cast<
int16_t
>
(
toInt
() >> 8) ;
118
}
119
121
int32_t
scale32
()
const
{
122
return
static_cast<
int32_t
>
(
toInt
() << 8);
123
}
124
126
float
scaleFloat
()
const
{
return
toFloat
() /
INT24_MAX
; }
127
128
void
setAndScale16
(
int16_t
i16
) {
129
value =
i16
;
130
value = value << 16;
131
}
132
133
int16_t
getAndScale16
() {
134
return
static_cast<
int16_t
>
(value >> 16);
135
}
136
137
private
:
138
// store 24 bit value shifted by 1 byte to the left
139
int32_t
value;
140
};
141
142
143
}
// namespace audio_tools
144
145
#ifdef USE_TYPETRAITS
146
147
namespace
std
{
148
template
<>
class
numeric_limits<
audio_tools
::int24_4bytes_t> {
149
public
:
150
static
audio_tools::int24_4bytes_t
lowest() {
return
audio_tools::int24_4bytes_t
(-0x7FFFFF);};
151
static
audio_tools::int24_4bytes_t
min() {
return
audio_tools::int24_4bytes_t
(-0x7FFFFF);};
152
static
audio_tools::int24_4bytes_t
max() {
return
audio_tools::int24_4bytes_t
(0x7FFFFF);};
153
};
154
}
155
156
#endif
AudioToolsConfig.h
INT24_MAX
#define INT24_MAX
Definition
Int24_3bytes_t.h:9
audio_tools::int24_4bytes_t
24bit integer which is used for I2S sound processing. The values are represented as int32_t,...
Definition
Int24_4bytes_t.h:22
audio_tools::int24_4bytes_t::setAndScale16
void setAndScale16(int16_t i16)
Definition
Int24_4bytes_t.h:128
audio_tools::int24_4bytes_t::operator-=
int24_4bytes_t & operator-=(int32_t valueA)
Definition
Int24_4bytes_t.h:100
audio_tools::int24_4bytes_t::int24_4bytes_t
int24_4bytes_t(const int64_t in)
Definition
Int24_4bytes_t.h:40
audio_tools::int24_4bytes_t::operator=
int24_4bytes_t & operator=(const int24_4bytes_t &other)
Definition
Int24_4bytes_t.h:71
audio_tools::int24_4bytes_t::int24_4bytes_t
int24_4bytes_t(const int32_t in)
Definition
Int24_4bytes_t.h:36
audio_tools::int24_4bytes_t::int24_4bytes_t
int24_4bytes_t(const float in)
Definition
Int24_4bytes_t.h:48
audio_tools::int24_4bytes_t::operator=
int24_4bytes_t & operator=(const float &other)
Definition
Int24_4bytes_t.h:76
audio_tools::int24_4bytes_t::getAndScale16
int16_t getAndScale16()
Definition
Int24_4bytes_t.h:133
audio_tools::int24_4bytes_t::int24_4bytes_t
int24_4bytes_t(void *ptr)
Definition
Int24_4bytes_t.h:28
audio_tools::int24_4bytes_t::int24_4bytes_t
int24_4bytes_t(const int16_t in)
Definition
Int24_4bytes_t.h:32
audio_tools::int24_4bytes_t::operator+=
int24_4bytes_t & operator+=(int32_t valueA)
Definition
Int24_4bytes_t.h:93
audio_tools::int24_4bytes_t::scale32
int32_t scale32() const
provides value between -2,147,483,647 and 2,147,483,647
Definition
Int24_4bytes_t.h:121
audio_tools::int24_4bytes_t::set
void set(const int32_t &in)
values are clipped and shifted by 1 byte
Definition
Int24_4bytes_t.h:61
audio_tools::int24_4bytes_t::toInt
int toInt() const
Standard Conversion to Int.
Definition
Int24_4bytes_t.h:108
audio_tools::int24_4bytes_t::scale16
int16_t scale16() const
provides value between -32767 and 32767
Definition
Int24_4bytes_t.h:116
audio_tools::int24_4bytes_t::int24_4bytes_t
int24_4bytes_t(const int24_4bytes_t &in)
Definition
Int24_4bytes_t.h:44
audio_tools::int24_4bytes_t::scaleFloat
float scaleFloat() const
provides value between -1.0 and 1.0
Definition
Int24_4bytes_t.h:126
audio_tools::int24_4bytes_t::toFloat
float toFloat() const
convert to float
Definition
Int24_4bytes_t.h:113
audio_tools::int24_4bytes_t::int24_4bytes_t
int24_4bytes_t()
Definition
Int24_4bytes_t.h:24
audio_tools
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition
AudioCodecsBase.h:10
audio_tools::writeData
size_t writeData(Print *p_out, T *data, int samples, int maxSamples=512)
Definition
AudioTypes.h:508
std
Definition
FFTReal.h:488
Generated by
1.9.8