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 * xsm.cpp - eXtra Simple Music Player, by Simon Peter <dn.tlp@gmx.net>
26 CxsmPlayer::CxsmPlayer(Copl *newopl)
27 : CPlayer(newopl), music(0)
31 CxsmPlayer::~CxsmPlayer()
33 if(music) delete [] music;
36 bool CxsmPlayer::load(const std::string &filename, const CFileProvider &fp)
38 binistream *f = fp.open(filename); if(!f) return false;
42 // check if header matches
43 f->readString(id, 6); songlen = f->readInt(2);
44 if(strncmp(id, "ofTAZ!", 6) || songlen > 3200) { fp.close(f); return false; }
46 // read and set instruments
47 for(i = 0; i < 9; i++) {
48 opl->write(0x20 + op_table[i], f->readInt(1));
49 opl->write(0x23 + op_table[i], f->readInt(1));
50 opl->write(0x40 + op_table[i], f->readInt(1));
51 opl->write(0x43 + op_table[i], f->readInt(1));
52 opl->write(0x60 + op_table[i], f->readInt(1));
53 opl->write(0x63 + op_table[i], f->readInt(1));
54 opl->write(0x80 + op_table[i], f->readInt(1));
55 opl->write(0x83 + op_table[i], f->readInt(1));
56 opl->write(0xe0 + op_table[i], f->readInt(1));
57 opl->write(0xe3 + op_table[i], f->readInt(1));
58 opl->write(0xc0 + op_table[i], f->readInt(1));
63 music = new char [songlen * 9];
64 for(i = 0; i < 9; i++)
65 for(j = 0; j < songlen; j++)
66 music[j * 9 + i] = f->readInt(1);
74 bool CxsmPlayer::update()
78 if(notenum >= songlen) {
83 for(c = 0; c < 9; c++)
84 if(music[notenum * 9 + c] != music[last * 9 + c])
85 opl->write(0xb0 + c, 0);
87 for(c = 0; c < 9; c++) {
88 if(music[notenum * 9 + c])
89 play_note(c, music[notenum * 9 + c] % 12, music[notenum * 9 + c] / 12);
99 void CxsmPlayer::rewind(int subsong)
105 float CxsmPlayer::getrefresh()
110 void CxsmPlayer::play_note(int c, int note, int octv)
112 int freq = note_table[note];
114 if(!note && !octv) freq = 0;
115 opl->write(0xa0 + c, freq & 0xff);
116 opl->write(0xb0 + c, (freq / 0xff) | 32 | (octv * 4));