aboutsummaryrefslogtreecommitdiff
path: root/sound.cpp
diff options
context:
space:
mode:
authorLionel Ulmer2002-05-03 21:11:16 +0000
committerLionel Ulmer2002-05-03 21:11:16 +0000
commitaa09cbf8fed6cc9cd8b461fd5f09a979d1f2a218 (patch)
tree3ed97c4bb9b87bb30b75b34f220c9abf97b9aa5b /sound.cpp
parentfe54e1caec7f50d5312816af6fb12d46050ca028 (diff)
downloadscummvm-rg350-aa09cbf8fed6cc9cd8b461fd5f09a979d1f2a218.tar.gz
scummvm-rg350-aa09cbf8fed6cc9cd8b461fd5f09a979d1f2a218.tar.bz2
scummvm-rg350-aa09cbf8fed6cc9cd8b461fd5f09a979d1f2a218.zip
Fixed a 'file descriptor' leak in the MP3 tracks caching
system. Rewrote a bit the call to the MAD timer API. svn-id: r4185
Diffstat (limited to 'sound.cpp')
-rw-r--r--sound.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/sound.cpp b/sound.cpp
index 806d213c8b..397e0d43d8 100644
--- a/sound.cpp
+++ b/sound.cpp
@@ -825,6 +825,9 @@ int Scumm::getCachedTrack(int track) {
sprintf(track_name, "%strack%d.mp3", _gameDataPath, track);
file = fopen(track_name, "rb");
_cached_tracks[current_index] = track;
+ /* First, close the previous file */
+ if (_mp3_tracks[current_index])
+ fclose(_mp3_tracks[current_index]);
_mp3_tracks[current_index] = NULL;
if (!file) {
// This warning is pretty pointless.
@@ -892,6 +895,7 @@ int Scumm::getCachedTrack(int track) {
error:
mad_frame_finish(&frame);
mad_stream_finish(&stream);
+ fclose(file);
return -1;
}
@@ -918,12 +922,13 @@ int Scumm::playMP3CDTrack(int track, int num_loops, int start, int delay) {
// Calc offset
frame_size = (float)(144 * _mad_header[index].bitrate / _mad_header[index].samplerate);
offset = (long)( (float)start / (float)75 * ((float)_mad_header[index].bitrate/(float)8));
-
+
// Calc delay
if (!delay) {
- mad_timer_set(&duration, 0, _mp3_size[index], (_mad_header[index].bitrate/8));
+ mad_timer_set(&duration, (_mp3_size[index] * 8) / _mad_header[index].bitrate,
+ (_mp3_size[index] * 8) % _mad_header[index].bitrate, _mad_header[index].bitrate);
} else {
- mad_timer_set(&duration, 0, delay, 75);
+ mad_timer_set(&duration, delay / 75, delay % 75, 75);
}
// Go