-
Notifications
You must be signed in to change notification settings - Fork 0
/
buzzichelper.cpp
68 lines (57 loc) · 1.25 KB
/
buzzichelper.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
#include "buzzichelper.h"
BuzzicHelper::BuzzicHelper(const QString &path)
: m_path(path)
{
}
BuzzicHelper::~BuzzicHelper()
{
deinit();
}
void BuzzicHelper::deinit()
{
if(m_input)
{
Buzzic2Release(m_input);
}
}
bool BuzzicHelper::initialize()
{
QFile file(m_path);
if(!file.open(QIODevice::ReadOnly))
{
qWarning("BuzzicHelper: open file failed");
return false;
}
const QByteArray &buffer = file.readAll();
file.close();
m_input = Buzzic2Load((unsigned char *)buffer.constData(), buffer.length());
if(!m_input)
{
qWarning("BuzzicHelper: failed to Buzzic2Load");
return false;
}
return true;
}
qint64 BuzzicHelper::read(unsigned char *data, qint64 maxSize)
{
const int offset = sizeof(float) * channels();
return Buzzic2Render(m_input, (StereoSample*)data, maxSize / offset) * offset;
}
QString BuzzicHelper::instruments() const
{
QString name;
for(int i = 0; i < instrumentCount(); ++i)
{
const char* v = Buzzic2IntrumentName(m_input, i);
if(v)
{
name += v;
name += "\n";
}
}
return name;
}
uint32_t BuzzicHelper::instrumentCount() const
{
return Buzzic2NumIntruments(m_input);
}