-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCAudioDataConsumer.cpp
49 lines (41 loc) · 1.04 KB
/
CAudioDataConsumer.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
#include "CAudioDataConsumer.h"
PurrFX::CAudioDataConsumer::CAudioDataConsumer(uint32_t i_nDuration):
m_nDuration(i_nDuration)
{
}
PurrFX::CAudioDataConsumer::~CAudioDataConsumer()
{
}
bool PurrFX::CAudioDataConsumer::finished() const
{
if (m_nDuration != InfiniteDuration)
return (m_nBytesToProcess == 0);
return false;
}
uint32_t PurrFX::CAudioDataConsumer::bytesToProcess() const
{
if (m_nDuration != InfiniteDuration)
return m_nBytesToProcess;
return 1024;
}
void PurrFX::CAudioDataConsumer::start(const CAudioFormat& i_rAudioFormat)
{
m_nBytesToProcess = m_nDuration
* i_rAudioFormat.sampleRate()
* i_rAudioFormat.channels()
* i_rAudioFormat.bytesPerSample();
onStart(i_rAudioFormat, m_nBytesToProcess);
}
void PurrFX::CAudioDataConsumer::processData(const char* i_pData, uint32_t i_nSize)
{
if (finished())
return;
if (m_nDuration != InfiniteDuration)
{
uint32_t nSize = (i_nSize <= m_nBytesToProcess ? i_nSize : m_nBytesToProcess);
m_nBytesToProcess -= nSize;
onData(i_pData, nSize);
}
else
onData(i_pData, i_nSize);
}