diff options
author | Strangerke | 2019-08-05 20:02:21 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2019-09-03 17:17:32 +0200 |
commit | 22251ec2a77445d09f9f1100cd2752339acd075f (patch) | |
tree | 64e87e15f3e0f908dfa1fda3299320c3fc9ca382 /engines/hdb | |
parent | cb8976b65af38a7548c25e48e10b9b0f65d8aafd (diff) | |
download | scummvm-rg350-22251ec2a77445d09f9f1100cd2752339acd075f.tar.gz scummvm-rg350-22251ec2a77445d09f9f1100cd2752339acd075f.tar.bz2 scummvm-rg350-22251ec2a77445d09f9f1100cd2752339acd075f.zip |
HDB: Introduce two new enums for the sound
Diffstat (limited to 'engines/hdb')
-rw-r--r-- | engines/hdb/sound.cpp | 50 | ||||
-rw-r--r-- | engines/hdb/sound.h | 18 |
2 files changed, 39 insertions, 29 deletions
diff --git a/engines/hdb/sound.cpp b/engines/hdb/sound.cpp index ca7659c329..e744af6314 100644 --- a/engines/hdb/sound.cpp +++ b/engines/hdb/sound.cpp @@ -1427,14 +1427,14 @@ bool Sound::init() { int index = 0; while (soundList[index].idx != LAST_SOUND) { int index2 = soundList[index].idx; - _soundCache[index2].loaded = 0; + _soundCache[index2].loaded = SNDMEM_NOTCACHED; _soundCache[index2].name = soundList[index].name; _soundCache[index2].luaName = soundList[index].luaName; if (index2 <= SND_UNLOCKED_ITEM || index2 == SND_BEEPBEEPBEEP) - _soundCache[index2].ext = -1; // WAV + _soundCache[index2].ext = SNDTYPE_WAV; else - _soundCache[index2].ext = 1; // MP3 - debug(9, "Registering sound: sName: %s, \tsLuaName: %s, \tExtension: %s", soundList[index].name, soundList[index].luaName, _soundCache[index].ext == 1 ? "MP3" : "WAV"); + _soundCache[index2].ext = SNDTYPE_MP3; + debug(9, "Registering sound: sName: %s, \tsLuaName: %s, \tExtension: %s", soundList[index].name, soundList[index].luaName, _soundCache[index].ext == SNDTYPE_MP3 ? "MP3" : "WAV"); index++; if (index > kMaxSounds) error("Reached MAX_SOUNDS in Sound::Init() !"); @@ -1481,24 +1481,24 @@ bool Sound::playSound(int index) { return false; // is sound in memory at least? - if (_soundCache[index].loaded == -1) - _soundCache[index].loaded = 1; + if (_soundCache[index].loaded == SNDMEM_FREEABLE) + _soundCache[index].loaded = SNDMEM_LOADED; // is sound marked as cached? - if (!_soundCache[index].loaded) { + if (_soundCache[index].loaded == SNDMEM_NOTCACHED) { Common::SeekableReadStream *stream = g_hdb->_fileMan->findFirstData(_soundCache[index].name, TYPE_BINARY); if (stream == nullptr) return false; - if (_soundCache[index].ext == 1) { + if (_soundCache[index].ext == SNDTYPE_MP3) { #ifdef USE_MAD _soundCache[index].audioStream = Audio::makeMP3Stream(stream, DisposeAfterUse::YES); - _soundCache[index].loaded = 1; + _soundCache[index].loaded = SNDMEM_LOADED; #endif // USE_MAD } else { _soundCache[index].audioStream = Audio::makeWAVStream(stream, DisposeAfterUse::YES); - _soundCache[index].loaded = 1; + _soundCache[index].loaded = SNDMEM_LOADED; } } else { _soundCache[index].audioStream->rewind(); @@ -1543,24 +1543,24 @@ bool Sound::playSoundEx(int index, int channel, bool loop) { return false; // is sound in memory at least? - if (_soundCache[index].loaded == -1) - _soundCache[index].loaded = 1; + if (_soundCache[index].loaded == SNDMEM_FREEABLE) + _soundCache[index].loaded = SNDMEM_LOADED; // is sound marked as cached? - if (!_soundCache[index].loaded) { + if (_soundCache[index].loaded == SNDMEM_NOTCACHED) { Common::SeekableReadStream *stream = g_hdb->_fileMan->findFirstData(_soundCache[index].name, TYPE_BINARY); if (stream == nullptr) return false; - if (_soundCache[index].ext == 1) { + if (_soundCache[index].ext == SNDTYPE_MP3) { #ifdef USE_MAD _soundCache[index].audioStream = Audio::makeMP3Stream(stream, DisposeAfterUse::YES); - _soundCache[index].loaded = 1; + _soundCache[index].loaded = SNDMEM_LOADED; #endif // USE_MAD } else { _soundCache[index].audioStream = Audio::makeWAVStream(stream, DisposeAfterUse::YES); - _soundCache[index].loaded = 1; + _soundCache[index].loaded = SNDMEM_LOADED; } } else { _soundCache[index].audioStream->rewind(); @@ -1606,9 +1606,8 @@ bool Sound::playVoice(int index, int actor) { return false; // is voice channel already active? if so, shut 'er down (automagically called StopVoice via callback) - if (_voices[actor].active) { + if (_voices[actor].active) g_hdb->_mixer->stopHandle(*_voices[actor].handle); - } #ifdef USE_MAD Common::SeekableReadStream *stream = g_hdb->_fileMan->findFirstData(soundList[index].name, TYPE_BINARY); @@ -1831,8 +1830,7 @@ void Sound::updateMusic() { } int Sound::registerSound(const char *name) { - int index = 0; - + int index = 0; while (_soundCache[index].name) { index++; if (index == kMaxSounds) @@ -1840,14 +1838,14 @@ int Sound::registerSound(const char *name) { } _soundCache[index].name = name; - _soundCache[index].loaded = 0; // just to be sure! + _soundCache[index].loaded = SNDMEM_NOTCACHED; // just to be sure! return index; } bool Sound::freeSound(int index) { - if (_soundCache[index].loaded == 1) { - _soundCache[index].loaded = 0; - _soundCache[index].ext = 0; + if (_soundCache[index].loaded == SNDMEM_LOADED) { + _soundCache[index].loaded = SNDMEM_NOTCACHED; + _soundCache[index].ext = SNDTYPE_NONE; return true; } return false; @@ -1885,8 +1883,8 @@ SoundType Sound::whatSongIsPlaying() { void Sound::markSoundCacheFreeable() { int i; for (i = 0; i < kMaxSounds; i++) { - if (_soundCache[i].loaded == 1) - _soundCache[i].loaded = -1; + if (_soundCache[i].loaded == SNDMEM_LOADED) + _soundCache[i].loaded = SNDMEM_FREEABLE; } } diff --git a/engines/hdb/sound.h b/engines/hdb/sound.h index 9e04dadbd4..516df9b3fd 100644 --- a/engines/hdb/sound.h +++ b/engines/hdb/sound.h @@ -1434,15 +1434,27 @@ struct Voice { } }; +enum SndMem { + SNDMEM_FREEABLE = -1, + SNDMEM_NOTCACHED = 0, + SNDMEM_LOADED = 1 +}; + +enum SndType { + SNDTYPE_NONE = 0, + SNDTYPE_WAV = -1, + SNDTYPE_MP3 = 1 +}; + struct SoundCache { - int loaded; // -1 = freeable; in memory, 0 = not cached, 1 = cached + SndMem loaded; // -1 = freeable; in memory, 0 = not cached, 1 = cached int32 size; // size of sound const char *name; // filename / MSD name const char *luaName; // name used by Lua for i.d. - int ext; // 0 = Uninitialized, -1 = WAV, 1 = MP3 + SndType ext; // 0 = Uninitialized, -1 = WAV, 1 = MP3 Audio::SeekableAudioStream *audioStream; - SoundCache() : loaded(0), size(0), name(nullptr), luaName(nullptr), ext(0), audioStream(nullptr) {} + SoundCache() : loaded(SNDMEM_NOTCACHED), size(0), name(nullptr), luaName(nullptr), ext(SNDTYPE_NONE), audioStream(nullptr) {} }; struct Song { |