forked from native-toolkit/libmodplug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modplug.cpp
275 lines (229 loc) · 6.41 KB
/
modplug.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
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*
* This source code is public domain.
*
* Authors: Kenton Varda <[email protected]> (C interface wrapper)
*/
#include "modplug.h"
#include "stdafx.h"
#include "sndfile.h"
struct _ModPlugFile
{
CSoundFile mSoundFile;
};
namespace ModPlug
{
ModPlug_Settings gSettings =
{
MODPLUG_ENABLE_OVERSAMPLING | MODPLUG_ENABLE_NOISE_REDUCTION,
2, // mChannels
16, // mBits
44100, // mFrequency
MODPLUG_RESAMPLE_LINEAR, //mResamplingMode
128, // mStereoSeparation
32, // mMaxMixChannels
0,
0,
0,
0,
0,
0,
0
};
int gSampleSize;
void UpdateSettings(bool updateBasicConfig)
{
if(gSettings.mFlags & MODPLUG_ENABLE_REVERB)
{
CSoundFile::SetReverbParameters(gSettings.mReverbDepth,
gSettings.mReverbDelay);
}
if(gSettings.mFlags & MODPLUG_ENABLE_MEGABASS)
{
CSoundFile::SetXBassParameters(gSettings.mBassAmount,
gSettings.mBassRange);
}
else // modplug seems to ignore the SetWaveConfigEx() setting for bass boost
CSoundFile::SetXBassParameters(0, 0);
if(gSettings.mFlags & MODPLUG_ENABLE_SURROUND)
{
CSoundFile::SetSurroundParameters(gSettings.mSurroundDepth,
gSettings.mSurroundDelay);
}
if(updateBasicConfig)
{
CSoundFile::SetWaveConfig(gSettings.mFrequency,
gSettings.mBits,
gSettings.mChannels);
CSoundFile::SetMixConfig(gSettings.mStereoSeparation,
gSettings.mMaxMixChannels);
gSampleSize = gSettings.mBits / 8 * gSettings.mChannels;
}
CSoundFile::SetWaveConfigEx(gSettings.mFlags & MODPLUG_ENABLE_SURROUND,
!(gSettings.mFlags & MODPLUG_ENABLE_OVERSAMPLING),
gSettings.mFlags & MODPLUG_ENABLE_REVERB,
true,
gSettings.mFlags & MODPLUG_ENABLE_MEGABASS,
gSettings.mFlags & MODPLUG_ENABLE_NOISE_REDUCTION,
false);
CSoundFile::SetResamplingMode(gSettings.mResamplingMode);
}
}
ModPlugFile* ModPlug_Load(const void* data, int size)
{
ModPlugFile* result = new ModPlugFile;
ModPlug::UpdateSettings(true);
if(result->mSoundFile.Create((const BYTE*)data, size))
{
result->mSoundFile.SetRepeatCount(ModPlug::gSettings.mLoopCount);
return result;
}
else
{
delete result;
return NULL;
}
}
void ModPlug_Unload(ModPlugFile* file)
{
file->mSoundFile.Destroy();
delete file;
}
int ModPlug_Read(ModPlugFile* file, void* buffer, int size)
{
return file->mSoundFile.Read(buffer, size) * ModPlug::gSampleSize;
}
const char* ModPlug_GetName(ModPlugFile* file)
{
return file->mSoundFile.GetTitle();
}
int ModPlug_GetLength(ModPlugFile* file)
{
return file->mSoundFile.GetSongTime() * 1000;
}
void ModPlug_InitMixerCallback(ModPlugFile* file,ModPlugMixerProc proc)
{
file->mSoundFile.gpSndMixHook = (LPSNDMIXHOOKPROC)proc ;
return;
}
void ModPlug_UnloadMixerCallback(ModPlugFile* file)
{
file->mSoundFile.gpSndMixHook = NULL;
return ;
}
unsigned int ModPlug_GetMasterVolume(ModPlugFile* file)
{
return (unsigned int)file->mSoundFile.m_nMasterVolume;
}
void ModPlug_SetMasterVolume(ModPlugFile* file,unsigned int cvol)
{
(void)file->mSoundFile.SetMasterVolume( (UINT)cvol,
FALSE );
return ;
}
int ModPlug_GetCurrentSpeed(ModPlugFile* file)
{
return file->mSoundFile.m_nMusicSpeed;
}
int ModPlug_GetCurrentTempo(ModPlugFile* file)
{
return file->mSoundFile.m_nMusicTempo;
}
int ModPlug_GetCurrentOrder(ModPlugFile* file)
{
return file->mSoundFile.GetCurrentOrder();
}
int ModPlug_GetCurrentPattern(ModPlugFile* file)
{
return file->mSoundFile.GetCurrentPattern();
}
int ModPlug_GetCurrentRow(ModPlugFile* file)
{
return file->mSoundFile.m_nRow;
}
int ModPlug_GetPlayingChannels(ModPlugFile* file)
{
return ( file->mSoundFile.m_nMixChannels < file->mSoundFile.m_nMaxMixChannels ? file->mSoundFile.m_nMixChannels : file->mSoundFile.m_nMaxMixChannels );
}
void ModPlug_SeekOrder(ModPlugFile* file,int order)
{
file->mSoundFile.SetCurrentOrder(order);
}
int ModPlug_GetModuleType(ModPlugFile* file)
{
return file->mSoundFile.m_nType;
}
char* ModPlug_GetMessage(ModPlugFile* file)
{
return file->mSoundFile.m_lpszSongComments;
}
#ifndef MODPLUG_NO_FILESAVE
char ModPlug_ExportS3M(ModPlugFile* file,const char* filepath)
{
return (char)file->mSoundFile.SaveS3M(filepath,0);
}
char ModPlug_ExportXM(ModPlugFile* file,const char* filepath)
{
return (char)file->mSoundFile.SaveXM(filepath,0);
}
char ModPlug_ExportMOD(ModPlugFile* file,const char* filepath)
{
return (char)file->mSoundFile.SaveMod(filepath,0);
}
char ModPlug_ExportIT(ModPlugFile* file,const char* filepath)
{
return (char)file->mSoundFile.SaveIT(filepath,0);
}
#endif // MODPLUG_NO_FILESAVE
unsigned int ModPlug_NumInstruments(ModPlugFile* file)
{
return file->mSoundFile.m_nInstruments;
}
unsigned int ModPlug_NumSamples(ModPlugFile* file)
{
return file->mSoundFile.m_nSamples;
}
unsigned int ModPlug_NumPatterns(ModPlugFile* file)
{
return file->mSoundFile.GetNumPatterns();
}
unsigned int ModPlug_NumChannels(ModPlugFile* file)
{
return file->mSoundFile.GetNumChannels();
}
unsigned int ModPlug_SampleName(ModPlugFile* file,unsigned int qual,char* buff)
{
return file->mSoundFile.GetSampleName(qual,buff);
}
unsigned int ModPlug_InstrumentName(ModPlugFile* file,unsigned int qual,char* buff)
{
return file->mSoundFile.GetInstrumentName(qual,buff);
}
ModPlugNote* ModPlug_GetPattern(ModPlugFile* file,int pattern,unsigned int* numrows) {
if ( pattern<MAX_PATTERNS ) {
if (file->mSoundFile.Patterns[pattern]) {
if (numrows) *numrows=(unsigned int)file->mSoundFile.PatternSize[pattern];
return (ModPlugNote*)file->mSoundFile.Patterns[pattern];
}
}
return NULL;
}
void ModPlug_Seek(ModPlugFile* file, int millisecond)
{
int maxpos;
int maxtime = file->mSoundFile.GetSongTime() * 1000;
float postime;
if(millisecond > maxtime)
millisecond = maxtime;
maxpos = file->mSoundFile.GetMaxPosition();
postime = (float)maxpos / (float)maxtime;
file->mSoundFile.SetCurrentPos((int)(millisecond * postime));
}
void ModPlug_GetSettings(ModPlug_Settings* settings)
{
memcpy(settings, &ModPlug::gSettings, sizeof(ModPlug_Settings));
}
void ModPlug_SetSettings(const ModPlug_Settings* settings)
{
memcpy(&ModPlug::gSettings, settings, sizeof(ModPlug_Settings));
ModPlug::UpdateSettings(false); // do not update basic config.
}