diff options
author | Sven Hesse | 2008-05-08 01:27:36 +0000 |
---|---|---|
committer | Sven Hesse | 2008-05-08 01:27:36 +0000 |
commit | 0c827c8cebf3709e980bb90be32b004acda058b8 (patch) | |
tree | d40c1c4561a4591c7b440a27e1fa9c99ce8e4beb /engines/gob/sound/soundblaster.cpp | |
parent | 220d6ce82f478966db6a4760b2288750212880b9 (diff) | |
download | scummvm-rg350-0c827c8cebf3709e980bb90be32b004acda058b8.tar.gz scummvm-rg350-0c827c8cebf3709e980bb90be32b004acda058b8.tar.bz2 scummvm-rg350-0c827c8cebf3709e980bb90be32b004acda058b8.zip |
Split off the actual mixing part of SoundBlaster
svn-id: r31938
Diffstat (limited to 'engines/gob/sound/soundblaster.cpp')
-rw-r--r-- | engines/gob/sound/soundblaster.cpp | 164 |
1 files changed, 15 insertions, 149 deletions
diff --git a/engines/gob/sound/soundblaster.cpp b/engines/gob/sound/soundblaster.cpp index f5339404b4..bacb16a6d3 100644 --- a/engines/gob/sound/soundblaster.cpp +++ b/engines/gob/sound/soundblaster.cpp @@ -27,48 +27,20 @@ namespace Gob { -SoundBlaster::SoundBlaster(Audio::Mixer &mixer) : _mixer(&mixer) { - _playingSound = 0; +SoundBlaster::SoundBlaster(Audio::Mixer &mixer) : SoundMixer(mixer) { _curSoundDesc = 0; - _rate = _mixer->getOutputRate(); - _end = true; - _data = 0; - _length = 0; - _freq = 0; - _repCount = 0; - - _offset = 0; - _offsetFrac = 0; - _offsetInc = 0; - - _cur = 0; - _last = 0; - - _fade = false; - _fadeVol = 65536; - _fadeVolStep = 0; - _fadeSamples = 0; - _curFadeSamples = 0; - _compositionSamples = 0; _compositionSampleCount = 0; _compositionPos = -1; - - _mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_handle, - this, -1, 255, 0, false, true); } SoundBlaster::~SoundBlaster() { - _mixer->stopHandle(_handle); } -bool SoundBlaster::isPlaying() const { - return !_end; -} - -char SoundBlaster::getPlayingSound() const { - return _playingSound; +void SoundBlaster::playSample(SoundDesc &sndDesc, int16 repCount, + int16 frequency, int16 fadeLength) { + SoundMixer::play(sndDesc, repCount, frequency, fadeLength); } void SoundBlaster::stopSound(int16 fadeLength, SoundDesc *sndDesc) { @@ -77,25 +49,10 @@ void SoundBlaster::stopSound(int16 fadeLength, SoundDesc *sndDesc) { if (sndDesc && (sndDesc != _curSoundDesc)) return; - if (fadeLength <= 0) { - _data = 0; - _end = true; - _playingSound = 0; + if (fadeLength <= 0) _curSoundDesc = 0; - return; - } - - _fade = true; - _fadeVol = 65536; - _fadeSamples = (int) (fadeLength * (((double) _rate) / 10.0)); - _fadeVolStep = MAX((int32) 1, (int32) (65536 / _fadeSamples)); - _curFadeSamples = 0; -} -void SoundBlaster::setRepeating(int32 repCount) { - Common::StackLock slock(_mutex); - - _repCount = repCount; + SoundMixer::stop(fadeLength); } void SoundBlaster::stopComposition() { @@ -146,115 +103,24 @@ void SoundBlaster::playComposition(int16 *composition, int16 freqVal, void SoundBlaster::setSample(SoundDesc &sndDesc, int16 repCount, int16 frequency, int16 fadeLength) { - if (frequency <= 0) - frequency = sndDesc._frequency; - _curSoundDesc = &sndDesc; - sndDesc._repCount = repCount - 1; - sndDesc._frequency = frequency; - - _data = (int8 *) sndDesc.getData(); - _length = sndDesc.size(); - _freq = frequency; - - _repCount = repCount; - _end = false; - _playingSound = 1; - - _offset = 0; - _offsetFrac = 0; - _offsetInc = (_freq << FRAC_BITS) / _rate; - - _last = _cur; - _cur = _data[0]; - - _curFadeSamples = 0; - if (fadeLength == 0) { - _fade = false; - _fadeVol = 65536; - _fadeSamples = 0; - _fadeVolStep = 0; - } else { - _fade = true; - _fadeVol = 0; - _fadeSamples = (int) (fadeLength * (((double) _rate) / 10.0)); - _fadeVolStep = - MAX((int32) 1, (int32) (65536 / _fadeSamples)); - } -} - -void SoundBlaster::playSample(SoundDesc &sndDesc, int16 repCount, int16 frequency, - int16 fadeLength) { - Common::StackLock slock(_mutex); - - if (!_end) - return; - - setSample(sndDesc, repCount, frequency, fadeLength); + SoundMixer::setSample(sndDesc, repCount, frequency, fadeLength); } void SoundBlaster::checkEndSample() { if (_compositionPos != -1) nextCompositionPos(); - else if ((_repCount == -1) || (--_repCount > 0)) { - _offset = 0; - _offsetFrac = 0; - _end = false; - _playingSound = 1; - } else { - _end = true; - _playingSound = 0; - } + else + SoundMixer::checkEndSample(); } -int SoundBlaster::readBuffer(int16 *buffer, const int numSamples) { - Common::StackLock slock(_mutex); - - for (int i = 0; i < numSamples; i++) { - if (!_data) - return i; - if (_end || (_offset >= _length)) - checkEndSample(); - if (_end) - return i; - - // Linear interpolation. See sound/rate.cpp - - int16 val = (_last + (((_cur - _last) * _offsetFrac + - FRAC_HALF) >> FRAC_BITS)) << 8; - *buffer++ = (val * _fadeVol) >> 16; - - _offsetFrac += _offsetInc; - - // Was there an integral change? - if (fracToInt(_offsetFrac) > 0) { - _last = _cur; - _cur = _data[_offset]; - _offset += fracToInt(_offsetFrac); - _offsetFrac &= FRAC_LO_MASK; - } - - if (_fade) { - - if (++_curFadeSamples >= _fadeSamples) { - if (_fadeVolStep > 0) { - _data = 0; - _end = true; - _playingSound = 0; - _compositionPos = -1; - _curSoundDesc = 0; - } else { - _fadeVol = 65536; - _fade = false; - } - } else - _fadeVol -= _fadeVolStep; - - if (_fadeVol < 0) - _fadeVol = 0; - - } +void SoundBlaster::endFade() { + if (_fadeVolStep > 0) { + _compositionPos = -1; + _curSoundDesc = 0; } - return numSamples; + + SoundMixer::endFade(); } } // End of namespace Gob |