-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudiodevice.cpp
More file actions
46 lines (33 loc) · 962 Bytes
/
audiodevice.cpp
File metadata and controls
46 lines (33 loc) · 962 Bytes
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
#include "audiodevice.h"
#include <QDebug>
#define T_UNUSED(c) static_cast<void>(c)
AudioDevice::AudioDevice(QByteArray pcm)
: _dataPcm(pcm)
{
open(QIODevice::ReadOnly); // 为了解决QIODevice::read (QIODevice): device not open
_writeLen = 0;
}
AudioDevice::~AudioDevice()
{
close();
}
qint64 AudioDevice::readData(char *data, qint64 maxlen)
{
if (_writeLen >= _dataPcm.size())
return 0;
int len;
//计算未播放的数据的长度
len = (_writeLen + maxlen) > _dataPcm.size() ? (_dataPcm.size() - _writeLen) : maxlen;
//把要播放的pcm数据存入声卡缓冲区里
memcpy(data, _dataPcm.data() + _writeLen, len);
// 更新已播放的数据长度
_writeLen += len;
qDebug() << "wriLen:" << _writeLen << " dataLen:" << _dataPcm.size();
return len;
}
qint64 AudioDevice::writeData(const char *data, qint64 len)
{
T_UNUSED(data);
T_UNUSED(len);
return 0;
}