2 * Adplug - Replayer for many OPL2/OPL3 audio file formats.
3 * Copyright (C) 1999 - 2002 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 * sng.cpp - SNG Player by Simon Peter <dn.tlp@gmx.net>
25 CPlayer *CsngPlayer::factory(Copl *newopl)
27 return new CsngPlayer(newopl);
30 bool CsngPlayer::load(const std::string &filename, const CFileProvider &fp)
32 binistream *f = fp.open(filename); if(!f) return false;
36 f->readString(header.id, 4);
37 header.length = f->readInt(2); header.start = f->readInt(2);
38 header.loop = f->readInt(2); header.delay = f->readInt(1);
39 header.compressed = f->readInt(1) ? true : false;
41 // file validation section
42 if(strncmp(header.id,"ObsM",4)) { fp.close(f); return false; }
45 header.length /= 2; header.start /= 2; header.loop /= 2;
46 data = new Sdata [header.length];
47 for(i = 0; i < header.length; i++) {
48 data[i].val = f->readInt(1);
49 data[i].reg = f->readInt(1);
57 bool CsngPlayer::update()
59 if(header.compressed && del) {
64 while(data[pos].reg) {
65 opl->write(data[pos].reg, data[pos].val);
67 if(pos >= header.length) {
73 if(!header.compressed)
74 opl->write(data[pos].reg, data[pos].val);
76 if(data[pos].val) del = data[pos].val - 1; pos++;
77 if(pos >= header.length) { songend = true; pos = header.loop; }
81 void CsngPlayer::rewind(int subsong)
83 pos = header.start; del = header.delay; songend = false;
84 opl->init(); opl->write(1,32); // go to OPL2 mode