aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaromir Wysoglad2019-06-24 09:06:47 +0200
committerThierry Crozat2019-07-28 15:09:14 +0100
commit2f84e6d22aecc96e66477a1e14adba4755cadc63 (patch)
tree663ff214c05f2ff6a835e8dd262995806bde482c
parent3cf9cfbf78433e81ac5dcc39b31f5fa76983bde4 (diff)
downloadscummvm-rg350-2f84e6d22aecc96e66477a1e14adba4755cadc63.tar.gz
scummvm-rg350-2f84e6d22aecc96e66477a1e14adba4755cadc63.tar.bz2
scummvm-rg350-2f84e6d22aecc96e66477a1e14adba4755cadc63.zip
SUPERNOVA: Refactor sound initialization
-rw-r--r--engines/supernova/resman.cpp42
-rw-r--r--engines/supernova/resman.h4
-rw-r--r--engines/supernova/sound.h9
3 files changed, 25 insertions, 30 deletions
diff --git a/engines/supernova/resman.cpp b/engines/supernova/resman.cpp
index 9b89b10d7a..0f104e53b3 100644
--- a/engines/supernova/resman.cpp
+++ b/engines/supernova/resman.cpp
@@ -44,8 +44,7 @@ struct AudioInfo {
static Common::MemoryReadStream *convertToMod(const char *filename, int version = 1);
-static const AudioInfo audioInfo[] = {
- // Supernova 1
+static const AudioInfo audioInfo1[] = {
{44, 0, -1},
{45, 0, -1},
{46, 0, 2510},
@@ -66,9 +65,9 @@ static const AudioInfo audioInfo[] = {
{54, 24020, 30030},
{54, 30030, 31040},
{54, 31040, -1},
+};
- {0 , 0, 0},
- // Supernova 2
+static const AudioInfo audioInfo2[] = {
{55, 18230, -1},
{47, 0, 16010},
{47, 16010, 17020},
@@ -134,6 +133,7 @@ ResourceManager::~ResourceManager() {
for (int i = 0; i < 47; i++)
delete _images[i];
}
+ delete[] _soundSamples;
}
void ResourceManager::initSoundFiles1() {
@@ -143,24 +143,25 @@ void ResourceManager::initSoundFiles1() {
// where SS SS (LE uint16) is the size of the sound sample + 2
// - samples end with a footer of 4 bytes: 00 00
// Skip those in the buffer
+ _soundSamples = new Common::ScopedPtr<Audio::SeekableAudioStream>[kAudioNumSamples1];
Common::File file;
for (int i = 0; i < kAudioNumSamples1; ++i) {
- if (!file.open(Common::String::format("msn_data.%03d", audioInfo[i]._filenumber))) {
+ if (!file.open(Common::String::format("msn_data.%03d", audioInfo1[i]._filenumber))) {
error("File %s could not be read!", file.getName());
}
int length = 0;
byte *buffer = nullptr;
- if (audioInfo[i]._offsetEnd == -1) {
+ if (audioInfo1[i]._offsetEnd == -1) {
file.seek(0, SEEK_END);
- length = file.pos() - audioInfo[i]._offsetStart - 10;
+ length = file.pos() - audioInfo1[i]._offsetStart - 10;
} else {
- length = audioInfo[i]._offsetEnd - audioInfo[i]._offsetStart - 10;
+ length = audioInfo1[i]._offsetEnd - audioInfo1[i]._offsetStart - 10;
}
buffer = new byte[length];
- file.seek(audioInfo[i]._offsetStart + 6);
+ file.seek(audioInfo1[i]._offsetStart + 6);
file.read(buffer, length);
file.close();
@@ -180,24 +181,25 @@ void ResourceManager::initSoundFiles2() {
// where SS SS (LE uint16) is the size of the sound sample + 2
// - samples end with a footer of 4 bytes: 00 00
// Skip those in the buffer
+ _soundSamples = new Common::ScopedPtr<Audio::SeekableAudioStream>[kAudioNumSamples2];
Common::File file;
- for (int i = 0; i < kAudioNumSamples2 - kAudioNumSamples1 - 1; ++i) {
- if (!file.open(Common::String::format("ms2_data.%03d", audioInfo[i + kAudioNumSamples1 + 1]._filenumber))) {
+ for (int i = 0; i < kAudioNumSamples2; ++i) {
+ if (!file.open(Common::String::format("ms2_data.%03d", audioInfo2[i]._filenumber))) {
error("File %s could not be read!", file.getName());
}
int length = 0;
byte *buffer = nullptr;
- if (audioInfo[i + kAudioNumSamples1 + 1]._offsetEnd == -1) {
+ if (audioInfo2[i]._offsetEnd == -1) {
file.seek(0, SEEK_END);
- length = file.pos() - audioInfo[i + kAudioNumSamples1 + 1]._offsetStart - 10;
+ length = file.pos() - audioInfo2[i]._offsetStart - 10;
} else {
- length = audioInfo[i + kAudioNumSamples1 + 1]._offsetEnd - audioInfo[i + kAudioNumSamples1 + 1]._offsetStart - 10;
+ length = audioInfo2[i]._offsetEnd - audioInfo2[i]._offsetStart - 10;
}
buffer = new byte[length];
- file.seek(audioInfo[i + kAudioNumSamples1 + 1]._offsetStart + 6);
+ file.seek(audioInfo2[i]._offsetStart + 6);
file.read(buffer, length);
file.close();
@@ -208,7 +210,7 @@ void ResourceManager::initSoundFiles2() {
initSiren();
_musicIntroBuffer.reset(convertToMod("ms2_data.052", 2));
- _musicMadMonkeysBuffer.reset(convertToMod("ms2_data.056", 2));
+ _musicOutroBuffer.reset(convertToMod("ms2_data.056", 2));
}
void ResourceManager::initGraphics() {
@@ -262,10 +264,7 @@ void ResourceManager::initImages2() {
Audio::SeekableAudioStream *ResourceManager::getSoundStream(AudioId index) {
Audio::SeekableAudioStream *stream;
- if (_MSPart == 1)
- stream = _soundSamples[index].get();
- else if (_MSPart == 2)
- stream = _soundSamples[index - kAudioNumSamples1 - 1].get();
+ stream = _soundSamples[index].get();
stream->rewind();
return stream;
@@ -277,8 +276,7 @@ Audio::AudioStream *ResourceManager::getSoundStream(MusicId index) {
_musicIntro.reset(Audio::makeProtrackerStream(_musicIntroBuffer.get()));
return _musicIntro.get();
case kMusicMadMonkeys:
- _musicMadMonkeys.reset(Audio::makeProtrackerStream(_musicMadMonkeysBuffer.get()));
- return _musicMadMonkeys.get();
+ // fall through
case kMusicOutro:
_musicOutro.reset(Audio::makeProtrackerStream(_musicOutroBuffer.get()));
return _musicOutro.get();
diff --git a/engines/supernova/resman.h b/engines/supernova/resman.h
index 9cbf83ab01..4ae617eb68 100644
--- a/engines/supernova/resman.h
+++ b/engines/supernova/resman.h
@@ -70,14 +70,12 @@ private:
byte *generateTone(byte *buffer, int frequency, int length, int audioRate, Common::SineTable &table);
private:
- Common::ScopedPtr<Audio::SeekableAudioStream> _soundSamples[kAudioNumSamples1];
+ Common::ScopedPtr<Audio::SeekableAudioStream> *_soundSamples;
Common::ScopedPtr<Common::MemoryReadStream> _musicIntroBuffer;
Common::ScopedPtr<Common::MemoryReadStream> _musicOutroBuffer;
- Common::ScopedPtr<Common::MemoryReadStream> _musicMadMonkeysBuffer;
Common::ScopedPtr<Audio::AudioStream> _musicIntro;
Common::ScopedPtr<Audio::AudioStream> _musicOutro;
Common::ScopedPtr<Audio::AudioStream> _sirenStream;
- Common::ScopedPtr<Audio::AudioStream> _musicMadMonkeys;
int _MSPart;
int _audioRate;
MSNImage *_images[kNumImageFiles];
diff --git a/engines/supernova/sound.h b/engines/supernova/sound.h
index c0ca635df8..55d8e0d1fa 100644
--- a/engines/supernova/sound.h
+++ b/engines/supernova/sound.h
@@ -55,7 +55,7 @@ enum AudioId {
kAudioNumSamples1,
// Supernova 2
- kAudioIntroDing,
+ kAudioIntroDing = 0,
kAudioSuccess2,
kAudioTaxiOpen,
kAudioTaxiLeaving,
@@ -78,10 +78,9 @@ enum AudioId {
};
enum MusicId {
- kMusicIntro = 49,
- kMusicIntro2 = 52,
- kMusicOutro = 52,
- kMusicMadMonkeys = 51
+ kMusicIntro,
+ kMusicOutro,
+ kMusicMadMonkeys
};
class Sound {