diff options
| -rw-r--r-- | sound/flac.cpp | 49 | ||||
| -rw-r--r-- | sound/mp3.cpp | 5 | 
2 files changed, 29 insertions, 25 deletions
diff --git a/sound/flac.cpp b/sound/flac.cpp index acd0a9fef7..f058d2dc6f 100644 --- a/sound/flac.cpp +++ b/sound/flac.cpp @@ -90,7 +90,6 @@ protected:  	bool _disposeAfterUse;  	uint _numLoops; -	const uint _totalNumLoops;  	::FLAC__SeekableStreamDecoder *_decoder; @@ -103,6 +102,9 @@ protected:  	/** index + 1(!) of the last sample to be played - 0 is end of stream */  	FLAC__uint64 _lastSample; +	/** total play time */ +	int32 _totalPlayTime; +  	/** true if the last sample was decoded from the FLAC-API - there might still be data in the buffer */  	bool _lastSampleWritten; @@ -142,28 +144,7 @@ public:  		return _streaminfo.channels == 0 || (_lastSampleWritten && _sampleCache.bufFill == 0);  	} -	int32 getTotalPlayTime() const { -		if (!_totalNumLoops) -			return AudioStream::kUnknownPlayTime; - -		int32 samples = 0; - -		if (!_lastSample) { -			if (!_streaminfo.total_samples) -				return AudioStream::kUnknownPlayTime; - -			samples = _streaminfo.total_samples - _firstSample; -		} else { -			samples = _lastSample - _firstSample - 1; -		} - -		const int32 rate = _streaminfo.sample_rate; - -		int32 seconds = samples / rate; -		int32 milliseconds = (1000 * (samples % rate)) / rate; - -		return (seconds * 1000 + milliseconds) * _totalNumLoops; -	} +	int32 getTotalPlayTime() const { return _totalPlayTime; }  	bool isStreamDecoderReady() const { return getStreamDecoderState() == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC ; } @@ -214,7 +195,6 @@ FlacInputStream::FlacInputStream(Common::SeekableReadStream *inStream, bool disp  		_inStream(inStream),  		_disposeAfterUse(dispose),  		_numLoops(numLoops), -		_totalNumLoops(numLoops),  		_firstSample(0), _lastSample(0),  		_outBuffer(NULL), _requestedSamples(0), _lastSampleWritten(false),  		_methodConvertBuffers(&FlacInputStream::convertBuffersGeneric) @@ -260,7 +240,28 @@ FlacInputStream::FlacInputStream(Common::SeekableReadStream *inStream, bool disp  			// avoid overflows).  			_firstSample = (FLAC__uint64)(startTime * (_streaminfo.sample_rate / 1000.0));  			_lastSample = (FLAC__uint64)(endTime * (_streaminfo.sample_rate / 1000.0)); +  			if (_firstSample == 0 || seekAbsolute(_firstSample)) { +				int32 samples = kUnknownPlayTime; + +				if (!_lastSample) { +					if (_streaminfo.total_samples) +						samples = _streaminfo.total_samples - _firstSample; +				} else { +					samples = _lastSample - _firstSample - 1; +				} + +				if (samples != kUnknownPlayTime && samples >= 0 && numLoops) { +					const int32 rate = _streaminfo.sample_rate; + +					int32 seconds = samples / rate; +					int32 milliseconds = (1000 * (samples % rate)) / rate; + +					_totalPlayTime = (seconds * 1000 + milliseconds) * numLoops; +				} else { +					_totalPlayTime = kUnknownPlayTime; +				} +  				return; // no error occured  			}  		} diff --git a/sound/mp3.cpp b/sound/mp3.cpp index 706c9d90ec..eea725ce3a 100644 --- a/sound/mp3.cpp +++ b/sound/mp3.cpp @@ -169,11 +169,14 @@ MP3InputStream::MP3InputStream(Common::SeekableReadStream *inStream, bool dispos  		// Reinit stream  		_state = MP3_STATE_INIT; + +		// Reset the stream data +		_inStream->seek(0, SEEK_SET);  	}  	_totalPlayTime = mad_timer_count(length, MAD_UNITS_MILLISECONDS); -	if (numLoops) +	if (numLoops && mad_timer_sign(length) >= 0)  		_totalPlayTime *= numLoops;  	else  		_totalPlayTime = kUnknownPlayTime;  | 
