Mercurial > audlegacy-plugins
comparison src/Input/adplug/core/dfm.cxx @ 0:13389e613d67 trunk
[svn] - initial import of audacious-plugins tree (lots to do)
author | nenolod |
---|---|
date | Mon, 18 Sep 2006 01:11:49 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13389e613d67 |
---|---|
1 /* | |
2 * Adplug - Replayer for many OPL2/OPL3 audio file formats. | |
3 * Copyright (C) 1999 - 2003 Simon Peter, <dn.tlp@gmx.net>, et al. | |
4 * | |
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. | |
9 * | |
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. | |
14 * | |
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
18 * | |
19 * dfm.cpp - Digital-FM Loader by Simon Peter <dn.tlp@gmx.net> | |
20 */ | |
21 | |
22 #include <stdio.h> | |
23 #include <string.h> | |
24 | |
25 #include "dfm.h" | |
26 #include "debug.h" | |
27 | |
28 CPlayer *CdfmLoader::factory(Copl *newopl) | |
29 { | |
30 return new CdfmLoader(newopl); | |
31 } | |
32 | |
33 bool CdfmLoader::load(const std::string &filename, const CFileProvider &fp) | |
34 { | |
35 binistream *f = fp.open(filename); if(!f) return false; | |
36 unsigned char npats,n,note,fx,c,r,param; | |
37 unsigned int i; | |
38 const unsigned char convfx[8] = {255,255,17,19,23,24,255,13}; | |
39 | |
40 // file validation | |
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; } | |
45 | |
46 // load | |
47 restartpos = 0; flags = Standard; bpm = 0; | |
48 init_trackord(); | |
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); | |
65 } | |
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++) { | |
70 n = f->readInt(1); | |
71 for(r = 0; r < 64; r++) | |
72 for(c = 0; c < 9; c++) { | |
73 note = f->readInt(1); | |
74 if((note & 15) == 15) | |
75 tracks[n*9+c][r].note = 127; // key off | |
76 else | |
77 tracks[n*9+c][r].note = ((note & 127) >> 4) * 12 + (note & 15); | |
78 if(note & 128) { // additional effect byte | |
79 fx = f->readInt(1); | |
80 if(fx >> 5 == 1) | |
81 tracks[n*9+c][r].inst = (fx & 31) + 1; | |
82 else { | |
83 tracks[n*9+c][r].command = convfx[fx >> 5]; | |
84 if(tracks[n*9+c][r].command == 17) { // set volume | |
85 param = fx & 31; | |
86 param = 63 - param * 2; | |
87 tracks[n*9+c][r].param1 = param >> 4; | |
88 tracks[n*9+c][r].param2 = param & 15; | |
89 } else { | |
90 tracks[n*9+c][r].param1 = (fx & 31) >> 4; | |
91 tracks[n*9+c][r].param2 = fx & 15; | |
92 } | |
93 } | |
94 } | |
95 | |
96 } | |
97 } | |
98 | |
99 fp.close(f); | |
100 rewind(0); | |
101 return true; | |
102 } | |
103 | |
104 std::string CdfmLoader::gettype() | |
105 { | |
106 char tmpstr[20]; | |
107 | |
108 sprintf(tmpstr,"Digital-FM %d.%d",header.hiver,header.lover); | |
109 return std::string(tmpstr); | |
110 } | |
111 | |
112 float CdfmLoader::getrefresh() | |
113 { | |
114 return 125.0f; | |
115 } |