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
|
/*
* Adplug - Replayer for many OPL2/OPL3 audio file formats.
* Copyright (C) 1999 - 2003 Simon Peter, <dn.tlp@gmx.net>, et al.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* dfm.cpp - Digital-FM Loader by Simon Peter <dn.tlp@gmx.net>
*/
#include <stdio.h>
#include <string.h>
#include "dfm.h"
#include "debug.h"
CPlayer *CdfmLoader::factory(Copl *newopl)
{
return new CdfmLoader(newopl);
}
bool CdfmLoader::load(const char *filename, const CFileProvider &fp)
{
binistream *f = fp.open(filename); if(!f) return false;
unsigned char npats,n,note,fx,c,r,param;
unsigned int i;
const unsigned char convfx[8] = {255,255,17,19,23,24,255,13};
// file validation
f->readString(header.id, 4);
header.hiver = f->readInt(1); header.lover = f->readInt(1);
if(strncmp(header.id,"DFM\x1a",4) || header.hiver > 1)
{ fp.close(f); return false; }
// load
restartpos = 0; flags = Standard; bpm = 0;
init_trackord();
f->readString(songinfo, 33);
initspeed = f->readInt(1);
for(i = 0; i < 32; i++)
f->readString(instname[i], 12);
for(i = 0; i < 32; i++) {
inst[i].data[1] = f->readInt(1);
inst[i].data[2] = f->readInt(1);
inst[i].data[9] = f->readInt(1);
inst[i].data[10] = f->readInt(1);
inst[i].data[3] = f->readInt(1);
inst[i].data[4] = f->readInt(1);
inst[i].data[5] = f->readInt(1);
inst[i].data[6] = f->readInt(1);
inst[i].data[7] = f->readInt(1);
inst[i].data[8] = f->readInt(1);
inst[i].data[0] = f->readInt(1);
}
for(i = 0; i < 128; i++) order[i] = f->readInt(1);
for(i = 0; i < 128 && order[i] != 128; i++) ; length = i;
npats = f->readInt(1);
for(i = 0; i < npats; i++) {
n = f->readInt(1);
for(r = 0; r < 64; r++)
for(c = 0; c < 9; c++) {
note = f->readInt(1);
if((note & 15) == 15)
tracks[n*9+c][r].note = 127; // key off
else
tracks[n*9+c][r].note = ((note & 127) >> 4) * 12 + (note & 15);
if(note & 128) { // additional effect byte
fx = f->readInt(1);
if(fx >> 5 == 1)
tracks[n*9+c][r].inst = (fx & 31) + 1;
else {
tracks[n*9+c][r].command = convfx[fx >> 5];
if(tracks[n*9+c][r].command == 17) { // set volume
param = fx & 31;
param = 63 - param * 2;
tracks[n*9+c][r].param1 = param >> 4;
tracks[n*9+c][r].param2 = param & 15;
} else {
tracks[n*9+c][r].param1 = (fx & 31) >> 4;
tracks[n*9+c][r].param2 = fx & 15;
}
}
}
}
}
fp.close(f);
rewind(0);
return true;
}
const char * CdfmLoader::gettype()
{
sprintf(tmpstr,"Digital-FM %d.%d",header.hiver,header.lover);
return tmpstr;
}
float CdfmLoader::getrefresh()
{
return 125.0f;
}
|