2 Adplug - Replayer for many OPL2/OPL3 audio file formats.
3 Copyright (C) 1999 - 2007 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 fmc.cpp - FMC Loader by Riven the Mage <riven@ok.ru>
25 /* -------- Public Methods -------------------------------- */
27 CPlayer *CfmcLoader::factory(Copl *newopl)
29 return new CfmcLoader(newopl);
32 bool CfmcLoader::load(const std::string &filename, const CFileProvider &fp)
34 binistream *f = fp.open(filename); if(!f) return false;
35 const unsigned char conv_fx[16] = {0,1,2,3,4,8,255,255,255,255,26,11,12,13,14,15};
40 f->readString(header.id, 4);
41 f->readString(header.title, 21);
42 header.numchan = f->readInt(1);
45 if (strncmp(header.id,"FMC!",4)) { fp.close(f); return false; }
48 realloc_instruments(32);
50 realloc_patterns(64,64,header.numchan);
54 for(i = 0; i < 256; i++) order[i] = f->readInt(1);
59 for(i = 0; i < 32; i++) {
60 instruments[i].synthesis = f->readInt(1);
61 instruments[i].feedback = f->readInt(1);
63 instruments[i].mod_attack = f->readInt(1);
64 instruments[i].mod_decay = f->readInt(1);
65 instruments[i].mod_sustain = f->readInt(1);
66 instruments[i].mod_release = f->readInt(1);
67 instruments[i].mod_volume = f->readInt(1);
68 instruments[i].mod_ksl = f->readInt(1);
69 instruments[i].mod_freq_multi = f->readInt(1);
70 instruments[i].mod_waveform = f->readInt(1);
71 instruments[i].mod_sustain_sound = f->readInt(1);
72 instruments[i].mod_ksr = f->readInt(1);
73 instruments[i].mod_vibrato = f->readInt(1);
74 instruments[i].mod_tremolo = f->readInt(1);
76 instruments[i].car_attack = f->readInt(1);
77 instruments[i].car_decay = f->readInt(1);
78 instruments[i].car_sustain = f->readInt(1);
79 instruments[i].car_release = f->readInt(1);
80 instruments[i].car_volume = f->readInt(1);
81 instruments[i].car_ksl = f->readInt(1);
82 instruments[i].car_freq_multi = f->readInt(1);
83 instruments[i].car_waveform = f->readInt(1);
84 instruments[i].car_sustain_sound = f->readInt(1);
85 instruments[i].car_ksr = f->readInt(1);
86 instruments[i].car_vibrato = f->readInt(1);
87 instruments[i].car_tremolo = f->readInt(1);
89 instruments[i].pitch_shift = f->readInt(1);
91 f->readString(instruments[i].name, 21);
99 for (j=0;j<header.numchan;j++)
106 event.byte0 = f->readInt(1);
107 event.byte1 = f->readInt(1);
108 event.byte2 = f->readInt(1);
111 tracks[t][k].note = event.byte0 & 0x7F;
112 tracks[t][k].inst = ((event.byte0 & 0x80) >> 3) + (event.byte1 >> 4) + 1;
113 tracks[t][k].command = conv_fx[event.byte1 & 0x0F];
114 tracks[t][k].param1 = event.byte2 >> 4;
115 tracks[t][k].param2 = event.byte2 & 0x0F;
118 if (tracks[t][k].command == 0x0E) // 0x0E (14): Retrig
119 tracks[t][k].param1 = 3;
120 if (tracks[t][k].command == 0x1A) { // 0x1A (26): Volume Slide
121 if (tracks[t][k].param1 > tracks[t][k].param2)
123 tracks[t][k].param1 -= tracks[t][k].param2;
124 tracks[t][k].param2 = 0;
128 tracks[t][k].param2 -= tracks[t][k].param1;
129 tracks[t][k].param1 = 0;
139 // convert instruments
146 if (order[i] >= 0xFE)
153 // data for Protracker
154 activechan = (0xffffffff >> (32 - header.numchan)) << (32 - header.numchan);
155 nop = t / header.numchan;
166 float CfmcLoader::getrefresh()
171 std::string CfmcLoader::gettype()
173 return std::string("Faust Music Creator");
176 std::string CfmcLoader::gettitle()
178 return std::string(header.title);
181 std::string CfmcLoader::getinstrument(unsigned int n)
183 return std::string(instruments[n].name);
186 unsigned int CfmcLoader::getinstruments()
191 /* -------- Private Methods ------------------------------- */
193 void CfmcLoader::buildinst(unsigned char i)
195 inst[i].data[0] = ((instruments[i].synthesis & 1) ^ 1);
196 inst[i].data[0] |= ((instruments[i].feedback & 7) << 1);
198 inst[i].data[3] = ((instruments[i].mod_attack & 15) << 4);
199 inst[i].data[3] |= (instruments[i].mod_decay & 15);
200 inst[i].data[5] = ((15 - (instruments[i].mod_sustain & 15)) << 4);
201 inst[i].data[5] |= (instruments[i].mod_release & 15);
202 inst[i].data[9] = (63 - (instruments[i].mod_volume & 63));
203 inst[i].data[9] |= ((instruments[i].mod_ksl & 3) << 6);
204 inst[i].data[1] = (instruments[i].mod_freq_multi & 15);
205 inst[i].data[7] = (instruments[i].mod_waveform & 3);
206 inst[i].data[1] |= ((instruments[i].mod_sustain_sound & 1) << 5);
207 inst[i].data[1] |= ((instruments[i].mod_ksr & 1) << 4);
208 inst[i].data[1] |= ((instruments[i].mod_vibrato & 1) << 6);
209 inst[i].data[1] |= ((instruments[i].mod_tremolo & 1) << 7);
211 inst[i].data[4] = ((instruments[i].car_attack & 15) << 4);
212 inst[i].data[4] |= (instruments[i].car_decay & 15);
213 inst[i].data[6] = ((15 - (instruments[i].car_sustain & 15)) << 4);
214 inst[i].data[6] |= (instruments[i].car_release & 15);
215 inst[i].data[10] = (63 - (instruments[i].car_volume & 63));
216 inst[i].data[10] |= ((instruments[i].car_ksl & 3) << 6);
217 inst[i].data[2] = (instruments[i].car_freq_multi & 15);
218 inst[i].data[8] = (instruments[i].car_waveform & 3);
219 inst[i].data[2] |= ((instruments[i].car_sustain_sound & 1) << 5);
220 inst[i].data[2] |= ((instruments[i].car_ksr & 1) << 4);
221 inst[i].data[2] |= ((instruments[i].car_vibrato & 1) << 6);
222 inst[i].data[2] |= ((instruments[i].car_tremolo & 1) << 7);
224 inst[i].slide = instruments[i].pitch_shift;