-
Notifications
You must be signed in to change notification settings - Fork 1
/
stsoundhelper.cpp
72 lines (62 loc) · 1.44 KB
/
stsoundhelper.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
71
72
#include "stsoundhelper.h"
StSoundHelper::StSoundHelper(const QString &path)
: m_path(path)
{
}
StSoundHelper::~StSoundHelper()
{
deinit();
}
void StSoundHelper::deinit()
{
if(m_input)
{
delete m_input;
}
}
bool StSoundHelper::initialize()
{
m_input = new CYmMusic;
if(!m_input)
{
qWarning("StSoundHelper: failed to create CYmMusic");
return false;
}
if(m_input->load(qPrintable(m_path)))
{
ymMusicInfo_t info;
m_input->getMusicInfo(&info);
m_input->setLoopMode(YMFALSE);
m_length = info.musicTimeInMs;
m_title = QString::fromUtf8(info.pSongName);
m_author = QString::fromUtf8(info.pSongAuthor);
m_comment = QString::fromUtf8(info.pSongComment);
}
else
{
if(m_input)
{
delete m_input;
}
m_input = nullptr;
qWarning("StSoundHelper: failed to open: %s", qPrintable(m_path));
return false;
}
return true;
}
qint64 StSoundHelper::read(unsigned char *data, qint64 maxSize)
{
ymsample *psample = (ymsample *)data;
const qint64 stereoSize = maxSize / (2 * sizeof(ymsample));
if(!m_input->update(psample, stereoSize))
{
return 0;
}
// recopy mono YM sound to 2 channels
for(qint64 i = stereoSize - 1; i >= 0; --i)
{
psample[(i * 2) ] = psample[i];
psample[(i * 2) + 1] = psample[i];
}
return maxSize;
}