aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO3
-rw-r--r--graphics/animation.cpp2
-rw-r--r--kyra/kyra.cpp4
-rw-r--r--queen/queen.cpp4
-rw-r--r--queen/sound.cpp6
-rw-r--r--saga/music.cpp4
-rw-r--r--saga/saga.cpp4
-rw-r--r--saga/sound.cpp2
-rw-r--r--scumm/imuse_digi/dimuse.cpp4
-rw-r--r--scumm/imuse_digi/dimuse_track.cpp4
-rw-r--r--scumm/scumm.cpp6
-rw-r--r--scumm/smush/smush_mixer.cpp2
-rw-r--r--scumm/smush/smush_player.cpp4
-rw-r--r--scumm/sound.cpp4
-rw-r--r--simon/simon.cpp4
-rw-r--r--simon/sound.cpp6
-rw-r--r--sky/sky.cpp4
-rw-r--r--sound/flac.cpp2
-rw-r--r--sound/mixer.cpp59
-rw-r--r--sound/mixer.h48
-rw-r--r--sound/mp3.cpp2
-rw-r--r--sound/softsynth/mt32.cpp2
-rw-r--r--sound/vorbis.cpp2
-rw-r--r--sword1/credits.cpp2
-rw-r--r--sword1/sound.cpp4
-rw-r--r--sword1/sword1.cpp4
-rw-r--r--sword2/driver/d_sound.cpp2
-rw-r--r--sword2/sword2.cpp4
28 files changed, 94 insertions, 104 deletions
diff --git a/TODO b/TODO
index b4723fc478..6acecbb1e1 100644
--- a/TODO
+++ b/TODO
@@ -160,9 +160,6 @@ Audio
=====
* Get the high quality resample code to work
[Fingolfin has started work on this]
-* Add "sound types" to the mixer; client code will be able to pass such a type
- whenever registering an audio stream. Then, volume control will be changed
- to be based on the sound type.
Config Manager
==============
diff --git a/graphics/animation.cpp b/graphics/animation.cpp
index 5cb3f70f22..d3453c00ba 100644
--- a/graphics/animation.cpp
+++ b/graphics/animation.cpp
@@ -133,7 +133,7 @@ bool BaseAnimationState::init(const char *name, void *audioArg) {
bgSoundStream = createAudioStream(name, audioArg);
if (bgSoundStream != NULL) {
- _snd->playInputStream(&bgSound, bgSoundStream, false, -1, 255, 0, false);
+ _snd->playInputStream(SoundMixer::kSFXAudioDataType, &bgSound, bgSoundStream, -1, 255, 0, false);
} else {
warning("Cutscene: Could not open Audio Track for %s", name);
}
diff --git a/kyra/kyra.cpp b/kyra/kyra.cpp
index 3ed497581d..b81bafb289 100644
--- a/kyra/kyra.cpp
+++ b/kyra/kyra.cpp
@@ -105,8 +105,8 @@ KyraEngine::KyraEngine(GameDetector *detector, OSystem *syst)
warning("Sound initialization failed.");
}
- _mixer->setVolume(ConfMan.getInt("sfx_volume"));
- _mixer->setMusicVolume(ConfMan.getInt("music_volume"));
+ _mixer->setVolumeForSoundType(SoundMixer::kSFXAudioDataType, ConfMan.getInt("sfx_volume"));
+ _mixer->setVolumeForSoundType(SoundMixer::kMusicAudioDataType, ConfMan.getInt("music_volume"));
// gets the game
if (detector->_game.features & GF_KYRA1) {
diff --git a/queen/queen.cpp b/queen/queen.cpp
index 22fad036f7..ddb7523206 100644
--- a/queen/queen.cpp
+++ b/queen/queen.cpp
@@ -358,9 +358,9 @@ int QueenEngine::init(GameDetector &detector) {
if (!_mixer->isReady())
warning("Sound initialisation failed.");
- _mixer->setVolume(ConfMan.getInt("sfx_volume"));
+ _mixer->setVolumeForSoundType(SoundMixer::kSFXAudioDataType, ConfMan.getInt("sfx_volume"));
// Set mixer music volume to maximum, since music volume is regulated by MusicPlayer's MIDI messages
- _mixer->setMusicVolume(256);
+ _mixer->setVolumeForSoundType(SoundMixer::kMusicAudioDataType, 256);
int midiDriver = MidiDriver::detectMusicDriver(MDT_NATIVE | MDT_ADLIB | MDT_PREFER_NATIVE);
MidiDriver *driver = MidiDriver::createMidi(midiDriver);
diff --git a/queen/sound.cpp b/queen/sound.cpp
index d551564bbd..d98b64595b 100644
--- a/queen/sound.cpp
+++ b/queen/sound.cpp
@@ -201,7 +201,7 @@ void SBSound::sfxPlay(const char *name, bool isSpeech) {
void MP3Sound::sfxPlay(const char *name, bool isSpeech) {
uint32 size;
File *f = _vm->resource()->giveCompressedSound(name, &size);
- _mixer->playInputStream(isSpeech ? &_speechHandle : &_sfxHandle, makeMP3Stream(f, size), false);
+ _mixer->playInputStream(SoundMixer::kSFXAudioDataType, isSpeech ? &_speechHandle : &_sfxHandle, makeMP3Stream(f, size));
}
#endif
@@ -209,7 +209,7 @@ void MP3Sound::sfxPlay(const char *name, bool isSpeech) {
void OGGSound::sfxPlay(const char *name, bool isSpeech) {
uint32 size;
File *f = _vm->resource()->giveCompressedSound(name, &size);
- _mixer->playInputStream(isSpeech ? &_speechHandle : &_sfxHandle, makeVorbisStream(f, size), false);
+ _mixer->playInputStream(SoundMixer::kSFXAudioDataType, isSpeech ? &_speechHandle : &_sfxHandle, makeVorbisStream(f, size));
}
#endif
@@ -217,7 +217,7 @@ void OGGSound::sfxPlay(const char *name, bool isSpeech) {
void FLACSound::sfxPlay(const char *name, bool isSpeech) {
uint32 size;
File *f = _vm->resource()->giveCompressedSound(name, &size);
- _mixer->playInputStream(isSpeech ? &_speechHandle : &_sfxHandle, makeFlacStream(f, size), false);
+ _mixer->playInputStream(SoundMixer::kSFXAudioDataType, isSpeech ? &_speechHandle : &_sfxHandle, makeFlacStream(f, size));
}
#endif
diff --git a/saga/music.cpp b/saga/music.cpp
index 338bf09977..0b8596be0f 100644
--- a/saga/music.cpp
+++ b/saga/music.cpp
@@ -295,7 +295,7 @@ void MusicPlayer::stopMusic() {
Music::Music(SoundMixer *mixer, MidiDriver *driver, int enabled) : _mixer(mixer), _enabled(enabled), _adlib(false) {
_player = new MusicPlayer(driver);
_musicInitialized = 1;
- _mixer->setMusicVolume(ConfMan.getInt("music_volume"));
+ _mixer->setVolumeForSoundType(SoundMixer::kMusicAudioDataType, ConfMan.getInt("music_volume"));
if (_vm->_gameType == GType_ITE) {
File file;
@@ -438,7 +438,7 @@ int Music::play(uint32 music_rn, uint16 flags) {
if (audioStream) {
debug(0, "Playing digitized music");
- _mixer->playInputStream(&_musicHandle, audioStream, true);
+ _mixer->playInputStream(SoundMixer::kMusicAudioDataType, &_musicHandle, audioStream);
return SUCCESS;
}
diff --git a/saga/saga.cpp b/saga/saga.cpp
index c22e38eb19..3f1c760dd1 100644
--- a/saga/saga.cpp
+++ b/saga/saga.cpp
@@ -107,8 +107,8 @@ SagaEngine::SagaEngine(GameDetector *detector, OSystem *syst)
warning("Sound initialization failed.");
}
- _mixer->setVolume(ConfMan.getInt("sfx_volume"));
- _mixer->setMusicVolume(ConfMan.getInt("music_volume"));
+ _mixer->setVolumeForSoundType(SoundMixer::kSFXAudioDataType, ConfMan.getInt("sfx_volume"));
+ _mixer->setVolumeForSoundType(SoundMixer::kMusicAudioDataType, ConfMan.getInt("music_volume"));
_vm = this;
}
diff --git a/saga/sound.cpp b/saga/sound.cpp
index 8fdf9d1e5e..c82fd5c65e 100644
--- a/saga/sound.cpp
+++ b/saga/sound.cpp
@@ -221,7 +221,7 @@ int Sound::playVoxVoice(SOUNDBUFFER *buf) {
AudioStream *audioStream;
audioStream = makeVOXStream(buf->s_buf, buf->s_buf_len);
- _mixer->playInputStream(&_voiceHandle, audioStream, false);
+ _mixer->playInputStream(SoundMixer::kSFXAudioDataType, &_voiceHandle, audioStream);
return SUCCESS;
}
diff --git a/scumm/imuse_digi/dimuse.cpp b/scumm/imuse_digi/dimuse.cpp
index c9527672ee..6d2df1d53e 100644
--- a/scumm/imuse_digi/dimuse.cpp
+++ b/scumm/imuse_digi/dimuse.cpp
@@ -149,7 +149,7 @@ void IMuseDigital::saveOrLoad(Serializer *ser) {
int freq = _sound->getFreq(track->soundHandle);
track->stream2 = NULL;
track->stream = makeAppendableAudioStream(freq, track->mixerFlags, streamBufferSize);
- _vm->_mixer->playInputStream(&track->handle, track->stream, false, -1, track->mixerVol, track->mixerPan, false);
+ _vm->_mixer->playInputStream(SoundMixer::kSFXAudioDataType, &track->handle, track->stream, -1, track->mixerVol, track->mixerPan, false);
}
}
}
@@ -289,7 +289,7 @@ void IMuseDigital::callback() {
if (_vm->_mixer->isReady()) {
if (!track->started) {
track->started = true;
- _vm->_mixer->playInputStream(&track->handle, track->stream2, false, -1, vol, pan, false);
+ _vm->_mixer->playInputStream(SoundMixer::kSFXAudioDataType, &track->handle, track->stream2, -1, vol, pan, false);
} else {
_vm->_mixer->setChannelVolume(track->handle, vol);
_vm->_mixer->setChannelBalance(track->handle, pan);
diff --git a/scumm/imuse_digi/dimuse_track.cpp b/scumm/imuse_digi/dimuse_track.cpp
index c59848d4b0..28a7aa7fd9 100644
--- a/scumm/imuse_digi/dimuse_track.cpp
+++ b/scumm/imuse_digi/dimuse_track.cpp
@@ -173,7 +173,7 @@ void IMuseDigital::startSound(int soundId, const char *soundName, int soundType,
int32 streamBufferSize = track->iteration;
track->stream2 = NULL;
track->stream = makeAppendableAudioStream(freq, track->mixerFlags, streamBufferSize);
- _vm->_mixer->playInputStream(&track->handle, track->stream, false, -1, track->mixerVol, track->mixerPan, false);
+ _vm->_mixer->playInputStream(SoundMixer::kSFXAudioDataType, &track->handle, track->stream, -1, track->mixerVol, track->mixerPan, false);
track->started = true;
}
@@ -305,7 +305,7 @@ IMuseDigital::Track *IMuseDigital::cloneToFadeOutTrack(Track *track, int fadeDel
// setup 1 second stream wrapped buffer
int32 streamBufferSize = fadeTrack->iteration;
fadeTrack->stream = makeAppendableAudioStream(_sound->getFreq(fadeTrack->soundHandle), fadeTrack->mixerFlags, streamBufferSize);
- _vm->_mixer->playInputStream(&fadeTrack->handle, fadeTrack->stream, false, -1, fadeTrack->vol / 1000, fadeTrack->pan, false);
+ _vm->_mixer->playInputStream(SoundMixer::kSFXAudioDataType, &fadeTrack->handle, fadeTrack->stream, -1, fadeTrack->vol / 1000, fadeTrack->pan, false);
fadeTrack->started = true;
fadeTrack->used = true;
diff --git a/scumm/scumm.cpp b/scumm/scumm.cpp
index 338b942429..efb8e3fe87 100644
--- a/scumm/scumm.cpp
+++ b/scumm/scumm.cpp
@@ -1388,11 +1388,11 @@ void ScummEngine::setupVolumes() {
_musicEngine->setMusicVolume(soundVolumeMusic);
}
- _mixer->setVolume(soundVolumeSfx);
- _mixer->setMusicVolume(soundVolumeMusic);
+ _mixer->setVolumeForSoundType(SoundMixer::kSFXAudioDataType, soundVolumeSfx);
+ _mixer->setVolumeForSoundType(SoundMixer::kMusicAudioDataType, soundVolumeMusic);
if (_imuseDigital) {
- _mixer->setVolume(255);
+ _mixer->setVolumeForSoundType(SoundMixer::kSFXAudioDataType, 255);
_imuseDigital->setGroupMusicVolume(soundVolumeMusic / 2);
_imuseDigital->setGroupSfxVolume(soundVolumeSfx / 2);
_imuseDigital->setGroupVoiceVolume(soundVolumeSpeech / 2);
diff --git a/scumm/smush/smush_mixer.cpp b/scumm/smush/smush_mixer.cpp
index f7309cb87e..8378200ecd 100644
--- a/scumm/smush/smush_mixer.cpp
+++ b/scumm/smush/smush_mixer.cpp
@@ -122,7 +122,7 @@ bool SmushMixer::handleFrame() {
if (_mixer->isReady()) {
if (!_channels[i].handle.isActive()) {
_channels[i].stream = makeAppendableAudioStream(rate, flags, 500000);
- _mixer->playInputStream(&_channels[i].handle, _channels[i].stream, false);
+ _mixer->playInputStream(SoundMixer::kSFXAudioDataType, &_channels[i].handle, _channels[i].stream);
}
_mixer->setChannelVolume(_channels[i].handle, vol);
_mixer->setChannelBalance(_channels[i].handle, pan);
diff --git a/scumm/smush/smush_player.cpp b/scumm/smush/smush_player.cpp
index 3e5e097c0a..669916cf1b 100644
--- a/scumm/smush/smush_player.cpp
+++ b/scumm/smush/smush_player.cpp
@@ -503,7 +503,7 @@ void SmushPlayer::handleIACT(Chunk &b) {
if (!_IACTchannel.isActive()) {
_IACTstream = makeAppendableAudioStream(22050, SoundMixer::FLAG_STEREO | SoundMixer::FLAG_16BITS, 400000);
- _vm->_mixer->playInputStream(&_IACTchannel, _IACTstream, false);
+ _vm->_mixer->playInputStream(SoundMixer::kSFXAudioDataType, &_IACTchannel, _IACTstream);
}
_IACTstream->append(output_data, 0x1000);
@@ -1177,7 +1177,7 @@ void SmushPlayer::tryOggFile(const char *filename) {
if (_compressedFile.isOpen()) {
int size = _compressedFile.size();
_compressedFileMode = true;
- _vm->_mixer->playInputStream(&_compressedFileSoundHandle, makeVorbisStream(&_compressedFile, size), false);
+ _vm->_mixer->playInputStream(SoundMixer::kSFXAudioDataType, &_compressedFileSoundHandle, makeVorbisStream(&_compressedFile, size));
}
#endif
}
diff --git a/scumm/sound.cpp b/scumm/sound.cpp
index a54f45d957..e6f1e9e2c2 100644
--- a/scumm/sound.cpp
+++ b/scumm/sound.cpp
@@ -1029,7 +1029,7 @@ void Sound::startSfxSound(File *file, int file_size, PlayingSoundHandle *handle,
//_vm->_imuseDigital->stopSound(kTalkSoundID);
_vm->_imuseDigital->startVoice(kTalkSoundID, input);
} else {
- _vm->_mixer->playInputStream(handle, input, false, id);
+ _vm->_mixer->playInputStream(SoundMixer::kSFXAudioDataType, handle, input, id);
}
}
@@ -1122,7 +1122,7 @@ ScummFile *Sound::openSfxFile() {
}
bool Sound::isSfxFinished() const {
- return !_vm->_mixer->hasActiveSFXChannel();
+ return !_vm->_mixer->hasActiveChannelOfType(SoundMixer::kSFXAudioDataType);
}
// We use a real timer in an attempt to get better sync with CD tracks. This is
diff --git a/simon/simon.cpp b/simon/simon.cpp
index 61feee10ba..f4d8808004 100644
--- a/simon/simon.cpp
+++ b/simon/simon.cpp
@@ -665,7 +665,7 @@ int SimonEngine::init(GameDetector &detector) {
warning("Sound initialization failed. "
"Features of the game that depend on sound synchronization will most likely break");
set_volume(ConfMan.getInt("sfx_volume"));
- _mixer->setMusicVolume(ConfMan.getInt("music_volume"));
+ _mixer->setVolumeForSoundType(SoundMixer::kMusicAudioDataType, ConfMan.getInt("music_volume"));
_system->beginGFXTransaction();
initCommonGFX(detector);
@@ -4225,7 +4225,7 @@ void SimonEngine::dx_unlock_attached() {
}
void SimonEngine::set_volume(byte volume) {
- _mixer->setVolume(volume);
+ _mixer->setVolumeForSoundType(SoundMixer::kSFXAudioDataType, volume);
}
byte SimonEngine::getByte() {
diff --git a/simon/sound.cpp b/simon/sound.cpp
index d272dc14c6..23582ed53e 100644
--- a/simon/sound.cpp
+++ b/simon/sound.cpp
@@ -219,7 +219,7 @@ void MP3Sound::playSound(uint sound, PlayingSoundHandle *handle, byte flags)
uint32 size = _offsets[sound + i] - _offsets[sound];
- _mixer->playInputStream(handle, makeMP3Stream(_file, size), false);
+ _mixer->playInputStream(SoundMixer::kSFXAudioDataType, handle, makeMP3Stream(_file, size));
}
#endif
@@ -243,7 +243,7 @@ void VorbisSound::playSound(uint sound, PlayingSoundHandle *handle, byte flags)
uint32 size = _offsets[sound + i] - _offsets[sound];
- _mixer->playInputStream(handle, makeVorbisStream(_file, size), false);
+ _mixer->playInputStream(SoundMixer::kSFXAudioDataType, handle, makeVorbisStream(_file, size));
}
#endif
@@ -267,7 +267,7 @@ void FlacSound::playSound(uint sound, PlayingSoundHandle *handle, byte flags)
uint32 size = _offsets[sound + i] - _offsets[sound];
- _mixer->playInputStream(handle, makeFlacStream(_file, size), false);
+ _mixer->playInputStream(SoundMixer::kSFXAudioDataType, handle, makeFlacStream(_file, size));
}
#endif
diff --git a/sky/sky.cpp b/sky/sky.cpp
index 9a2fdc6ce1..80d2e05f03 100644
--- a/sky/sky.cpp
+++ b/sky/sky.cpp
@@ -239,8 +239,8 @@ int SkyEngine::init(GameDetector &detector) {
if (!_mixer->isReady())
warning("Sound initialisation failed");
- _mixer->setVolume(ConfMan.getInt("sfx_volume"));
- _mixer->setMusicVolume(ConfMan.getInt("music_volume"));
+ _mixer->setVolumeForSoundType(SoundMixer::kSFXAudioDataType, ConfMan.getInt("sfx_volume"));
+ _mixer->setVolumeForSoundType(SoundMixer::kMusicAudioDataType, ConfMan.getInt("music_volume"));
_floppyIntro = ConfMan.getBool("alt_intro");
_skyDisk = new Disk(_gameDataPath);
diff --git a/sound/flac.cpp b/sound/flac.cpp
index 15e04f34f6..b0306967e0 100644
--- a/sound/flac.cpp
+++ b/sound/flac.cpp
@@ -783,7 +783,7 @@ void FlacTrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int star
flac->setLastSample(0);
if (flac->seekAbsolute(static_cast<FLAC__uint64>(startFrame) * (info.sample_rate / 75))) {
- mixer->playInputStream(handle, flac, true);
+ mixer->playInputStream(SoundMixer::kMusicAudioDataType, handle, flac);
return;
}
// startSample is beyond the existing Samples
diff --git a/sound/mixer.cpp b/sound/mixer.cpp
index 6e8f514c1f..76d2697586 100644
--- a/sound/mixer.cpp
+++ b/sound/mixer.cpp
@@ -41,11 +41,12 @@
* Channels used by the sound mixer.
*/
class Channel {
+public:
+ const SoundMixer::SoundType _type;
private:
SoundMixer *_mixer;
PlayingSoundHandle *_handle;
bool _autofreeStream;
- const bool _isMusic;
bool _permanent;
byte _volume;
int8 _balance;
@@ -61,8 +62,8 @@ protected:
public:
- Channel(SoundMixer *mixer, PlayingSoundHandle *handle, bool isMusic, int id = -1);
- Channel(SoundMixer *mixer, PlayingSoundHandle *handle, AudioStream *input, bool autofreeStream, bool isMusic, bool reverseStereo = false, int id = -1, bool permanent = false);
+ Channel(SoundMixer *mixer, PlayingSoundHandle *handle, SoundMixer::SoundType type, int id = -1);
+ Channel(SoundMixer *mixer, PlayingSoundHandle *handle, SoundMixer::SoundType type, AudioStream *input, bool autofreeStream, bool reverseStereo = false, int id = -1, bool permanent = false);
virtual ~Channel();
void mix(int16 *data, uint len);
@@ -73,9 +74,6 @@ public:
bool isFinished() const {
return _input->endOfStream();
}
- bool isMusicChannel() const {
- return _isMusic;
- }
void pause(bool paused) {
_paused = paused;
}
@@ -107,8 +105,8 @@ SoundMixer::SoundMixer() {
_premixChannel = 0;
int i = 0;
- _globalVolume = 0;
- _musicVolume = 0;
+ for (i = 0; i < ARRAYSIZE(_volumeForSoundType); i++)
+ _volumeForSoundType[i] = 256;
_paused = false;
@@ -148,7 +146,7 @@ void SoundMixer::setupPremix(AudioStream *stream) {
return;
// Create the channel
- _premixChannel = new Channel(this, 0, stream, false, true);
+ _premixChannel = new Channel(this, 0, kPlainAudioDataType, stream, false);
}
void SoundMixer::insertChannel(PlayingSoundHandle *handle, Channel *chan) {
@@ -172,7 +170,7 @@ void SoundMixer::insertChannel(PlayingSoundHandle *handle, Channel *chan) {
}
void SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags,
- int id, byte volume, int8 balance, uint32 loopStart, uint32 loopEnd) {
+ int id, byte volume, int8 balance, uint32 loopStart, uint32 loopEnd, SoundType type) {
Common::StackLock lock(_mutex);
// Prevent duplicate sounds
@@ -199,13 +197,13 @@ void SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, u
}
// Create the channel
- Channel *chan = new Channel(this, handle, input, true, false, (flags & SoundMixer::FLAG_REVERSE_STEREO) != 0, id);
+ Channel *chan = new Channel(this, handle, type, input, true, (flags & SoundMixer::FLAG_REVERSE_STEREO) != 0, id);
chan->setVolume(volume);
chan->setBalance(balance);
insertChannel(handle, chan);
}
-void SoundMixer::playInputStream(PlayingSoundHandle *handle, AudioStream *input, bool isMusic,
+void SoundMixer::playInputStream(SoundType type, PlayingSoundHandle *handle, AudioStream *input,
int id, byte volume, int8 balance, bool autofreeStream, bool permanent) {
Common::StackLock lock(_mutex);
@@ -225,7 +223,7 @@ void SoundMixer::playInputStream(PlayingSoundHandle *handle, AudioStream *input,
}
// Create the channel
- Channel *chan = new Channel(this, handle, input, autofreeStream, isMusic, false, id, permanent);
+ Channel *chan = new Channel(this, handle, type, input, autofreeStream, false, id, permanent);
chan->setVolume(volume);
chan->setBalance(balance);
insertChannel(handle, chan);
@@ -396,16 +394,17 @@ bool SoundMixer::isSoundIDActive(int id) {
return false;
}
-bool SoundMixer::hasActiveSFXChannel() {
- // FIXME/TODO: We need to distinguish between SFX and music channels
+bool SoundMixer::hasActiveChannelOfType(SoundType type) {
Common::StackLock lock(_mutex);
for (int i = 0; i != NUM_CHANNELS; i++)
- if (_channels[i] && !_channels[i]->isMusicChannel())
+ if (_channels[i] && !_channels[i]->_type == type)
return true;
return false;
}
-void SoundMixer::setVolume(int volume) {
+void SoundMixer::setVolumeForSoundType(SoundType type, int volume) {
+ assert(0 <= type && type < ARRAYSIZE(_volumeForSoundType));
+
// Check range
if (volume > 256)
volume = 256;
@@ -415,17 +414,13 @@ void SoundMixer::setVolume(int volume) {
// TODO: Maybe we should do logarithmic (not linear) volume
// scaling? See also Player_V2::setMasterVolume
- _globalVolume = volume;
+ _volumeForSoundType[type] = volume;
}
-void SoundMixer::setMusicVolume(int volume) {
- // Check range
- if (volume > 256)
- volume = 256;
- else if (volume < 0)
- volume = 0;
-
- _musicVolume = volume;
+int SoundMixer::getVolumeForSoundType(SoundType type) const {
+ assert(0 <= type && type < ARRAYSIZE(_volumeForSoundType));
+
+ return _volumeForSoundType[type];
}
@@ -434,16 +429,16 @@ void SoundMixer::setMusicVolume(int volume) {
#pragma mark -
-Channel::Channel(SoundMixer *mixer, PlayingSoundHandle *handle, bool isMusic, int id)
- : _mixer(mixer), _handle(handle), _autofreeStream(true), _isMusic(isMusic),
+Channel::Channel(SoundMixer *mixer, PlayingSoundHandle *handle, SoundMixer::SoundType type, int id)
+ : _type(type), _mixer(mixer), _handle(handle), _autofreeStream(true),
_volume(255), _balance(0), _paused(false), _id(id), _samplesConsumed(0),
_samplesDecoded(0), _mixerTimeStamp(0), _converter(0), _input(0) {
assert(mixer);
}
-Channel::Channel(SoundMixer *mixer, PlayingSoundHandle *handle, AudioStream *input,
- bool autofreeStream, bool isMusic, bool reverseStereo, int id, bool permanent)
- : _mixer(mixer), _handle(handle), _autofreeStream(autofreeStream), _isMusic(isMusic),
+Channel::Channel(SoundMixer *mixer, PlayingSoundHandle *handle, SoundMixer::SoundType type, AudioStream *input,
+ bool autofreeStream, bool reverseStereo, int id, bool permanent)
+ : _type(type), _mixer(mixer), _handle(handle), _autofreeStream(autofreeStream),
_volume(255), _balance(0), _paused(false), _id(id), _samplesConsumed(0),
_samplesDecoded(0), _mixerTimeStamp(0), _converter(0), _input(input), _permanent(permanent) {
assert(mixer);
@@ -481,7 +476,7 @@ void Channel::mix(int16 *data, uint len) {
// volume is in the range 0 - 256.
// Hence, the vol_l/vol_r values will be in that range, too
- int vol = (isMusicChannel() ? _mixer->getMusicVolume() : _mixer->getVolume()) * _volume;
+ int vol = _mixer->getVolumeForSoundType(_type) * _volume;
st_volume_t vol_l, vol_r;
if (_balance == 0) {
diff --git a/sound/mixer.h b/sound/mixer.h
index b70c3b8692..268e66296f 100644
--- a/sound/mixer.h
+++ b/sound/mixer.h
@@ -68,6 +68,14 @@ public:
/** loop the audio */
FLAG_LOOP = 1 << 6
};
+
+ enum SoundType {
+ kPlainAudioDataType = 0,
+
+ kMusicAudioDataType = 1,
+ kSFXAudioDataType = 2
+ // kSpeechAudioDataType = 3 TODO: Add this type later...
+ };
private:
enum {
@@ -81,8 +89,7 @@ private:
uint _outputRate;
- int _globalVolume;
- int _musicVolume;
+ int _volumeForSoundType[4];
bool _paused;
@@ -123,14 +130,16 @@ public:
* (using the makeLinearInputStream factory function), which is then
* passed on to playInputStream.
*/
- void playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags,
+ void playRaw(PlayingSoundHandle *handle,
+ void *sound, uint32 size, uint rate, byte flags,
int id = -1, byte volume = 255, int8 balance = 0,
- uint32 loopStart = 0, uint32 loopEnd = 0);
+ uint32 loopStart = 0, uint32 loopEnd = 0,
+ SoundType type = kSFXAudioDataType);
/**
* Start playing the given audio input stream.
*/
- void playInputStream(PlayingSoundHandle *handle, AudioStream *input, bool isMusic,
+ void playInputStream(SoundType type, PlayingSoundHandle *handle, AudioStream *input,
int id = -1, byte volume = 255, int8 balance = 0,
bool autofreeStream = true, bool permanent = false);
@@ -223,39 +232,28 @@ public:
uint32 getSoundElapsedTime(PlayingSoundHandle handle);
/**
- * Check whether any SFX channel is active.
+ * Check whether any channel of the given sound type is active.
+ * For example, this can be used to check whether any SFX sound
+ * is currently playing, by checking for type kSFXAudioDataType.
*
- * @return true if any SFX (= non-music) channels are active.
+ * @param type the sound type to look for
+ * @return true if any channels of the specified type are active.
*/
- bool hasActiveSFXChannel();
+ bool hasActiveChannelOfType(SoundType type);
/**
- * Set the global volume.
+ * Set the volume for the given sound type.
*
* @param volume the new global volume, 0-256
*/
- void setVolume(int volume);
+ void setVolumeForSoundType(SoundType type, int volume);
/**
* Query the global volume.
*
* @return the global music volume, 0-256
*/
- int getVolume() const { return _globalVolume; }
-
- /**
- * Set the music volume.
- *
- * @param volume the new music volume, 0-256
- */
- void setMusicVolume(int volume);
-
- /**
- * Query the music volume.
- *
- * @return the current music volume, 0-256
- */
- int getMusicVolume() const { return _musicVolume; }
+ int getVolumeForSoundType(SoundType type) const;
/**
* Query the system's audio output sample rate. This returns
diff --git a/sound/mp3.cpp b/sound/mp3.cpp
index a81f2171e3..51f444aa1c 100644
--- a/sound/mp3.cpp
+++ b/sound/mp3.cpp
@@ -380,7 +380,7 @@ void MP3TrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int start
// Play it
AudioStream *input = new MP3InputStream(_file, durationTime);
- mixer->playInputStream(handle, input, true);
+ mixer->playInputStream(SoundMixer::kMusicAudioDataType, handle, input);
}
MP3TrackInfo::~MP3TrackInfo() {
diff --git a/sound/softsynth/mt32.cpp b/sound/softsynth/mt32.cpp
index 4789e46fc7..3244e0bb42 100644
--- a/sound/softsynth/mt32.cpp
+++ b/sound/softsynth/mt32.cpp
@@ -267,7 +267,7 @@ int MidiDriver_MT32::open() {
_initialising = false;
g_system->clearScreen();
g_system->updateScreen();
- _mixer->playInputStream(&_handle, this, false, -1, 255, 0, false, true);
+ _mixer->playInputStream(SoundMixer::kSFXAudioDataType, &_handle, this, -1, 255, 0, false, true);
return 0;
}
diff --git a/sound/vorbis.cpp b/sound/vorbis.cpp
index 2b3b416fb3..0ddf423439 100644
--- a/sound/vorbis.cpp
+++ b/sound/vorbis.cpp
@@ -178,7 +178,7 @@ void VorbisTrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int st
#endif
AudioStream *input = makeVorbisStream(&_ov_file, duration * ov_info(&_ov_file, -1)->rate / 75);
- mixer->playInputStream(handle, input, true);
+ mixer->playInputStream(SoundMixer::kMusicAudioDataType, handle, input);
}
DigitalTrackInfo *getVorbisTrack(int track) {
diff --git a/sword1/credits.cpp b/sword1/credits.cpp
index 75fc8b2060..ab454cb9a5 100644
--- a/sword1/credits.cpp
+++ b/sword1/credits.cpp
@@ -109,7 +109,7 @@ void CreditsPlayer::play(void) {
// everything's initialized, time to render and show the credits.
PlayingSoundHandle bgSound;
- _mixer->playInputStream(&bgSound, bgSoundStream, true, 0);
+ _mixer->playInputStream(SoundMixer::kMusicAudioDataType, &bgSound, bgSoundStream, 0);
int relDelay = 0;
uint16 scrollY = 0;
diff --git a/sword1/sound.cpp b/sword1/sound.cpp
index e409af5e02..5f976e49f2 100644
--- a/sword1/sound.cpp
+++ b/sword1/sound.cpp
@@ -194,7 +194,7 @@ bool Sound::startSpeech(uint16 roomNo, uint16 localNo) {
#ifdef USE_MAD
else if (_cowMode == CowMp3) {
_cowFile.seek(index);
- _mixer->playInputStream(&_speechHandle, makeMP3Stream(&_cowFile, sampleSize), false, SOUND_SPEECH_ID, speechVol, speechPan);
+ _mixer->playInputStream(SoundMixer::kSFXAudioDataType, &_speechHandle, makeMP3Stream(&_cowFile, sampleSize), SOUND_SPEECH_ID, speechVol, speechPan);
// with compressed audio, we can't calculate the wave volume.
// so default to talking.
for (int cnt = 0; cnt < 480; cnt++)
@@ -205,7 +205,7 @@ bool Sound::startSpeech(uint16 roomNo, uint16 localNo) {
#ifdef USE_VORBIS
else if (_cowMode == CowVorbis) {
_cowFile.seek(index);
- _mixer->playInputStream(&_speechHandle, makeVorbisStream(&_cowFile, sampleSize), false, SOUND_SPEECH_ID, speechVol, speechPan);
+ _mixer->playInputStream(SoundMixer::kSFXAudioDataType, &_speechHandle, makeVorbisStream(&_cowFile, sampleSize), SOUND_SPEECH_ID, speechVol, speechPan);
for (int cnt = 0; cnt < 480; cnt++)
_waveVolume[cnt] = true;
_waveVolPos = 0;
diff --git a/sword1/sword1.cpp b/sword1/sword1.cpp
index 218c6a7ee0..4bafa81544 100644
--- a/sword1/sword1.cpp
+++ b/sword1/sword1.cpp
@@ -165,8 +165,8 @@ int SwordEngine::init(GameDetector &detector) {
_resMan = new ResMan("swordres.rif");
debug(5, "Starting object manager");
_objectMan = new ObjectMan(_resMan);
- _mixer->setVolume(255);
- _mixer->setMusicVolume(256);
+ _mixer->setVolumeForSoundType(SoundMixer::kSFXAudioDataType, 256);
+ _mixer->setVolumeForSoundType(SoundMixer::kMusicAudioDataType, 256);
_mouse = new Mouse(_system, _resMan, _objectMan);
_screen = new Screen(_system, _resMan, _objectMan);
_music = new Music(_system, _mixer);
diff --git a/sword2/driver/d_sound.cpp b/sword2/driver/d_sound.cpp
index 546071ba51..7538b2158d 100644
--- a/sword2/driver/d_sound.cpp
+++ b/sword2/driver/d_sound.cpp
@@ -937,7 +937,7 @@ int32 Sound::playCompSpeech(uint32 speechid, uint8 vol, int8 pan) {
int8 p = _panTable[pan + 16];
// Start the speech playing
- _vm->_mixer->playInputStream(&_soundHandleSpeech, input, false, -1, volume, p);
+ _vm->_mixer->playInputStream(SoundMixer::kSFXAudioDataType, &_soundHandleSpeech, input, -1, volume, p);
return RD_OK;
}
diff --git a/sword2/sword2.cpp b/sword2/sword2.cpp
index 82d7d0c0b7..303afb357f 100644
--- a/sword2/sword2.cpp
+++ b/sword2/sword2.cpp
@@ -255,8 +255,8 @@ int Sword2Engine::init(GameDetector &detector) {
// We have our own volume settings panel, so don't let ScummVM's mixer
// soften the sound in any way.
- _mixer->setVolume(256);
- _mixer->setMusicVolume(256);
+ _mixer->setVolumeForSoundType(SoundMixer::kSFXAudioDataType, 256);
+ _mixer->setVolumeForSoundType(SoundMixer::kMusicAudioDataType, 256);
// During normal gameplay, we care neither about mouse button releases
// nor the scroll wheel.