2 * Adplug - Replayer for many OPL2/OPL3 audio file formats.
3 * Copyright (C) 1999 - 2003 Simon Peter, <dn.tlp@gmx.net>, et al.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * dfm.cpp - Digital-FM Loader by Simon Peter <dn.tlp@gmx.net>
28 CPlayer *CdfmLoader::factory(Copl *newopl)
30 return new CdfmLoader(newopl);
33 bool CdfmLoader::load(const std::string &filename, const CFileProvider &fp)
35 binistream *f = fp.open(filename); if(!f) return false;
36 unsigned char npats,n,note,fx,c,r,param;
38 const unsigned char convfx[8] = {255,255,17,19,23,24,255,13};
41 f->readString(header.id, 4);
42 header.hiver = f->readInt(1); header.lover = f->readInt(1);
43 if(strncmp(header.id,"DFM\x1a",4) || header.hiver > 1)
44 { fp.close(f); return false; }
47 restartpos = 0; flags = Standard; bpm = 0;
49 f->readString(songinfo, 33);
50 initspeed = f->readInt(1);
51 for(i = 0; i < 32; i++)
52 f->readString(instname[i], 12);
53 for(i = 0; i < 32; i++) {
54 inst[i].data[1] = f->readInt(1);
55 inst[i].data[2] = f->readInt(1);
56 inst[i].data[9] = f->readInt(1);
57 inst[i].data[10] = f->readInt(1);
58 inst[i].data[3] = f->readInt(1);
59 inst[i].data[4] = f->readInt(1);
60 inst[i].data[5] = f->readInt(1);
61 inst[i].data[6] = f->readInt(1);
62 inst[i].data[7] = f->readInt(1);
63 inst[i].data[8] = f->readInt(1);
64 inst[i].data[0] = f->readInt(1);
66 for(i = 0; i < 128; i++) order[i] = f->readInt(1);
67 for(i = 0; i < 128 && order[i] != 128; i++) ; length = i;
68 npats = f->readInt(1);
69 for(i = 0; i < npats; i++) {
71 for(r = 0; r < 64; r++)
72 for(c = 0; c < 9; c++) {
75 tracks[n*9+c][r].note = 127; // key off
77 tracks[n*9+c][r].note = ((note & 127) >> 4) * 12 + (note & 15);
78 if(note & 128) { // additional effect byte
81 tracks[n*9+c][r].inst = (fx & 31) + 1;
83 tracks[n*9+c][r].command = convfx[fx >> 5];
84 if(tracks[n*9+c][r].command == 17) { // set volume
86 param = 63 - param * 2;
87 tracks[n*9+c][r].param1 = param >> 4;
88 tracks[n*9+c][r].param2 = param & 15;
90 tracks[n*9+c][r].param1 = (fx & 31) >> 4;
91 tracks[n*9+c][r].param2 = fx & 15;
104 std::string CdfmLoader::gettype()
108 sprintf(tmpstr,"Digital-FM %d.%d",header.hiver,header.lover);
109 return std::string(tmpstr);
112 float CdfmLoader::getrefresh()