[Scummvm-cvs-logs] CVS: scummvm sound.cpp,1.71,1.72

Lionel Ulmer bbrox at users.sourceforge.net
Fri May 3 14:12:02 CEST 2002


Update of /cvsroot/scummvm/scummvm
In directory usw-pr-cvs1:/tmp/cvs-serv12425

Modified Files:
	sound.cpp 
Log Message:
Fixed a 'file descriptor' leak in the MP3 tracks caching
system. Rewrote a bit the call to the MAD timer API.



Index: sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound.cpp,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -d -r1.71 -r1.72
--- sound.cpp	1 May 2002 22:36:15 -0000	1.71
+++ sound.cpp	3 May 2002 21:11:16 -0000	1.72
@@ -825,6 +825,9 @@
 	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 @@
  error:
 	mad_frame_finish(&frame);
 	mad_stream_finish(&stream);
+	fclose(file);
 
 	return -1;
 }
@@ -918,12 +922,13 @@
 	// 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





More information about the Scummvm-git-logs mailing list