2003-05-03 02:59:45 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2003-2006 The ScummVM project
|
2003-05-03 02:59:45 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-05-03 02:59:45 +00:00
|
|
|
*
|
2006-02-11 10:03:24 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2003-05-03 02:59:45 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-05-28 23:31:43 +00:00
|
|
|
#include "sky/music/adlibmusic.h"
|
2003-10-05 20:21:20 +00:00
|
|
|
#include "sky/music/adlibchannel.h"
|
|
|
|
#include "sound/mixer.h"
|
|
|
|
#include "sky/sky.h"
|
2003-05-03 02:59:45 +00:00
|
|
|
|
2004-01-03 01:58:58 +00:00
|
|
|
namespace Sky {
|
|
|
|
|
2005-05-10 23:48:48 +00:00
|
|
|
AdlibMusic::AdlibMusic(Audio::Mixer *pMixer, Disk *pDisk)
|
2005-01-28 22:05:51 +00:00
|
|
|
: MusicBase(pDisk) {
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-05-03 02:59:45 +00:00
|
|
|
_driverFileBase = 60202;
|
2003-10-01 09:40:28 +00:00
|
|
|
_mixer = pMixer;
|
2003-08-06 00:28:00 +00:00
|
|
|
_sampleRate = pMixer->getOutputRate();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-02-24 22:39:42 +00:00
|
|
|
_opl = makeAdlibOPL(_sampleRate);
|
2003-07-11 10:23:13 +00:00
|
|
|
|
2004-11-27 16:18:25 +00:00
|
|
|
_mixer->setupPremix(this);
|
2003-05-03 02:59:45 +00:00
|
|
|
}
|
|
|
|
|
2004-01-03 15:57:57 +00:00
|
|
|
AdlibMusic::~AdlibMusic(void) {
|
2003-05-03 02:59:45 +00:00
|
|
|
|
2004-10-17 19:40:05 +00:00
|
|
|
_mixer->setupPremix(0);
|
2003-06-22 21:42:59 +00:00
|
|
|
}
|
|
|
|
|
2004-01-03 15:57:57 +00:00
|
|
|
void AdlibMusic::premixerCall(int16 *data, uint len) {
|
2003-05-03 02:59:45 +00:00
|
|
|
|
|
|
|
if (_musicData == NULL) {
|
|
|
|
// no music loaded
|
2003-09-18 16:01:33 +00:00
|
|
|
memset(data, 0, 2 * len * sizeof(int16));
|
2003-05-03 02:59:45 +00:00
|
|
|
} else if ((_currentMusic == 0) || (_numberOfChannels == 0)) {
|
|
|
|
// music loaded but not played as of yet
|
2003-09-18 16:01:33 +00:00
|
|
|
memset(data, 0, 2 * len * sizeof(int16));
|
2003-05-03 02:59:45 +00:00
|
|
|
// poll anyways as pollMusic() can activate the music
|
|
|
|
pollMusic();
|
|
|
|
_nextMusicPoll = _sampleRate/50;
|
2003-09-18 16:01:33 +00:00
|
|
|
} else {
|
|
|
|
uint32 render;
|
|
|
|
int16 *origData = data;
|
|
|
|
uint origLen = len;
|
|
|
|
while (len) {
|
|
|
|
render = (len > _nextMusicPoll) ? (_nextMusicPoll) : (len);
|
|
|
|
len -= render;
|
|
|
|
_nextMusicPoll -= render;
|
|
|
|
YM3812UpdateOne(_opl, data, render);
|
|
|
|
data += render;
|
|
|
|
if (_nextMusicPoll == 0) {
|
|
|
|
pollMusic();
|
|
|
|
_nextMusicPoll = _sampleRate/50;
|
|
|
|
}
|
|
|
|
}
|
2003-11-08 20:27:27 +00:00
|
|
|
|
2003-09-18 16:01:33 +00:00
|
|
|
// Convert mono data to stereo
|
|
|
|
for (int i = (origLen - 1); i >= 0; i--) {
|
|
|
|
origData[2 * i] = origData[2 * i + 1] = origData[i];
|
2003-05-03 02:59:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-03 15:57:57 +00:00
|
|
|
void AdlibMusic::setupPointers(void) {
|
2003-05-03 02:59:45 +00:00
|
|
|
|
2003-10-05 20:21:20 +00:00
|
|
|
if (SkyEngine::_systemVars.gameVersion == 109) {
|
2003-05-28 23:31:43 +00:00
|
|
|
// disk demo uses a different adlib driver version, some offsets have changed
|
2003-07-13 06:04:11 +00:00
|
|
|
//_musicDataLoc = (_musicData[0x11CC] << 8) | _musicData[0x11CB];
|
|
|
|
//_initSequence = _musicData + 0xEC8;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-07-13 06:04:11 +00:00
|
|
|
_musicDataLoc = READ_LE_UINT16(_musicData + 0x1200);
|
|
|
|
_initSequence = _musicData + 0xEFB;
|
2003-10-05 20:21:20 +00:00
|
|
|
} else if (SkyEngine::_systemVars.gameVersion == 267) {
|
2003-07-13 06:04:11 +00:00
|
|
|
_musicDataLoc = READ_LE_UINT16(_musicData + 0x11F7);
|
2003-05-28 23:31:43 +00:00
|
|
|
_initSequence = _musicData + 0xE87;
|
|
|
|
} else {
|
2003-07-13 06:04:11 +00:00
|
|
|
_musicDataLoc = READ_LE_UINT16(_musicData + 0x1201);
|
2003-05-28 23:31:43 +00:00
|
|
|
_initSequence = _musicData + 0xE91;
|
|
|
|
}
|
2003-05-03 02:59:45 +00:00
|
|
|
_nextMusicPoll = 0;
|
|
|
|
}
|
|
|
|
|
2004-01-03 15:57:57 +00:00
|
|
|
void AdlibMusic::setupChannels(uint8 *channelData) {
|
2003-05-03 02:59:45 +00:00
|
|
|
|
|
|
|
_numberOfChannels = channelData[0];
|
|
|
|
channelData++;
|
|
|
|
for (uint8 cnt = 0; cnt < _numberOfChannels; cnt++) {
|
|
|
|
uint16 chDataStart = ((channelData[(cnt << 1) | 1] << 8) | channelData[cnt << 1]) + _musicDataLoc;
|
2004-01-03 15:57:57 +00:00
|
|
|
_channels[cnt] = new AdlibChannel(_opl, _musicData, chDataStart);
|
2005-12-05 05:02:43 +00:00
|
|
|
_channels[cnt]->updateVolume(_musicVolume);
|
2003-05-03 02:59:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-03 15:57:57 +00:00
|
|
|
void AdlibMusic::startDriver(void) {
|
2003-05-03 02:59:45 +00:00
|
|
|
|
|
|
|
uint16 cnt = 0;
|
|
|
|
while (_initSequence[cnt] || _initSequence[cnt+1]) {
|
2003-07-11 07:14:21 +00:00
|
|
|
OPLWriteReg (_opl, _initSequence[cnt], _initSequence[cnt+1]);
|
2003-05-03 02:59:45 +00:00
|
|
|
cnt += 2;
|
|
|
|
}
|
|
|
|
_allowedCommands = 0xD;
|
|
|
|
}
|
2004-01-03 01:58:58 +00:00
|
|
|
|
|
|
|
} // End of namespace Sky
|