aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Kiehl2002-11-13 16:34:22 +0000
committerOliver Kiehl2002-11-13 16:34:22 +0000
commit2ffeb62bfda8c7149b01e61571d90bdbe9e67ac4 (patch)
tree8c3b0b09eaf5963e531d896a01754bebaa10279b
parent26b284a93eb9b90506b0767743d6e82c60a36336 (diff)
downloadscummvm-rg350-2ffeb62bfda8c7149b01e61571d90bdbe9e67ac4.tar.gz
scummvm-rg350-2ffeb62bfda8c7149b01e61571d90bdbe9e67ac4.tar.bz2
scummvm-rg350-2ffeb62bfda8c7149b01e61571d90bdbe9e67ac4.zip
fixed looping problem, removed useless code and renamed playSound to playEffects
svn-id: r5538
-rw-r--r--simon/items.cpp2
-rw-r--r--simon/simon.cpp48
-rw-r--r--simon/simon.h10
-rw-r--r--simon/vga.cpp4
4 files changed, 34 insertions, 30 deletions
diff --git a/simon/items.cpp b/simon/items.cpp
index 30bc54a81b..321b558016 100644
--- a/simon/items.cpp
+++ b/simon/items.cpp
@@ -1644,7 +1644,7 @@ void SimonState::o_unk_120(uint a)
void SimonState::o_unk_163(uint a)
{
- playSound(a);
+ playEffects(a);
}
void SimonState::o_unk_160(uint a)
diff --git a/simon/simon.cpp b/simon/simon.cpp
index dc8f2dc176..50110c8081 100644
--- a/simon/simon.cpp
+++ b/simon/simon.cpp
@@ -4849,7 +4849,7 @@ struct VocBlockHeader {
#ifdef USE_MAD
-void SimonState::playMP3(File *sound_file, uint32 *offsets, uint sound, PlayingSoundHandle *sound_handle, byte flags)
+int SimonState::playMP3(File *sound_file, uint32 *offsets, uint sound, PlayingSoundHandle *sound_handle, byte flags)
{
sound_file->seek(offsets[sound], SEEK_SET);
@@ -4858,11 +4858,11 @@ void SimonState::playMP3(File *sound_file, uint32 *offsets, uint sound, PlayingS
byte *buffer = (byte *)malloc(size);
sound_file->read(buffer, size);
- _mixer->playMP3(sound_handle, buffer, size, flags);
+ return _mixer->playMP3(sound_handle, buffer, size, flags);
}
#endif
-void SimonState::playVoc(File *sound_file, uint32 *offsets, uint sound, PlayingSoundHandle *sound_handle, byte flags)
+int SimonState::playVoc(File *sound_file, uint32 *offsets, uint sound, PlayingSoundHandle *sound_handle, byte flags)
{
VocHeader voc_hdr;
VocBlockHeader voc_block_hdr;
@@ -4872,8 +4872,7 @@ void SimonState::playVoc(File *sound_file, uint32 *offsets, uint sound, PlayingS
if (sound_file->read(&voc_hdr, sizeof(voc_hdr)) != sizeof(voc_hdr) ||
strncmp((char *)voc_hdr.desc, "Creative Voice File\x1A", 10) != 0) {
- warning("playVoc(%d): cannot read voc header", sound);
- return;
+ error("playVoc(%d): cannot read voc header", sound);
}
sound_file->read(&voc_block_hdr, sizeof(voc_block_hdr));
@@ -4894,10 +4893,10 @@ void SimonState::playVoc(File *sound_file, uint32 *offsets, uint sound, PlayingS
byte *buffer = (byte *)malloc(size);
sound_file->read(buffer, size);
- _mixer->playRaw(sound_handle, buffer, size, samples_per_sec, flags);
+ return _mixer->playRaw(sound_handle, buffer, size, samples_per_sec, flags);
}
-void SimonState::playWav(File *sound_file, uint32 *offsets, uint sound, PlayingSoundHandle *sound_handle, byte flags)
+int SimonState::playWav(File *sound_file, uint32 *offsets, uint sound, PlayingSoundHandle *sound_handle, byte flags)
{
WaveHeader wave_hdr;
uint32 data[2];
@@ -4909,8 +4908,7 @@ void SimonState::playWav(File *sound_file, uint32 *offsets, uint sound, PlayingS
|| wave_hdr.fmt != MKID('fmt ') || READ_LE_UINT16(&wave_hdr.format_tag) != 1
|| READ_LE_UINT16(&wave_hdr.channels) != 1
|| READ_LE_UINT16(&wave_hdr.bits_per_sample) != 8) {
- warning("playWav(%d): cannot read RIFF header", sound);
- return;
+ error("playWav(%d): cannot read RIFF header", sound);
}
sound_file->seek(FROM_LE_32(wave_hdr.size) - sizeof(wave_hdr) + 20, SEEK_CUR);
@@ -4919,14 +4917,13 @@ void SimonState::playWav(File *sound_file, uint32 *offsets, uint sound, PlayingS
data[1] = sound_file->readUint32LE();
if ( //fread(data, sizeof(data), 1, sound_file) != 1 ||
data[0] != 'atad') {
- warning("playWav(%d): cannot read data header", sound);
- return;
+ error("playWav(%d): cannot read data header", sound);
}
byte *buffer = (byte *)malloc(data[1]);
sound_file->read(buffer, data[1]);
- _mixer->playRaw(sound_handle, buffer, data[1], FROM_LE_32(wave_hdr.samples_per_sec), flags);
+ return _mixer->playRaw(sound_handle, buffer, data[1], FROM_LE_32(wave_hdr.samples_per_sec), flags);
}
void SimonState::playVoice(uint voice)
@@ -4934,9 +4931,6 @@ void SimonState::playVoice(uint voice)
if (_voice_offsets == NULL)
return;
- if (_voice_sound != 0)
- _mixer->stop(_voice_sound);
-
#ifdef USE_MAD
if (_voice_type == FORMAT_MP3) {
playMP3(_voice_file, _voice_offsets, voice, &_voice_sound, SoundMixer::FLAG_AUTOFREE);
@@ -4952,10 +4946,10 @@ void SimonState::playVoice(uint voice)
#endif
}
-void SimonState::playSound(uint sound)
+void SimonState::playEffects(uint sound)
{
- if (_effects_sound != 0)
- _mixer->stop(_effects_sound);
+ if (_effects_offsets == NULL)
+ return;
if (_game == GAME_SIMON1TALKIE) { /* simon 1 talkie */
#ifdef USE_MAD
@@ -4974,20 +4968,28 @@ void SimonState::playSound(uint sound)
} else if (_game & GAME_SIMON2) { /* simon 2 dos / talkie */
playVoc(_game_file, _effects_offsets, sound, &_effects_sound, SoundMixer::FLAG_UNSIGNED|SoundMixer::FLAG_AUTOFREE);
} else { /* simon 1 dos */
- warning("playSound(%d)", sound);
+ warning("playEffects(%d)", sound);
}
}
void SimonState::playAmbient(uint sound)
{
- if (_effects_sound != 0)
- _mixer->stop(_ambient_sound);
+ if (_effects_offsets == NULL)
+ return;
+
+ if (sound == _ambient_playing)
+ return;
+
+ _ambient_playing = sound;
+
+ if (_ambient_sound)
+ _mixer->stop(_ambient_index);
if (_game & GAME_WIN) {
- playWav(_game_file, _effects_offsets, sound, &_ambient_sound,
+ _ambient_index = playWav(_game_file, _effects_offsets, sound, &_ambient_sound,
SoundMixer::FLAG_LOOP|SoundMixer::FLAG_UNSIGNED|SoundMixer::FLAG_AUTOFREE);
} else {
- playVoc(_game_file, _effects_offsets, sound, &_ambient_sound,
+ _ambient_index = playVoc(_game_file, _effects_offsets, sound, &_ambient_sound,
SoundMixer::FLAG_LOOP|SoundMixer::FLAG_UNSIGNED|SoundMixer::FLAG_AUTOFREE);
}
}
diff --git a/simon/simon.h b/simon/simon.h
index f7986fcccd..845bb4f06b 100644
--- a/simon/simon.h
+++ b/simon/simon.h
@@ -338,6 +338,8 @@ public:
PlayingSoundHandle _effects_sound;
PlayingSoundHandle _voice_sound;
PlayingSoundHandle _ambient_sound;
+ int _ambient_index;
+ uint _ambient_playing;
int _timer_id;
@@ -775,12 +777,12 @@ public:
void initSound();
void playVoice(uint voice);
- void playSound(uint sound);
+ void playEffects(uint sound);
void playAmbient(uint sound);
- void playVoc(File *sound_file, uint32 *offsets, uint sound, PlayingSoundHandle *sound_handle, byte flags);
- void playWav(File *sound_file, uint32 *offsets, uint sound, PlayingSoundHandle *sound_handle, byte flags);
- void playMP3(File *sound_file, uint32 *offsets, uint sound, PlayingSoundHandle *sound_handle, byte flags);
+ int playVoc(File *sound_file, uint32 *offsets, uint sound, PlayingSoundHandle *sound_handle, byte flags);
+ int playWav(File *sound_file, uint32 *offsets, uint sound, PlayingSoundHandle *sound_handle, byte flags);
+ int playMP3(File *sound_file, uint32 *offsets, uint sound, PlayingSoundHandle *sound_handle, byte flags);
void playMusic(uint music);
void checkTimerCallback();
diff --git a/simon/vga.cpp b/simon/vga.cpp
index 770f429b84..a0c322842f 100644
--- a/simon/vga.cpp
+++ b/simon/vga.cpp
@@ -1604,13 +1604,13 @@ void SimonState::vc_52()
uint16 a = vc_read_next_word();
if (!(_game & GAME_SIMON2)) {
- playSound(a);
+ playEffects(a);
} else {
if (a >= 0x8000) {
a = -a;
playAmbient(a);
} else {
- playSound(a);
+ playEffects(a);
}
}
}