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 * dro2.cpp - DOSBox Raw OPL v2.0 player by Adam Nielsen <malvineous@shikadi.net>
27 CPlayer *Cdro2Player::factory(Copl *newopl)
29 return new Cdro2Player(newopl);
32 Cdro2Player::Cdro2Player(Copl *newopl) :
39 Cdro2Player::~Cdro2Player()
41 if (this->data) delete[] this->data;
42 if (this->piConvTable) delete[] this->piConvTable;
45 bool Cdro2Player::load(const std::string &filename, const CFileProvider &fp)
47 binistream *f = fp.open(filename);
52 if (strncmp(id, "DBRAWOPL", 8)) {
56 int version = f->readInt(4);
62 this->iLength = f->readInt(4) * 2; // stored in file as number of byte pairs
63 f->ignore(4); // Length in milliseconds
64 f->ignore(1); /// OPL type (0 == OPL2, 1 == Dual OPL2, 2 == OPL3)
65 int iFormat = f->readInt(1);
70 int iCompression = f->readInt(1);
71 if (iCompression != 0) {
75 this->iCmdDelayS = f->readInt(1);
76 this->iCmdDelayL = f->readInt(1);
77 this->iConvTableLen = f->readInt(1);
79 this->piConvTable = new uint8_t[this->iConvTableLen];
80 f->readString((char *)this->piConvTable, this->iConvTableLen);
82 this->data = new uint8_t[this->iLength];
83 f->readString((char *)this->data, this->iLength);
91 bool Cdro2Player::update()
93 while (this->iPos < this->iLength) {
94 int iIndex = this->data[this->iPos++];
95 int iValue = this->data[this->iPos++];
98 if (iIndex == this->iCmdDelayS) {
99 this->iDelay = iValue + 1;
103 } else if (iIndex == this->iCmdDelayL) {
104 this->iDelay = (iValue + 1) << 8;
110 // High bit means use second chip in dual-OPL2 config
111 this->opl->setchip(1);
114 this->opl->setchip(0);
116 if (iIndex > this->iConvTableLen) {
117 printf("DRO2: Error - index beyond end of codemap table! Corrupted .dro?\n");
120 int iReg = this->piConvTable[iIndex];
121 this->opl->write(iReg, iValue);
126 // This won't result in endless-play using Adplay, but IMHO that code belongs
127 // in Adplay itself, not here.
128 return this->iPos < this->iLength;
131 void Cdro2Player::rewind(int subsong)
138 float Cdro2Player::getrefresh()
140 if (this->iDelay > 0) return 1000.0 / this->iDelay;