-
Notifications
You must be signed in to change notification settings - Fork 1
/
adplughelper.cpp
150 lines (135 loc) · 3.52 KB
/
adplughelper.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "adplughelper.h"
#include <qmmp/qmmp.h>
#include <QSettings>
#include <adplug/emuopl.h>
#include <adplug/kemuopl.h>
#include <adplug/nemuopl.h>
#include <adplug/wemuopl.h>
#include <adplug/surroundopl.h>
AdPlugHelper::AdPlugHelper(const QString &path)
: m_path(path)
{
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
QSettings settings;
#else
QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
#endif
settings.beginGroup("AdPlug");
const int type = settings.value("emulator", 0).toInt();
const bool surround = settings.value("use_surround", false).toBool();
settings.endGroup();
switch(type)
{
case 0:
if(surround)
{
COPLprops a;
a.opl = new CEmuopl(sampleRate(), true, false);
a.use16bit = true;
a.stereo = true;
COPLprops b;
b.opl = new CEmuopl(sampleRate(), true, false);
b.use16bit = true;
b.stereo = true;
m_opl = new CSurroundopl(&a, &b, true);
}
else
{
m_opl = new CEmuopl(sampleRate(), true, false);
}
break;
case 1:
if(surround)
{
COPLprops a;
a.opl = new CNemuopl(sampleRate());
a.use16bit = true;
a.stereo = true;
COPLprops b;
b.opl = new CNemuopl(sampleRate());
b.use16bit = true;
b.stereo = true;
m_opl = new CSurroundopl(&a, &b, true);
}
else
{
m_opl = new CNemuopl(sampleRate());
}
break;
case 2:
if(surround)
{
COPLprops a;
a.opl = new CWemuopl(sampleRate(), true, false);
a.use16bit = true;
a.stereo = true;
COPLprops b;
b.opl = new CWemuopl(sampleRate(), true, false);
b.use16bit = true;
b.stereo = true;
m_opl = new CSurroundopl(&a, &b, true);
}
else
{
m_opl = new CWemuopl(sampleRate(), true, false);
}
break;
case 3:
if(surround)
{
COPLprops a;
a.opl = new CKemuopl(sampleRate(), true, false);
a.use16bit = true;
a.stereo = true;
COPLprops b;
b.opl = new CKemuopl(sampleRate(), true, false);
b.use16bit = true;
b.stereo = true;
m_opl = new CSurroundopl(&a, &b, true);
}
else
{
m_opl = new CKemuopl(sampleRate(), true, false);
}
break;
default:
break;
}
m_player = CAdPlug::factory(qPrintable(path), m_opl);
}
AdPlugHelper::~AdPlugHelper()
{
deinit();
}
AdPlugHelper::Frame AdPlugHelper::read()
{
size_t to_write;
const size_t bufsiz = sizeof(m_buf) / sizeof(*m_buf);
if(m_remaining == 0)
{
if(!m_player->update())
{
return Frame(0, nullptr);
}
m_remaining = sampleRate() / m_player->getrefresh();
}
to_write = m_remaining > bufsiz ? bufsiz : m_remaining;
m_opl->update(m_buf, to_write);
m_remaining -= to_write;
return Frame(to_write * 2, reinterpret_cast<unsigned char *>(m_buf));
}
void AdPlugHelper::deinit()
{
delete m_opl;
delete m_player;
}
QString AdPlugHelper::instruments() const
{
QString value;
for(unsigned int i = 0; i < instrumentCount(); ++i)
{
value += QString::fromStdString(m_player->getinstrument(i));
value += "\n";
}
return value;
}