aboutsummaryrefslogtreecommitdiff
path: root/engines/gob/sound.cpp
diff options
context:
space:
mode:
authorMax Horn2007-02-26 20:41:52 +0000
committerMax Horn2007-02-26 20:41:52 +0000
commit73188b47161462e8de10539bc64a58ee11563a84 (patch)
tree17364dbdbc950c8f34556c59b0b02434a479ed81 /engines/gob/sound.cpp
parent1c80f2ffa0d22c39fce5da342b72f890415aec8c (diff)
downloadscummvm-rg350-73188b47161462e8de10539bc64a58ee11563a84.tar.gz
scummvm-rg350-73188b47161462e8de10539bc64a58ee11563a84.tar.bz2
scummvm-rg350-73188b47161462e8de10539bc64a58ee11563a84.zip
'Optimized' SquareWaveStream::readBuffer a bit, removed some dead code, and changed Snd::terminate to a destructor (this ensures client code can't forget to do just that -- not that we'd ever forget ... ;-)
svn-id: r25884
Diffstat (limited to 'engines/gob/sound.cpp')
-rw-r--r--engines/gob/sound.cpp30
1 files changed, 13 insertions, 17 deletions
diff --git a/engines/gob/sound.cpp b/engines/gob/sound.cpp
index af5bc59661..0832702a94 100644
--- a/engines/gob/sound.cpp
+++ b/engines/gob/sound.cpp
@@ -77,11 +77,8 @@ void Snd::SquareWaveStream::update(uint32 milis) {
}
int Snd::SquareWaveStream::readBuffer(int16 *buffer, const int numSamples) {
- for (int i = 0; i < numSamples; i++) {
- if (!_remainingSamples) {
- buffer[i] = 0;
- continue;
- }
+ int i;
+ for (i = 0; _remainingSamples && i < numSamples; i++) {
buffer[i] = _sampleValue;
if (_periodSamples++ > _periodLength) {
_periodSamples = 0;
@@ -91,6 +88,10 @@ int Snd::SquareWaveStream::readBuffer(int16 *buffer, const int numSamples) {
_remainingSamples--;
_mixedSamples++;
}
+
+ // Clear the rest of the buffer
+ if (i < numSamples)
+ memset(buffer + i, 0, (numSamples - i) * sizeof(int16));
return numSamples;
}
@@ -128,16 +129,16 @@ Snd::Snd(GobEngine *vm) : _vm(vm) {
&_speakerStream, -1, 255, 0, false, true);
}
-void Snd::terminate() {
- // stop permanent streams manually
- _vm->_mixer->stopHandle(_handle);
+Snd::~Snd() {
+ // stop permanent streams manually:
+
+ // First the speaker stream
_vm->_mixer->stopHandle(_speakerHandle);
- _vm->_mixer->stopAll();
+ // Next, this stream (class Snd is an AudioStream, too)
+ _vm->_mixer->stopHandle(_handle);
}
-void Snd::setBlasterPort(int16 port) {return;}
-
void Snd::speakerOn(int16 frequency, int32 length) {
_speakerStream.playNote(frequency, length, _vm->_mixer->getOutputRate());
_speakerStartTimeKey = _vm->_util->getTimeKey();
@@ -151,8 +152,7 @@ void Snd::speakerOnUpdate(uint32 milis) {
_speakerStream.update(milis);
}
-void Snd::stopSound(int16 fadeLength)
-{
+void Snd::stopSound(int16 fadeLength) {
Common::StackLock slock(_mutex);
if (fadeLength <= 0) {
@@ -224,10 +224,6 @@ void Snd::playComposition(int16 *composition, int16 freqVal, SoundDesc **sndDesc
nextCompositionPos();
}
-void Snd::writeAdlib(int16 port, int16 data) {
- return;
-}
-
Snd::SoundDesc *Snd::loadSoundData(const char *path) {
Snd::SoundDesc *sndDesc;