aboutsummaryrefslogtreecommitdiff
path: root/engines/mads/nebular/sound_nebular.cpp
diff options
context:
space:
mode:
authorMatthew Hoops2015-04-04 20:09:30 -0400
committerMatthew Hoops2015-07-07 20:19:44 -0400
commit4c6724c5faabad1618e5d538ec27a1c334ed4c6e (patch)
treeb70647fe59c5bb5ec01c86a4f7119b4904c0e33b /engines/mads/nebular/sound_nebular.cpp
parent5024ae136a73d90b1d5a450aed0f990f226e3056 (diff)
downloadscummvm-rg350-4c6724c5faabad1618e5d538ec27a1c334ed4c6e.tar.gz
scummvm-rg350-4c6724c5faabad1618e5d538ec27a1c334ed4c6e.tar.bz2
scummvm-rg350-4c6724c5faabad1618e5d538ec27a1c334ed4c6e.zip
MADS: Use the built-in OPL timer
Diffstat (limited to 'engines/mads/nebular/sound_nebular.cpp')
-rw-r--r--engines/mads/nebular/sound_nebular.cpp45
1 files changed, 11 insertions, 34 deletions
diff --git a/engines/mads/nebular/sound_nebular.cpp b/engines/mads/nebular/sound_nebular.cpp
index 10cbc73bf2..0a1c1ea288 100644
--- a/engines/mads/nebular/sound_nebular.cpp
+++ b/engines/mads/nebular/sound_nebular.cpp
@@ -189,11 +189,6 @@ ASound::ASound(Audio::Mixer *mixer, OPL::OPL *opl, const Common::String &filenam
_randomSeed = 1234;
_amDep = _vibDep = _splitPoint = true;
- _samplesTillCallback = 0;
- _samplesTillCallbackRemainder = 0;
- _samplesPerCallback = getRate() / CALLBACKS_PER_SECOND;
- _samplesPerCallbackRemainder = getRate() % CALLBACKS_PER_SECOND;
-
for (int i = 0; i < 11; ++i) {
_channelData[i]._field0 = 0;
_channelData[i]._freqMask = 0;
@@ -211,15 +206,15 @@ ASound::ASound(Audio::Mixer *mixer, OPL::OPL *opl, const Common::String &filenam
_mixer = mixer;
_opl = opl;
- _opl->init();
- _mixer->playStream(Audio::Mixer::kPlainSoundType, &_soundHandle, this, -1,
- Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true);
-
// Initialize the Adlib
adlibInit();
// Reset the adlib
command0();
+
+ _opl->start(new Common::Functor0Mem<void, ASound>(this, &ASound::onTimer), CALLBACKS_PER_SECOND);
+ _mixer->playStream(Audio::Mixer::kPlainSoundType, &_soundHandle, this, -1,
+ Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true);
}
ASound::~ASound() {
@@ -833,32 +828,14 @@ void ASound::updateFNumber() {
write2(8, hiReg, val2);
}
-int ASound::readBuffer(int16 *buffer, const int numSamples) {
- Common::StackLock slock(_driverMutex);
-
- int32 samplesLeft = numSamples;
- memset(buffer, 0, sizeof(int16) * numSamples);
- while (samplesLeft) {
- if (!_samplesTillCallback) {
- poll();
- flush();
-
- _samplesTillCallback = _samplesPerCallback;
- _samplesTillCallbackRemainder += _samplesPerCallbackRemainder;
- if (_samplesTillCallbackRemainder >= CALLBACKS_PER_SECOND) {
- _samplesTillCallback++;
- _samplesTillCallbackRemainder -= CALLBACKS_PER_SECOND;
- }
- }
-
- int32 render = MIN<int>(samplesLeft, _samplesTillCallback);
- samplesLeft -= render;
- _samplesTillCallback -= render;
+int ASound::readBuffer(int16 *data, const int numSamples) {
+ return _opl->readBuffer(data, numSamples);
+}
- _opl->readBuffer(buffer, render);
- buffer += render;
- }
- return numSamples;
+void ASound::onTimer() {
+ Common::StackLock slock(_driverMutex);
+ poll();
+ flush();
}
int ASound::getRate() const {