-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathayflyhelper.cpp
55 lines (45 loc) · 1021 Bytes
/
ayflyhelper.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
#include "ayflyhelper.h"
bool endCallback(void *)
{
return true;
}
AyflyHelper::AyflyHelper(const QString &path)
: m_path(path)
{
}
AyflyHelper::~AyflyHelper()
{
deinit();
}
void AyflyHelper::deinit()
{
if(m_input)
{
ay_closesong(&m_input);
}
}
bool AyflyHelper::initialize()
{
QFile file(m_path);
if(!file.open(QIODevice::ReadOnly))
{
qWarning("AyflyHelper: open file failed");
return false;
}
const QByteArray &buffer = file.readAll();
file.close();
if(!ay_initsongindirect((unsigned char *)buffer.constData(), sampleRate(), buffer.length()))
{
qWarning("AyflyHelper: ay_initsongindirect error");
return false;
}
m_input = ay_initsong(qPrintable(m_path), sampleRate());
if(!m_input)
{
qWarning("AyflyHelper: ay_initsong error");
return false;
}
m_length = ay_getsonglength(m_input) / 50 * 1000;
ay_setelapsedcallback(m_input, endCallback, nullptr);
return true;
}