|
359
|
1 /*
|
|
|
2 * Adplug - Replayer for many OPL2/OPL3 audio file formats.
|
|
|
3 * Copyright (C) 1999 - 2002 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
18 *
|
|
|
19 * sng.cpp - SNG Player by Simon Peter <dn.tlp@gmx.net>
|
|
|
20 */
|
|
|
21
|
|
|
22 #include "sng.h"
|
|
|
23
|
|
|
24 CPlayer *CsngPlayer::factory(Copl *newopl)
|
|
|
25 {
|
|
|
26 return new CsngPlayer(newopl);
|
|
|
27 }
|
|
|
28
|
|
|
29 bool CsngPlayer::load(const std::string &filename, const CFileProvider &fp)
|
|
|
30 {
|
|
|
31 binistream *f = fp.open(filename); if(!f) return false;
|
|
|
32 int i;
|
|
|
33
|
|
|
34 // load header
|
|
|
35 f->readString(header.id, 4);
|
|
|
36 header.length = f->readInt(2); header.start = f->readInt(2);
|
|
|
37 header.loop = f->readInt(2); header.delay = f->readInt(1);
|
|
|
38 header.compressed = f->readInt(1) ? true : false;
|
|
|
39
|
|
|
40 // file validation section
|
|
|
41 if(strncmp(header.id,"ObsM",4)) { fp.close(f); return false; }
|
|
|
42
|
|
|
43 // load section
|
|
|
44 header.length /= 2; header.start /= 2; header.loop /= 2;
|
|
|
45 data = new Sdata [header.length];
|
|
|
46 for(i = 0; i < header.length; i++) {
|
|
|
47 data[i].val = f->readInt(1);
|
|
|
48 data[i].reg = f->readInt(1);
|
|
|
49 }
|
|
|
50
|
|
|
51 rewind(0);
|
|
|
52 fp.close(f);
|
|
|
53 return true;
|
|
|
54 }
|
|
|
55
|
|
|
56 bool CsngPlayer::update()
|
|
|
57 {
|
|
|
58 if(header.compressed && del) {
|
|
|
59 del--;
|
|
|
60 return !songend;
|
|
|
61 }
|
|
|
62
|
|
|
63 while(data[pos].reg) {
|
|
|
64 opl->write(data[pos].reg, data[pos].val);
|
|
|
65 pos++;
|
|
|
66 if(pos >= header.length) {
|
|
|
67 songend = true;
|
|
|
68 pos = header.loop;
|
|
|
69 }
|
|
|
70 }
|
|
|
71
|
|
|
72 if(!header.compressed)
|
|
|
73 opl->write(data[pos].reg, data[pos].val);
|
|
|
74
|
|
|
75 if(data[pos].val) del = data[pos].val - 1; pos++;
|
|
|
76 if(pos >= header.length) { songend = true; pos = header.loop; }
|
|
|
77 return !songend;
|
|
|
78 }
|
|
|
79
|
|
|
80 void CsngPlayer::rewind(int subsong)
|
|
|
81 {
|
|
|
82 pos = header.start; del = header.delay; songend = false;
|
|
|
83 opl->init(); opl->write(1,32); // go to OPL2 mode
|
|
|
84 }
|