2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-03-29 15:59:37 +00:00
|
|
|
#include "common/endian.h"
|
|
|
|
|
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 {
|
|
|
|
|
2009-02-13 16:55:16 +00:00
|
|
|
AdlibMusic::AdlibMusic(Audio::Mixer *pMixer, Disk *pDisk) : MusicBase(pDisk) {
|
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
|
|
|
|
2007-03-18 14:08:34 +00:00
|
|
|
_mixer->playInputStream(Audio::Mixer::kMusicSoundType, &_soundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, false, true);
|
2003-05-03 02:59:45 +00:00
|
|
|
}
|
|
|
|
|
2004-01-03 15:57:57 +00:00
|
|
|
AdlibMusic::~AdlibMusic(void) {
|
2008-06-06 16:40:39 +00:00
|
|
|
OPLDestroy(_opl);
|
2007-02-20 18:50:17 +00:00
|
|
|
_mixer->stopHandle(_soundHandle);
|
2003-06-22 21:42:59 +00:00
|
|
|
}
|
|
|
|
|
2007-03-10 17:39:27 +00:00
|
|
|
int AdlibMusic::readBuffer(int16 *data, const int numSamples) {
|
2003-05-03 02:59:45 +00:00
|
|
|
if (_musicData == NULL) {
|
|
|
|
// no music loaded
|
2007-03-10 17:39:27 +00:00
|
|
|
memset(data, 0, numSamples * sizeof(int16));
|
2003-05-03 02:59:45 +00:00
|
|
|
} else if ((_currentMusic == 0) || (_numberOfChannels == 0)) {
|
|
|
|
// music loaded but not played as of yet
|
2007-03-10 17:39:27 +00:00
|
|
|
memset(data, 0, numSamples * sizeof(int16));
|
2003-05-03 02:59:45 +00:00
|
|
|
// poll anyways as pollMusic() can activate the music
|
|
|
|
pollMusic();
|
2007-03-10 17:39:27 +00:00
|
|
|
_nextMusicPoll = _sampleRate / 50;
|
2003-09-18 16:01:33 +00:00
|
|
|
} else {
|
|
|
|
uint32 render;
|
2007-03-10 22:49:19 +00:00
|
|
|
uint remaining = numSamples;
|
2007-03-10 17:39:27 +00:00
|
|
|
while (remaining) {
|
2007-03-10 22:49:19 +00:00
|
|
|
render = (remaining > _nextMusicPoll) ? _nextMusicPoll : remaining;
|
2007-03-10 17:39:27 +00:00
|
|
|
remaining -= render;
|
2003-09-18 16:01:33 +00:00
|
|
|
_nextMusicPoll -= render;
|
|
|
|
YM3812UpdateOne(_opl, data, render);
|
|
|
|
data += render;
|
|
|
|
if (_nextMusicPoll == 0) {
|
|
|
|
pollMusic();
|
2007-03-10 17:39:27 +00:00
|
|
|
_nextMusicPoll = _sampleRate / 50;
|
2003-09-18 16:01:33 +00:00
|
|
|
}
|
|
|
|
}
|
2003-05-03 02:59:45 +00:00
|
|
|
}
|
2007-03-10 17:39:27 +00:00
|
|
|
return numSamples;
|
2003-05-03 02:59:45 +00:00
|
|
|
}
|
|
|
|
|
2004-01-03 15:57:57 +00:00
|
|
|
void AdlibMusic::setupPointers(void) {
|
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++) {
|
2007-03-18 14:08:34 +00:00
|
|
|
uint16 chDataStart = READ_LE_UINT16((uint16 *)channelData + cnt) + _musicDataLoc;
|
2004-01-03 15:57:57 +00:00
|
|
|
_channels[cnt] = new AdlibChannel(_opl, _musicData, chDataStart);
|
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;
|
2007-03-18 14:08:34 +00:00
|
|
|
while (_initSequence[cnt] || _initSequence[cnt + 1]) {
|
|
|
|
OPLWriteReg (_opl, _initSequence[cnt], _initSequence[cnt + 1]);
|
2003-05-03 02:59:45 +00:00
|
|
|
cnt += 2;
|
|
|
|
}
|
2007-03-18 14:08:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AdlibMusic::setVolume(uint16 param) {
|
|
|
|
_musicVolume = param;
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, 2 * param);
|
|
|
|
}
|
|
|
|
|
2007-09-19 08:40:12 +00:00
|
|
|
bool AdlibMusic::isStereo(void) const {
|
|
|
|
return false;
|
2007-03-18 14:08:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AdlibMusic::endOfData(void) const {
|
2007-09-19 08:40:12 +00:00
|
|
|
return false;
|
2007-03-18 14:08:34 +00:00
|
|
|
}
|
|
|
|
|
2007-09-19 08:40:12 +00:00
|
|
|
int AdlibMusic::getRate(void) const {
|
|
|
|
return _sampleRate;
|
2003-05-03 02:59:45 +00:00
|
|
|
}
|
2004-01-03 01:58:58 +00:00
|
|
|
|
|
|
|
} // End of namespace Sky
|