[Scummvm-git-logs] scummvm master -> 37293f5b3f3c80b3190f058313a3a43403e3a454
sev-
sev at scummvm.org
Fri Oct 11 18:10:52 CEST 2019
This automated email contains information about 5 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
89b20bbb86 HDB: Factor out the song code into the Song class, avoiding a lot of duplicate code.
5675a00d8f HDB: Bail if the music stream couldn't be created.
1d9e7568fd HDB: Have a return value if the needed codec isn't included in the build.
b62b3ab859 HDB: No need to restate that member functions are indeed part of the class.
37293f5b3f HDB: Using the class keyword makes the intended use clearer.
Commit: 89b20bbb86608a6b61b56b13e9c35757bc5c4158
https://github.com/scummvm/scummvm/commit/89b20bbb86608a6b61b56b13e9c35757bc5c4158
Author: Henrik "Henke37" Andersson (henke at henke37.cjb.net)
Date: 2019-10-11T18:10:46+02:00
Commit Message:
HDB: Factor out the song code into the Song class, avoiding a lot of duplicate code.
Changed paths:
engines/hdb/sound.cpp
engines/hdb/sound.h
diff --git a/engines/hdb/sound.cpp b/engines/hdb/sound.cpp
index 4579212..5edde11 100644
--- a/engines/hdb/sound.cpp
+++ b/engines/hdb/sound.cpp
@@ -1422,8 +1422,6 @@ void Sound::test() {
}
void Sound::init() {
- _song1.playing = _song2.playing = false;
-
//
// init sound caching system
//
@@ -1465,21 +1463,6 @@ void Sound::loadSaveFile(Common::InSaveFile *in) {
}
}
-void Sound::setMusicVolume(int volume) {
- _musicVolume = volume;
- if (_song1.playing) {
- if (_song1.fadingIn)
- _song1.fadeInVol = volume;
- if (!_song1.fadingOut)
- g_hdb->_mixer->setChannelVolume(_song1.handle, volume);
- }
- if (_song2.playing) {
- if (_song2.fadingIn)
- _song2.fadeInVol = volume;
- if (!_song2.fadingOut)
- g_hdb->_mixer->setChannelVolume(_song2.handle, volume);
- }
-}
void Sound::playSound(int index) {
if (index > _numSounds || !_sfxVolume)
@@ -1708,6 +1691,16 @@ void Sound::playVoice(int index, int actor) {
return;
}
+void Sound::setMusicVolume(int volume) {
+ _musicVolume = volume;
+ if (_song1.isPlaying()) {
+ _song1.setVolume(volume);
+ }
+ if (_song2.isPlaying()) {
+ _song2.setVolume(volume);
+ }
+}
+
void Sound::startMusic(SoundType song) {
g_hdb->_menu->saveSong(song);
@@ -1728,22 +1721,18 @@ void Sound::fadeInMusic(SoundType song, int ramp) {
}
void Sound::fadeOutMusic(int ramp) {
- if (_song1.playing) {
- _song1.fadeOutRamp = ramp;
- _song1.fadingOut = true;
- _song1.fadeOutVol = _musicVolume;
- } else if (_song2.playing) {
- _song2.fadeOutRamp = ramp;
- _song2.fadingOut = true;
- _song2.fadeOutVol = _musicVolume;
+ if (_song1.isPlaying()) {
+ _song1.fadeOut(ramp);
+ } else if (_song2.isPlaying()) {
+ _song2.fadeOut(ramp);
}
}
bool Sound::songPlaying(SoundType song) {
- if (_song1.playing && _song1.song == song)
+ if (_song1.isPlaying() && _song1.getSong() == song)
return true;
- if (_song2.playing && _song2.song == song)
+ if (_song2.isPlaying() && _song2.getSong() == song)
return true;
return false;
@@ -1754,209 +1743,163 @@ void Sound::stopChannel(int channel) {
}
void Sound::stopMusic() {
- if (_song1.playing) {
- _song1.playing = false;
- g_hdb->_mixer->stopHandle(_song1.handle);
+ if (_song1.isPlaying()) {
+ _song1.stop();
}
- if (_song2.playing) {
- _song2.playing = false;
- g_hdb->_mixer->stopHandle(_song2.handle);
+ if (_song2.isPlaying()) {
+ _song2.stop();
}
}
void Sound::beginMusic(SoundType song, bool fadeIn, int ramp) {
- Common::String songName(soundList[song].name);
+ if (!_song1.isPlaying()) {
+ // Start fading out SONG2 if its playing
+ if (_song2.isPlaying()) {
+ _song2.fadeOut(ramp);
+ }
+
+ _song1.playSong(song, fadeIn, ramp);
+ }
+ else if (!_song2.isPlaying()) {
+ // Start fading out SONG1 if its playing
+ if (_song1.isPlaying()) {
+ _song1.fadeOut(ramp);
+ }
+ _song2.playSong(song, fadeIn, ramp);
+ }
+}
+
+bool Song::isPlaying() const {
+ return _playing;
+}
+
+SoundType Song::getSong() const {
+ return _song;
+}
+
+void Song::fadeOut(int ramp) {
+ fadeOutRamp = ramp;
+ fadingOut = true;
+ fadeOutVol = g_hdb->_sound->_musicVolume;
+}
+
+void Song::stop() {
+ _playing = false;
+ g_hdb->_mixer->stopHandle(handle);
+}
+
+void Song::playSong(SoundType song, bool fadeIn, int ramp) {
+ this->_song = song;
+ this->_playing = true;
+
+ Common::String fileName = getFileName(song);
+ Audio::AudioStream* musicStream = createStream(fileName);
+
+ int initialVolume;
+
+ if (fadeIn) {
+ fadeInRamp = ramp;
+ fadingIn = true;
+ fadeInVol = 0;
+ initialVolume=0;
+ } else {
+ initialVolume=g_hdb->_sound->_musicVolume;
+ }
+
+ g_hdb->_mixer->playStream(
+ Audio::Mixer::kMusicSoundType,
+ &handle,
+ musicStream,
+ -1,
+ initialVolume,
+ 0,
+ DisposeAfterUse::YES,
+ false,
+ false
+ );
+}
+
+Common::String Song::getFileName(SoundType song) {
+ Common::String fileName(soundList[song].name);
if (g_hdb->getPlatform() == Common::kPlatformLinux) {
- songName.replace(songName.begin() + songName.size() - 4, songName.end(), ".ogg");
+ fileName.replace(fileName.begin() + fileName.size() - 4, fileName.end(), ".ogg");
}
if (g_hdb->isPPC()) {
switch (song) {
case SONG_JEEBIES:
- songName = "jeebies.mp3";
+ fileName = "jeebies.mp3";
break;
case SONG_VIBRACIOUS:
- songName = "vibracious.mp3";
+ fileName = "vibracious.mp3";
break;
case SONG_ARETHERE:
- songName = "are_we_there_yet.mp3";
+ fileName = "are_we_there_yet.mp3";
break;
default:
break;
}
}
- if (!_song1.playing) {
- // Start fading out SONG2 if its playing
- if (_song2.playing) {
- _song2.fadeOutRamp = ramp;
- _song2.fadingOut = true;
- _song2.fadeOutVol = _musicVolume;
- }
-
- // Load up the song
+ return fileName;
+}
- Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(songName);
- if (stream == nullptr)
- return;
+Audio::AudioStream* Song::createStream(Common::String fileName) {
+ Common::SeekableReadStream* stream = SearchMan.createReadStreamForMember(fileName);
+ if (stream == nullptr)
+ return nullptr;
- if (g_hdb->getPlatform() != Common::kPlatformLinux) {
+ if (g_hdb->getPlatform() != Common::kPlatformLinux) {
#ifdef USE_MAD
- Audio::SeekableAudioStream *audioStream = Audio::makeMP3Stream(stream, DisposeAfterUse::YES);
- Audio::AudioStream *loopingStream = new Audio::LoopingAudioStream(audioStream, 0, DisposeAfterUse::YES);
-
- g_hdb->_mixer->setChannelVolume(_song1.handle, _musicVolume);
-
- // do we need to fade-in this song?
- if (fadeIn) {
- _song1.fadeInRamp = ramp;
- _song1.fadingIn = true;
- _song1.fadeInVol = 0;
- g_hdb->_mixer->setChannelVolume(_song1.handle, 0);
- }
-
- g_hdb->_mixer->playStream(
- Audio::Mixer::kMusicSoundType,
- &_song1.handle,
- loopingStream,
- -1,
- Audio::Mixer::kMaxChannelVolume,
- 0,
- DisposeAfterUse::YES,
- false,
- false
- );
- _song1.playing = true;
+ Audio::SeekableAudioStream* audioStream = Audio::makeMP3Stream(stream, DisposeAfterUse::YES);
+ return new Audio::LoopingAudioStream(audioStream, 0, DisposeAfterUse::YES);
#endif
- } else {
+ } else {
#ifdef USE_VORBIS
- Audio::SeekableAudioStream *audioStream = Audio::makeVorbisStream(stream, DisposeAfterUse::YES);
- Audio::AudioStream *loopingStream = new Audio::LoopingAudioStream(audioStream, 0, DisposeAfterUse::YES);
-
- g_hdb->_mixer->setChannelVolume(_song1.handle, _musicVolume);
-
- // do we need to fade-in this song?
- if (fadeIn) {
- _song1.fadeInRamp = ramp;
- _song1.fadingIn = true;
- _song1.fadeInVol = 0;
- g_hdb->_mixer->setChannelVolume(_song1.handle, 0);
- }
-
- g_hdb->_mixer->playStream(
- Audio::Mixer::kMusicSoundType,
- &_song1.handle,
- loopingStream,
- -1,
- Audio::Mixer::kMaxChannelVolume,
- 0,
- DisposeAfterUse::YES,
- false,
- false
- );
- _song1.playing = true;
+ Audio::SeekableAudioStream* audioStream = Audio::makeVorbisStream(stream, DisposeAfterUse::YES);
+ return new Audio::LoopingAudioStream(audioStream, 0, DisposeAfterUse::YES);
#endif
- }
- } else if (!_song2.playing) {
- // Start fading out SONG1 if its playing
- if (_song1.playing) {
- _song1.fadeOutRamp = ramp;
- _song1.fadingOut = true;
- _song1.fadeOutVol = _musicVolume;
- }
-
- // Load up the song
-
- Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(songName);
- if (stream == nullptr)
- return;
+ }
+}
- if (g_hdb->getPlatform() != Common::kPlatformLinux) {
-#ifdef USE_MAD
+void Song::setVolume(int volume) {
+ if (fadingIn)
+ fadeInVol = volume;
+ if (!fadingOut)
+ g_hdb->_mixer->setChannelVolume(handle, volume);
+}
- Audio::SeekableAudioStream *audioStream = Audio::makeMP3Stream(stream, DisposeAfterUse::YES);
- Audio::AudioStream *loopingStream = new Audio::LoopingAudioStream(audioStream, 0, DisposeAfterUse::YES);
-
- g_hdb->_mixer->setChannelVolume(_song2.handle, _musicVolume);
-
- // do we need to fade-in this song?
- if (fadeIn) {
- _song2.fadeInRamp = ramp;
- _song2.fadingIn = true;
- _song2.fadeInVol = 0;
- g_hdb->_mixer->setChannelVolume(_song2.handle, 0);
- }
-
- g_hdb->_mixer->playStream(
- Audio::Mixer::kMusicSoundType,
- &_song2.handle,
- loopingStream,
- -1,
- Audio::Mixer::kMaxChannelVolume,
- 0,
- DisposeAfterUse::YES,
- false,
- false
- );
- _song2.playing = true;
-#endif
- } else {
-#ifdef USE_VORBIS
- Audio::SeekableAudioStream *audioStream = Audio::makeVorbisStream(stream, DisposeAfterUse::YES);
- Audio::AudioStream *loopingStream = new Audio::LoopingAudioStream(audioStream, 0, DisposeAfterUse::YES);
-
- g_hdb->_mixer->setChannelVolume(_song2.handle, _musicVolume);
-
- // do we need to fade-in this song?
- if (fadeIn) {
- _song2.fadeInRamp = ramp;
- _song2.fadingIn = true;
- _song2.fadeInVol = 0;
- g_hdb->_mixer->setChannelVolume(_song2.handle, 0);
- }
-
- g_hdb->_mixer->playStream(
- Audio::Mixer::kMusicSoundType,
- &_song2.handle,
- loopingStream,
- -1,
- Audio::Mixer::kMaxChannelVolume,
- 0,
- DisposeAfterUse::YES,
- false,
- false
- );
- _song2.playing = true;
-#endif
- }
+void Song::update() {
+ if (fadingOut) {
+ fadeOutVol = 0;
+ _playing = false;
+ g_hdb->_mixer->stopHandle(handle);
+ }
+ else if (fadingIn) {
+ fadeInVol = g_hdb->_sound->_musicVolume;
+ fadingIn = false;
}
}
void Sound::updateMusic() {
-
- if (_song1.playing) {
- if (_song1.fadingOut) {
- _song1.fadeOutVol = 0;
- _song1.playing = false;
- g_hdb->_mixer->stopHandle(_song1.handle);
- } else if (_song1.fadingIn) {
- _song1.fadeInVol = _musicVolume;
- _song1.fadingIn = false;
- }
+ if (_song1.isPlaying()) {
+ _song1.update();
}
- if (_song2.playing) {
- if (_song2.fadingOut) {
- _song2.fadeOutVol = 0;
- _song2.playing = false;
- g_hdb->_mixer->stopHandle(_song2.handle);
- } else if (_song2.fadingIn) {
- _song2.fadeInVol = _musicVolume;
- _song2.fadingIn = false;
- }
+ if (_song2.isPlaying()) {
+ _song2.update();
}
+}
+SoundType Sound::whatSongIsPlaying() {
+ if (_song1.isPlaying())
+ return _song1.getSong();
+
+ if (_song2.isPlaying())
+ return _song2.getSong();
+
+ return SONG_NONE;
}
int Sound::registerSound(const char *name) {
@@ -1995,16 +1938,6 @@ int Sound::getSNDIndex(const char *name) {
return 0;
}
-SoundType Sound::whatSongIsPlaying() {
- if (_song1.playing)
- return _song1.song;
-
- if (_song2.playing)
- return _song2.song;
-
- return SONG_NONE;
-}
-
void Sound::markSoundCacheFreeable() {
for (int i = 0; i < kMaxSounds; i++) {
if (_soundCache[i].loaded == SNDMEM_LOADED)
diff --git a/engines/hdb/sound.h b/engines/hdb/sound.h
index 8cf687d..accdbff 100644
--- a/engines/hdb/sound.h
+++ b/engines/hdb/sound.h
@@ -1457,10 +1457,31 @@ struct SoundCache {
};
struct Song {
- bool playing;
- SoundType song;
+
+ Song() : _playing(false), _song(SONG_NONE),
+ fadingOut(false), fadeOutVol(0), fadeOutRamp(0),
+ fadingIn(false), fadeInVol(0), fadeInRamp(0) {}
+
+ void playSong(SoundType song, bool fadeIn, int ramp);
+ void fadeOut(int ramp);
+ void stop();
+
+ bool isPlaying() const;
+ SoundType getSong() const;
+
+ void setVolume(int volume);
+
+ void update();
+
+private:
+ static Common::String Song::getFileName(SoundType song);
+ Audio::AudioStream* Song::createStream(Common::String fileName);
+
Audio::SoundHandle handle;
+ bool _playing;
+ SoundType _song;
+
bool fadingOut;
int fadeOutVol;
int fadeOutRamp;
@@ -1468,10 +1489,6 @@ struct Song {
bool fadingIn;
int fadeInVol;
int fadeInRamp;
-
- Song() : playing(false), song(SONG_NONE),
- fadingOut(false), fadeOutVol(0), fadeOutRamp(0),
- fadingIn(false), fadeInVol(0), fadeInRamp(0) {}
};
class Sound {
Commit: 5675a00d8fa2be55d4ff366b65cfd4c0721ab4fe
https://github.com/scummvm/scummvm/commit/5675a00d8fa2be55d4ff366b65cfd4c0721ab4fe
Author: Henrik "Henke37" Andersson (henke at henke37.cjb.net)
Date: 2019-10-11T18:10:46+02:00
Commit Message:
HDB: Bail if the music stream couldn't be created.
Changed paths:
engines/hdb/sound.cpp
diff --git a/engines/hdb/sound.cpp b/engines/hdb/sound.cpp
index 5edde11..d69618a 100644
--- a/engines/hdb/sound.cpp
+++ b/engines/hdb/sound.cpp
@@ -1789,12 +1789,15 @@ void Song::stop() {
}
void Song::playSong(SoundType song, bool fadeIn, int ramp) {
- this->_song = song;
- this->_playing = true;
Common::String fileName = getFileName(song);
Audio::AudioStream* musicStream = createStream(fileName);
+ if (musicStream == nullptr) return;
+
+ this->_song = song;
+ this->_playing = true;
+
int initialVolume;
if (fadeIn) {
Commit: 1d9e7568fdd827024e6c458d30950e94968a830b
https://github.com/scummvm/scummvm/commit/1d9e7568fdd827024e6c458d30950e94968a830b
Author: Henrik "Henke37" Andersson (henke at henke37.cjb.net)
Date: 2019-10-11T18:10:46+02:00
Commit Message:
HDB: Have a return value if the needed codec isn't included in the build.
Changed paths:
engines/hdb/sound.cpp
diff --git a/engines/hdb/sound.cpp b/engines/hdb/sound.cpp
index d69618a..33c3540 100644
--- a/engines/hdb/sound.cpp
+++ b/engines/hdb/sound.cpp
@@ -1857,11 +1857,15 @@ Audio::AudioStream* Song::createStream(Common::String fileName) {
#ifdef USE_MAD
Audio::SeekableAudioStream* audioStream = Audio::makeMP3Stream(stream, DisposeAfterUse::YES);
return new Audio::LoopingAudioStream(audioStream, 0, DisposeAfterUse::YES);
+#else
+ return nullptr;
#endif
} else {
#ifdef USE_VORBIS
Audio::SeekableAudioStream* audioStream = Audio::makeVorbisStream(stream, DisposeAfterUse::YES);
return new Audio::LoopingAudioStream(audioStream, 0, DisposeAfterUse::YES);
+#else
+ return nullptr;
#endif
}
}
Commit: b62b3ab8598d7243131c5da853331050ae6d204b
https://github.com/scummvm/scummvm/commit/b62b3ab8598d7243131c5da853331050ae6d204b
Author: Henrik "Henke37" Andersson (henke at henke37.cjb.net)
Date: 2019-10-11T18:10:46+02:00
Commit Message:
HDB: No need to restate that member functions are indeed part of the class.
Changed paths:
engines/hdb/sound.h
diff --git a/engines/hdb/sound.h b/engines/hdb/sound.h
index accdbff..ebddcb1 100644
--- a/engines/hdb/sound.h
+++ b/engines/hdb/sound.h
@@ -1474,8 +1474,8 @@ struct Song {
void update();
private:
- static Common::String Song::getFileName(SoundType song);
- Audio::AudioStream* Song::createStream(Common::String fileName);
+ static Common::String getFileName(SoundType song);
+ Audio::AudioStream* createStream(Common::String fileName);
Audio::SoundHandle handle;
Commit: 37293f5b3f3c80b3190f058313a3a43403e3a454
https://github.com/scummvm/scummvm/commit/37293f5b3f3c80b3190f058313a3a43403e3a454
Author: Henrik "Henke37" Andersson (henke at henke37.cjb.net)
Date: 2019-10-11T18:10:46+02:00
Commit Message:
HDB: Using the class keyword makes the intended use clearer.
Changed paths:
engines/hdb/sound.h
diff --git a/engines/hdb/sound.h b/engines/hdb/sound.h
index ebddcb1..3ae5b3b 100644
--- a/engines/hdb/sound.h
+++ b/engines/hdb/sound.h
@@ -1456,8 +1456,8 @@ struct SoundCache {
SoundCache() : loaded(SNDMEM_NOTCACHED), size(0), name(nullptr), luaName(nullptr), ext(SNDTYPE_NONE), data(nullptr) {}
};
-struct Song {
-
+class Song {
+public:
Song() : _playing(false), _song(SONG_NONE),
fadingOut(false), fadeOutVol(0), fadeOutRamp(0),
fadingIn(false), fadeInVol(0), fadeInRamp(0) {}
More information about the Scummvm-git-logs
mailing list