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.
|
2005-04-05 18:08:02 +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
|
2008-01-05 12:45:14 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2005-04-05 18:08:02 +00:00
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2005-04-09 19:19:54 +00:00
|
|
|
* 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.
|
2005-04-05 18:08:02 +00:00
|
|
|
*
|
|
|
|
*/
|
2005-05-06 15:59:33 +00:00
|
|
|
|
2008-05-08 15:51:02 +00:00
|
|
|
#include "gob/sound/soundblaster.h"
|
2009-06-18 13:27:14 +00:00
|
|
|
#include "gob/sound/sounddesc.h"
|
2005-05-06 15:59:33 +00:00
|
|
|
|
2005-04-05 15:07:40 +00:00
|
|
|
namespace Gob {
|
2005-04-29 10:07:00 +00:00
|
|
|
|
2008-05-08 16:15:14 +00:00
|
|
|
SoundBlaster::SoundBlaster(Audio::Mixer &mixer) : SoundMixer(mixer, Audio::Mixer::kSFXSoundType) {
|
2007-02-17 09:56:09 +00:00
|
|
|
_curSoundDesc = 0;
|
2005-04-30 11:32:18 +00:00
|
|
|
|
2007-02-04 15:45:15 +00:00
|
|
|
_compositionSamples = 0;
|
|
|
|
_compositionSampleCount = 0;
|
2007-01-30 22:19:55 +00:00
|
|
|
_compositionPos = -1;
|
2012-06-16 00:58:53 +00:00
|
|
|
|
|
|
|
_compositionRepCount = 0;
|
2005-04-30 11:32:18 +00:00
|
|
|
}
|
2005-04-29 10:07:00 +00:00
|
|
|
|
2008-05-08 00:47:23 +00:00
|
|
|
SoundBlaster::~SoundBlaster() {
|
2007-02-26 18:52:28 +00:00
|
|
|
}
|
|
|
|
|
2008-05-08 01:27:36 +00:00
|
|
|
void SoundBlaster::playSample(SoundDesc &sndDesc, int16 repCount,
|
|
|
|
int16 frequency, int16 fadeLength) {
|
|
|
|
SoundMixer::play(sndDesc, repCount, frequency, fadeLength);
|
2007-02-15 22:07:44 +00:00
|
|
|
}
|
|
|
|
|
2008-05-08 00:47:23 +00:00
|
|
|
void SoundBlaster::stopSound(int16 fadeLength, SoundDesc *sndDesc) {
|
2007-01-30 22:19:55 +00:00
|
|
|
Common::StackLock slock(_mutex);
|
2005-04-30 11:32:18 +00:00
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
if (sndDesc && (sndDesc != _curSoundDesc))
|
|
|
|
return;
|
|
|
|
|
2012-06-18 15:04:46 +00:00
|
|
|
_compositionRepCount = 0;
|
|
|
|
|
2008-05-08 01:27:36 +00:00
|
|
|
if (fadeLength <= 0)
|
2007-03-20 14:51:57 +00:00
|
|
|
_curSoundDesc = 0;
|
2007-01-30 22:19:55 +00:00
|
|
|
|
2008-05-08 01:27:36 +00:00
|
|
|
SoundMixer::stop(fadeLength);
|
2007-03-29 17:55:39 +00:00
|
|
|
}
|
|
|
|
|
2008-05-08 00:47:23 +00:00
|
|
|
void SoundBlaster::stopComposition() {
|
2007-01-30 22:19:55 +00:00
|
|
|
if (_compositionPos != -1) {
|
|
|
|
stopSound(0);
|
|
|
|
_compositionPos = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-08 00:47:23 +00:00
|
|
|
void SoundBlaster::endComposition() {
|
|
|
|
_compositionPos = -1;
|
2012-06-18 15:04:46 +00:00
|
|
|
_compositionRepCount = 0;
|
2008-05-08 00:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SoundBlaster::nextCompositionPos() {
|
2007-01-30 22:19:55 +00:00
|
|
|
int8 slot;
|
2005-04-30 11:32:18 +00:00
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
while ((++_compositionPos < 50) &&
|
|
|
|
((slot = _composition[_compositionPos]) != -1)) {
|
|
|
|
if ((slot >= 0) && (slot < _compositionSampleCount)) {
|
|
|
|
SoundDesc &sample = _compositionSamples[slot];
|
|
|
|
if (!sample.empty() && (sample.getType() == SOUND_SND)) {
|
|
|
|
setSample(sample, 1, 0, 0);
|
|
|
|
return;
|
|
|
|
}
|
2005-04-30 11:32:18 +00:00
|
|
|
}
|
2007-02-12 19:30:52 +00:00
|
|
|
if (_compositionPos == 49)
|
|
|
|
_compositionPos = -1;
|
2005-04-30 11:32:18 +00:00
|
|
|
}
|
2012-06-16 00:58:53 +00:00
|
|
|
|
2007-01-30 22:19:55 +00:00
|
|
|
_compositionPos = -1;
|
|
|
|
}
|
|
|
|
|
2012-06-29 17:09:56 +00:00
|
|
|
void SoundBlaster::playComposition(const int16 *composition, int16 freqVal,
|
2007-03-20 14:51:57 +00:00
|
|
|
SoundDesc *sndDescs, int8 sndCount) {
|
2007-01-30 22:19:55 +00:00
|
|
|
|
2008-05-08 00:47:23 +00:00
|
|
|
_compositionSamples = sndDescs;
|
2009-01-01 15:06:43 +00:00
|
|
|
_compositionSampleCount = sndCount;
|
2007-02-04 15:45:15 +00:00
|
|
|
|
2008-05-08 00:47:23 +00:00
|
|
|
int i = -1;
|
2007-02-04 15:45:15 +00:00
|
|
|
do {
|
|
|
|
i++;
|
2007-01-30 22:19:55 +00:00
|
|
|
_composition[i] = composition[i];
|
2007-02-04 15:45:15 +00:00
|
|
|
} while ((i < 50) && (composition[i] != -1));
|
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
_compositionPos = -1;
|
2007-01-30 22:19:55 +00:00
|
|
|
nextCompositionPos();
|
2005-04-29 10:07:00 +00:00
|
|
|
}
|
|
|
|
|
2012-06-16 00:58:53 +00:00
|
|
|
void SoundBlaster::repeatComposition(int32 repCount) {
|
|
|
|
_compositionRepCount = repCount;
|
|
|
|
}
|
|
|
|
|
2008-05-08 00:47:23 +00:00
|
|
|
void SoundBlaster::setSample(SoundDesc &sndDesc, int16 repCount, int16 frequency,
|
2007-03-20 14:51:57 +00:00
|
|
|
int16 fadeLength) {
|
2005-04-30 11:32:18 +00:00
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
_curSoundDesc = &sndDesc;
|
2008-05-08 01:27:36 +00:00
|
|
|
SoundMixer::setSample(sndDesc, repCount, frequency, fadeLength);
|
2007-01-30 22:19:55 +00:00
|
|
|
}
|
|
|
|
|
2008-05-08 00:47:23 +00:00
|
|
|
void SoundBlaster::checkEndSample() {
|
2012-06-16 00:58:53 +00:00
|
|
|
if (_compositionPos != -1) {
|
|
|
|
nextCompositionPos();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_compositionRepCount != 0) {
|
|
|
|
if (_compositionRepCount > 0)
|
|
|
|
_compositionRepCount--;
|
|
|
|
|
2007-01-30 22:19:55 +00:00
|
|
|
nextCompositionPos();
|
2012-06-16 00:58:53 +00:00
|
|
|
if (_compositionPos != -1)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SoundMixer::checkEndSample();
|
2007-01-30 22:19:55 +00:00
|
|
|
}
|
|
|
|
|
2008-05-08 01:27:36 +00:00
|
|
|
void SoundBlaster::endFade() {
|
|
|
|
if (_fadeVolStep > 0) {
|
|
|
|
_compositionPos = -1;
|
|
|
|
_curSoundDesc = 0;
|
2007-01-30 22:19:55 +00:00
|
|
|
}
|
2008-05-08 01:27:36 +00:00
|
|
|
|
|
|
|
SoundMixer::endFade();
|
2007-01-30 22:19:55 +00:00
|
|
|
}
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2007-01-30 22:19:55 +00:00
|
|
|
} // End of namespace Gob
|