-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasaphelper.cpp
70 lines (58 loc) · 1.73 KB
/
asaphelper.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
#include "asaphelper.h"
AsapHelper::AsapHelper(const QString &path)
: m_path(path)
{
}
AsapHelper::~AsapHelper()
{
deinit();
}
void AsapHelper::deinit()
{
if(m_input)
{
ASAP_Delete(m_input);
}
}
bool AsapHelper::initialize()
{
QFile file(m_path);
if(!file.open(QIODevice::ReadOnly))
{
qWarning("AsapHelper: open file failed");
return false;
}
const QByteArray &buffer = file.readAll();
file.close();
m_input = ASAP_New();
ASAP_DetectSilence(m_input, 5);
if(!ASAP_Load(m_input, qPrintable(m_path), (unsigned char *)buffer.constData(), buffer.length()))
{
qWarning("AsapHelper: ASAP_Load error");
return false;
}
ASAPInfo *info =(ASAPInfo *)ASAP_GetInfo(m_input);
//struct ASAPInfo { int channels; int covoxAddr; int defaultSong; int fastplay; int headerLen;
// int init; int music; cibool ntsc; int player; int songs; ASAPModuleType type;
// unsigned char songPos[32]; char author[128]; char date[128]; int durations[32];
// char filename[128]; cibool loops[32]; char title[128]; };
if(!ASAP_PlaySong(m_input, ASAPInfo_GetDefaultSong(info), 360000))
{
qWarning("AsapHelper: ASAP_PlaySong error");
return false;
}
m_title = ASAPInfo_GetTitle(info);
m_author = ASAPInfo_GetAuthor(info);
m_year = QString::number(ASAPInfo_GetYear(info));
m_length = ASAPInfo_GetDuration(info, ASAPInfo_GetDefaultSong(info));
m_channels = ASAPInfo_GetChannels(info);
return true;
}
qint64 AsapHelper::read(unsigned char *data, qint64 maxSize)
{
if(ASAP_GetPosition(m_input) >= totalTime())
{
return 0;
}
return ASAP_Generate(m_input, data, maxSize, ASAPSampleFormat_S16_L_E);
}