-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCPcmSample.cpp
93 lines (82 loc) · 2.45 KB
/
CPcmSample.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "CPcmSample.h"
PurrFX::CPcmSample::CPcmSample(sample_t i_nSample)
{
m_nSample = i_nSample;
}
PurrFX::CPcmSample::CPcmSample()
{
}
PurrFX::CPcmSample::CPcmSample(uint8_t i_nValue):
CPcmSample(
int8_t(
int32_t(i_nValue ) -
int32_t(std::numeric_limits<int8_t>::min())
)
)
{
}
PurrFX::CPcmSample::CPcmSample(int8_t i_nValue)
{
m_nSample = i_nValue > 0
? i_nValue / sample_t( std::numeric_limits<int8_t>::max() )
: i_nValue / sample_t( -std::numeric_limits<int8_t>::min() );
assert(m_nSample >= -1.0L && m_nSample <= 1.0L);
}
PurrFX::CPcmSample::CPcmSample(uint16_t i_nValue):
CPcmSample(
int16_t(
int32_t(i_nValue ) -
int32_t(std::numeric_limits<int16_t>::min())
)
)
{
}
PurrFX::CPcmSample::CPcmSample(int16_t i_nValue)
{
m_nSample = i_nValue > 0
? i_nValue / sample_t( std::numeric_limits<int16_t>::max() )
: i_nValue / sample_t( -std::numeric_limits<int16_t>::min() );
assert(m_nSample >= -1.0L && m_nSample <= 1.0L);
}
PurrFX::CPcmSample PurrFX::CPcmSample::toMono(const CPcmSample& i_rLeft, const CPcmSample& i_rRight)
{
return CPcmSample( (i_rLeft.m_nSample+i_rRight.m_nSample)/2.0L );
}
uint8_t PurrFX::CPcmSample::toU8() const
{
sample_t nSample = (m_nSample + 1.0L)/2.0L;
assert(nSample >= 0 && nSample <= 1.0);
sample_t nResult = nSample*std::numeric_limits<uint8_t>::max();
assert(nResult >= std::numeric_limits<uint8_t>::min() &&
nResult <= std::numeric_limits<uint8_t>::max() );
return uint8_t(nResult);
}
int8_t PurrFX::CPcmSample::toS8() const
{
sample_t nResult = m_nSample * ( m_nSample < 0
? -std::numeric_limits<int8_t>::min()
: std::numeric_limits<int8_t>::max()
);
assert(nResult >= std::numeric_limits<int8_t>::min() &&
nResult <= std::numeric_limits<int8_t>::max() );
return int8_t(nResult);
}
uint16_t PurrFX::CPcmSample::toU16() const
{
sample_t nSample = (m_nSample + 1.0L)/2.0L;
assert(nSample >= 0 && nSample <= 1.0);
sample_t nResult = nSample*std::numeric_limits<uint16_t>::max();
assert(nResult >= std::numeric_limits<uint16_t>::min() &&
nResult <= std::numeric_limits<uint16_t>::max() );
return uint16_t(nResult);
}
int16_t PurrFX::CPcmSample::toS16() const
{
sample_t nResult = m_nSample * ( m_nSample < 0
? -std::numeric_limits<int16_t>::min()
: std::numeric_limits<int16_t>::max()
);
assert(nResult >= std::numeric_limits<int16_t>::min() &&
nResult <= std::numeric_limits<int16_t>::max() );
return int16_t(nResult);
}