-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmpmoduleplayer.cpp
More file actions
213 lines (166 loc) · 4 KB
/
xmpmoduleplayer.cpp
File metadata and controls
213 lines (166 loc) · 4 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#include <xmpmoduleplayer.h>
#include <QMessageBox>
#include "mainwindow.h"
XmpModulePlayer::XmpModulePlayer(QObject* parent):
QThread(parent)
{
ctx = xmp_create_context();
QAudioFormat format;
// Set up the format, eg.
format.setSampleRate(44100);
format.setChannelCount(2);
format.setSampleSize(16);
format.setCodec("audio/pcm");
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::UnSignedInt);
audio = new QAudioOutput(format, NULL);
ourDevice = new ProxyDevice();
ourDevice->open(QIODevice::ReadWrite);
player_state = IDLE;
isLoop = 0;
connect(ourDevice, &ProxyDevice::feedAudio, this, &XmpModulePlayer::feedAudioSlot, Qt::DirectConnection);
}
void XmpModulePlayer::run()
{
}
ProxyDevice* XmpModulePlayer::getDevice()
{
return ourDevice;
}
void XmpModulePlayer::loadModule(char * filename)
{
if(xmp_load_module(ctx, filename) != 0)
{
//printf("Error on module loading!\n");
throw "Error on module loading!\n";
return;
}
xmp_get_module_info(ctx, &mi);
}
PLAY_STATE XmpModulePlayer::getPlayerState()
{
return player_state;
}
void XmpModulePlayer::startModule()
{
if(player_state == IDLE)
{
xmp_start_player(ctx, 44100, 0);
audio->start(ourDevice);
player_state = PLAYING;
}else if(player_state == PLAYING)
{
audio->suspend();
player_state = PAUSED;
}else if(player_state == PAUSED)
{
audio->resume();
player_state = PLAYING;
}
}
void XmpModulePlayer::pauseModule()
{
audio->suspend();
}
void XmpModulePlayer::resumeModule()
{
audio->resume();
}
char* XmpModulePlayer::getModuleTitle()
{
return mi.mod->name;
}
char *XmpModulePlayer::getModuleType()
{
return mi.mod->type;
}
char *XmpModulePlayer::getModuleComment()
{
return mi.comment;
}
QStringList XmpModulePlayer::getInstrumentNames()
{
QStringList ilist;
//qDebug() << "" << mi.mod->ins;
for(int i=1; i <= mi.mod->ins; i++)
{
QString str;
ilist.append(str.sprintf("%02X|%s", i, mi.mod->xxi[i].name));
}
return ilist;
}
qint32 XmpModulePlayer::getModuleLength()
{
return mi.mod->len;
}
qint32 XmpModulePlayer::getModuleBPM()
{
return mi.mod->bpm;
}
qint32 XmpModulePlayer::getModuleSpeed()
{
return mi.mod->spd;
}
qint32 XmpModulePlayer::getChannelNumber()
{
return mi.mod->chn;
}
void XmpModulePlayer::setPosition(qint32 pos)
{
xmp_set_position(ctx, pos);
}
void XmpModulePlayer::seek(quint32 time)
{
xmp_seek_time(ctx, time);
}
qint32 XmpModulePlayer::getTotalTime()
{
xmp_get_frame_info(ctx, &fi);
return fi.total_time;
}
//qint32 XmpModulePlayer::getModuleProgress()
//{
// xmp_get_frame_info(ctx, &fi);
// qint32 progress = fi.pos * 100 / mi.mod->len;
// return progress;
//}
void XmpModulePlayer::setLoop(bool loop)
{
isLoop = loop==true ? 1 : 0;
}
QAudioOutput* XmpModulePlayer::getAudio()
{
return audio;
}
void XmpModulePlayer::setVolume(qint32 volume)
{
qreal linearVolume = QAudio::convertVolume(volume / qreal(100.0),
QAudio::LogarithmicVolumeScale,
QAudio::LinearVolumeScale);
qDebug() << linearVolume;
// audio->setVolume(qRound(linearVolume * 100));
audio->setVolume(linearVolume + 1);
// audio->setVolume(qreal(100.0) / volume );
}
void XmpModulePlayer::feedAudioSlot(char* data, qint64 size, qint64& wasRead)
{
//if(xmp_play_buffer(ctx, data, size, isLoop) == 0)
if(xmp_play_frame(ctx) == 0)
{
xmp_get_frame_info(ctx, &fi);
memcpy(data, fi.buffer, fi.buffer_size);
//wasRead = size;
wasRead = fi.buffer_size;
emit sendFrameInfo(&mi, &fi);
}else
wasRead = 0;
}
void XmpModulePlayer::stopModule()
{
if(player_state == PLAYING || player_state == PAUSED)
{
audio->stop();
xmp_end_player(ctx);
player_state = IDLE;
}
}