aboutsummaryrefslogtreecommitdiff
path: root/engines/sky
diff options
context:
space:
mode:
authorMatthew Hoops2015-04-04 19:29:52 -0400
committerMatthew Hoops2015-07-07 20:19:44 -0400
commitb122ec279073a003ce4fb1dd0cd652e3393c18e0 (patch)
treef200b2c306333ead31b5d86ef22890786a06c049 /engines/sky
parentb638efe0fad55e18513a9c0453100c0d3b9dd8c3 (diff)
downloadscummvm-rg350-b122ec279073a003ce4fb1dd0cd652e3393c18e0.tar.gz
scummvm-rg350-b122ec279073a003ce4fb1dd0cd652e3393c18e0.tar.bz2
scummvm-rg350-b122ec279073a003ce4fb1dd0cd652e3393c18e0.zip
SKY: Use the built-in OPL timer
Diffstat (limited to 'engines/sky')
-rw-r--r--engines/sky/music/adlibmusic.cpp32
-rw-r--r--engines/sky/music/adlibmusic.h4
2 files changed, 10 insertions, 26 deletions
diff --git a/engines/sky/music/adlibmusic.cpp b/engines/sky/music/adlibmusic.cpp
index e410b3fb7b..c13d6150ec 100644
--- a/engines/sky/music/adlibmusic.cpp
+++ b/engines/sky/music/adlibmusic.cpp
@@ -39,6 +39,7 @@ AdLibMusic::AdLibMusic(Audio::Mixer *pMixer, Disk *pDisk) : MusicBase(pMixer, pD
if (!_opl || !_opl->init())
error("Failed to create OPL");
+ _opl->start(new Common::Functor0Mem<void, AdLibMusic>(this, &AdLibMusic::onTimer), 50);
_mixer->playStream(Audio::Mixer::kMusicSoundType, &_soundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true);
}
@@ -48,31 +49,12 @@ AdLibMusic::~AdLibMusic() {
}
int AdLibMusic::readBuffer(int16 *data, const int numSamples) {
- if (_musicData == NULL) {
- // no music loaded
- memset(data, 0, numSamples * sizeof(int16));
- } else if ((_currentMusic == 0) || (_numberOfChannels == 0)) {
- // music loaded but not played as of yet
- memset(data, 0, numSamples * sizeof(int16));
- // poll anyways as pollMusic() can activate the music
+ return _opl->readBuffer(data, numSamples);
+}
+
+void AdLibMusic::onTimer() {
+ if (_musicData != NULL)
pollMusic();
- _nextMusicPoll = _sampleRate / 50;
- } else {
- uint32 render;
- uint remaining = numSamples;
- while (remaining) {
- render = (remaining > _nextMusicPoll) ? _nextMusicPoll : remaining;
- remaining -= render;
- _nextMusicPoll -= render;
- _opl->readBuffer(data, render);
- data += render;
- if (_nextMusicPoll == 0) {
- pollMusic();
- _nextMusicPoll = _sampleRate / 50;
- }
- }
- }
- return numSamples;
}
void AdLibMusic::setupPointers() {
@@ -90,7 +72,6 @@ void AdLibMusic::setupPointers() {
_musicDataLoc = READ_LE_UINT16(_musicData + 0x1201);
_initSequence = _musicData + 0xE91;
}
- _nextMusicPoll = 0;
}
void AdLibMusic::setupChannels(uint8 *channelData) {
@@ -112,6 +93,7 @@ void AdLibMusic::startDriver() {
void AdLibMusic::setVolume(uint16 param) {
_musicVolume = param;
+ // FIXME: This is bad. There's no real volume control here.
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, 2 * param);
}
diff --git a/engines/sky/music/adlibmusic.h b/engines/sky/music/adlibmusic.h
index 9a0796d774..fe2e5ac2a5 100644
--- a/engines/sky/music/adlibmusic.h
+++ b/engines/sky/music/adlibmusic.h
@@ -48,12 +48,14 @@ private:
OPL::OPL *_opl;
Audio::SoundHandle _soundHandle;
uint8 *_initSequence;
- uint32 _sampleRate, _nextMusicPoll;
+ uint32 _sampleRate;
virtual void setupPointers();
virtual void setupChannels(uint8 *channelData);
virtual void startDriver();
void premixerCall(int16 *buf, uint len);
+
+ void onTimer();
};
} // End of namespace Sky