aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sound.cpp18
-rw-r--r--sound/mixer.cpp84
2 files changed, 54 insertions, 48 deletions
diff --git a/sound.cpp b/sound.cpp
index 75e12c87a3..ddd0c1bbaa 100644
--- a/sound.cpp
+++ b/sound.cpp
@@ -192,6 +192,8 @@ int Scumm::startTalkSound(uint32 offset, uint32 b, int mode)
byte file_byte, file_byte_2;
int size;
+ debug(1, "Starting sound %d.", offset);
+
if (!_sfxFile) {
warning("startTalkSound: SFX file is not open");
return -1;
@@ -232,6 +234,7 @@ int Scumm::startTalkSound(uint32 offset, uint32 b, int mode)
fileRead((FILE *) _sfxFile, &file_byte, sizeof(file_byte));
fileRead((FILE *) _sfxFile, &file_byte_2, sizeof(file_byte_2));
_mouthSyncTimes[i++] = file_byte | (file_byte_2 << 8);
+ debug(1, " - %d (0x%08x)", _mouthSyncTimes[i - 1], _mouthSyncTimes[i - 1]);
num--;
}
_mouthSyncTimes[i] = 0xFFFF;
@@ -274,6 +277,8 @@ int Scumm::isSoundRunning(int sound)
IMuse *se;
int i;
+ debug(1, " -> %d", sound);
+
if (sound == current_cd_sound)
return _system->poll_cdrom();
@@ -664,7 +669,7 @@ int Scumm::getCachedTrack(int track) {
if (bytes <= 0) {
if (bytes == -1) {
warning("Invalid format for track %d", track);
- return -1;
+ goto error;
}
break;
}
@@ -691,14 +696,14 @@ int Scumm::getCachedTrack(int track) {
break;
memmove(buffer, stream.next_frame,
- buflen = &buffer[buflen] - stream.next_frame);
+ buflen = &buffer[buflen] - stream.next_frame);
}
if (count)
memcpy(&_mad_header[current_index], &frame.header, sizeof(mad_header));
else {
warning("Invalid format for track %d", track);
- return -1;
+ goto error;
}
mad_frame_finish(&frame);
@@ -711,8 +716,13 @@ int Scumm::getCachedTrack(int track) {
_mp3_buffer = malloc(MP3_BUFFER_SIZE);
return current_index;
+
+ error:
+ mad_frame_finish(&frame);
+ mad_stream_finish(&stream);
+
+ return -1;
}
-
int Scumm::playMP3CDTrack(int track, int num_loops, int start, int delay) {
int index;
diff --git a/sound/mixer.cpp b/sound/mixer.cpp
index 5961a4f02a..90b55a0a0e 100644
--- a/sound/mixer.cpp
+++ b/sound/mixer.cpp
@@ -310,6 +310,8 @@ void SoundMixer::Channel_MP3::destroy() {
mad_frame_finish(&_frame);
mad_stream_finish(&_stream);
+ debug(1, "Sound finished");
+
delete this;
}
@@ -339,7 +341,7 @@ void SoundMixer::Channel_MP3_CDMUSIC::mix(int16 *data, uint len) {
if (!_initialized) {
int skip_loop;
// just skipped
- memset(_ptr, 0,_buffer_size + MAD_BUFFER_GUARD);
+ memset(_ptr, 0,_buffer_size);
_size = fread(_ptr, 1, _buffer_size, _file);
if (!_size) {
destroy();
@@ -350,18 +352,18 @@ void SoundMixer::Channel_MP3_CDMUSIC::mix(int16 *data, uint len) {
skip_loop = 2;
while (skip_loop != 0) {
if (mad_frame_decode(&_frame,&_stream) == 0) {
- /* Do not decrease duration - see if it's a problem */
- skip_loop--;
- if (skip_loop == 0) {
- mad_synth_frame(&_synth, &_frame);
- }
+ /* Do not decrease duration - see if it's a problem */
+ skip_loop--;
+ if (skip_loop == 0) {
+ mad_synth_frame(&_synth, &_frame);
+ }
} else {
- if (!MAD_RECOVERABLE(_stream.error)) {
- debug(1, "Unrecoverable error while skipping !");
- destroy();
- return;
- }
- }
+ if (!MAD_RECOVERABLE(_stream.error)) {
+ debug(1, "Unrecoverable error while skipping !");
+ destroy();
+ return;
+ }
+ }
}
// We are supposed to be in synch
mad_frame_mute(&_frame);
@@ -372,9 +374,9 @@ void SoundMixer::Channel_MP3_CDMUSIC::mix(int16 *data, uint len) {
_initialized = true;
}
else {
- debug(1, "Cannot resume decoding");
- destroy();
- return;
+ debug(1, "Cannot resume decoding");
+ destroy();
+ return;
}
}
@@ -396,40 +398,34 @@ void SoundMixer::Channel_MP3_CDMUSIC::mix(int16 *data, uint len) {
mad_timer_negate(&frame_duration);
mad_timer_add(&_duration, frame_duration);
if (mad_timer_compare(_duration, mad_timer_zero) < 0) {
- destroy();
- return;
+ destroy();
+ return;
}
if (mad_frame_decode(&_frame, &_stream) == -1) {
- if (_stream.error == MAD_ERROR_BUFLEN) {
- int not_decoded;
-
- if (!_stream.next_frame) {
- memset(_ptr, 0, _buffer_size + MAD_BUFFER_GUARD);
- _size =
- fread(_ptr, 1, _buffer_size, _file);
- not_decoded = 0;
- }
- else {
- not_decoded = _stream.bufend - _stream.next_frame;
- memcpy(_ptr, _stream.next_frame, not_decoded);
- _size =
- fread((unsigned char *)_ptr + not_decoded, 1,
- _buffer_size - not_decoded, _file);
- }
- _stream.error = MAD_ERROR_NONE;
- // Restream
- mad_stream_buffer(&_stream, (unsigned char *)_ptr, _size + not_decoded);
- if (mad_frame_decode(&_frame, &_stream) == -1) {
- debug(1, "Error decoding after restream %d !",
- _stream.error);
- }
- } else if (!MAD_RECOVERABLE(_stream.error)) {
- error("MAD frame decode error in MP3 CDMUSIC !");
- }
+ if (_stream.error == MAD_ERROR_BUFLEN) {
+ int not_decoded;
+
+ if (!_stream.next_frame) {
+ memset(_ptr, 0, _buffer_size + MAD_BUFFER_GUARD);
+ _size = fread(_ptr, 1, _buffer_size, _file);
+ not_decoded = 0;
+ } else {
+ not_decoded = _stream.bufend - _stream.next_frame;
+ memcpy(_ptr, _stream.next_frame, not_decoded);
+ _size = fread((unsigned char *)_ptr + not_decoded, 1, _buffer_size - not_decoded, _file);
+ }
+ _stream.error = MAD_ERROR_NONE;
+ // Restream
+ mad_stream_buffer(&_stream, (unsigned char *)_ptr, _size + not_decoded);
+ if (mad_frame_decode(&_frame, &_stream) == -1) {
+ debug(1, "Error decoding after restream %d !", _stream.error);
+ }
+ } else if (!MAD_RECOVERABLE(_stream.error)) {
+ error("MAD frame decode error in MP3 CDMUSIC !");
+ }
}
mad_synth_frame(&_synth, &_frame);
_pos_in_frame = 0;
-
}
}