-
Notifications
You must be signed in to change notification settings - Fork 1
/
decoder_openmpt.cpp
85 lines (69 loc) · 1.77 KB
/
decoder_openmpt.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
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "decoder_openmpt.h"
#include <QSettings>
DecoderOpenMPT *DecoderOpenMPT::m_instance = nullptr;
DecoderOpenMPT::DecoderOpenMPT(QIODevice *input)
: Decoder(input)
{
m_instance = this;
}
DecoderOpenMPT::~DecoderOpenMPT()
{
m_instance = nullptr;
delete m_helper;
}
DecoderOpenMPT *DecoderOpenMPT::instance()
{
return m_instance;
}
void DecoderOpenMPT::readSettings()
{
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
QSettings settings;
#else
QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
#endif
settings.beginGroup("OpenMPT");
m_helper->setInterpolator(settings.value("interpolator", INTERP_WINDOWED).toInt());
m_helper->setStereoSeparation(settings.value("stereo_separation", 100).toInt());
settings.endGroup();
}
bool DecoderOpenMPT::initialize()
{
if(!input())
return false;
if(!input()->isOpen() && !input()->open(QIODevice::ReadOnly))
return false;
m_helper = new OpenMPTHelper(input());
if(!m_helper->initialize())
{
qWarning("DecoderOpenMPT: initialize failed");
return false;
}
const int rate = m_helper->sampleRate();
const int channels = m_helper->channels();
if(rate == 0 || channels == 0)
{
qWarning("DecoderOpenMPT: rate or channel invalid");
return false;
}
readSettings();
configure(rate, channels, Qmmp::PCM_FLOAT);
qDebug("DecoderOpenMPT: initialize success");
return true;
}
qint64 DecoderOpenMPT::totalTime() const
{
return m_helper->totalTime();
}
int DecoderOpenMPT::bitrate() const
{
return m_helper->channelCount();
}
qint64 DecoderOpenMPT::read(unsigned char *data, qint64 maxSize)
{
return m_helper->read(data, maxSize);
}
void DecoderOpenMPT::seek(qint64 time)
{
m_helper->seek(time);
}