[Scummvm-cvs-logs] SF.net SVN: scummvm:[47591] scummvm/trunk
lordhoto at users.sourceforge.net
lordhoto at users.sourceforge.net
Wed Jan 27 09:08:33 CET 2010
Revision: 47591
http://scummvm.svn.sourceforge.net/scummvm/?rev=47591&view=rev
Author: lordhoto
Date: 2010-01-27 08:08:33 +0000 (Wed, 27 Jan 2010)
Log Message:
-----------
Fix invalid sample position on Timestamp to sample conversion for Stereo streams.
Modified Paths:
--------------
scummvm/trunk/engines/kyra/sound_digital.cpp
scummvm/trunk/sound/audiostream.cpp
scummvm/trunk/sound/audiostream.h
scummvm/trunk/sound/decoders/flac.cpp
scummvm/trunk/sound/decoders/raw.cpp
scummvm/trunk/sound/decoders/vorbis.cpp
Modified: scummvm/trunk/engines/kyra/sound_digital.cpp
===================================================================
--- scummvm/trunk/engines/kyra/sound_digital.cpp 2010-01-27 05:10:38 UTC (rev 47590)
+++ scummvm/trunk/engines/kyra/sound_digital.cpp 2010-01-27 08:08:33 UTC (rev 47591)
@@ -356,7 +356,7 @@
}
bool AUDStream::seek(const Audio::Timestamp &where) {
- const uint32 seekSample = Audio::calculateSampleOffset(where, getRate());
+ const uint32 seekSample = Audio::convertTimeToStreamPos(where, getRate(), isStereo()).totalNumberOfFrames();
_stream->seek(_streamStart);
_processedSize = 0;
Modified: scummvm/trunk/sound/audiostream.cpp
===================================================================
--- scummvm/trunk/sound/audiostream.cpp 2010-01-27 05:10:38 UTC (rev 47590)
+++ scummvm/trunk/sound/audiostream.cpp 2010-01-27 08:08:33 UTC (rev 47591)
@@ -164,8 +164,8 @@
DisposeAfterUse::Flag disposeAfterUse)
: _parent(stream), _disposeAfterUse(disposeAfterUse), _loops(loops),
_pos(0, getRate() * (isStereo() ? 2 : 1)),
- _loopStart(loopStart.convertToFramerate(getRate() * (isStereo() ? 2 : 1))),
- _loopEnd(loopEnd.convertToFramerate(getRate() * (isStereo() ? 2 : 1))),
+ _loopStart(convertTimeToStreamPos(loopStart, getRate(), isStereo())),
+ _loopEnd(convertTimeToStreamPos(loopEnd, getRate(), isStereo())),
_done(false) {
if (!_parent->rewind())
_done = true;
@@ -212,9 +212,9 @@
SubSeekableAudioStream::SubSeekableAudioStream(SeekableAudioStream *parent, const Timestamp start, const Timestamp end, DisposeAfterUse::Flag disposeAfterUse)
: _parent(parent), _disposeAfterUse(disposeAfterUse),
- _start(start.convertToFramerate(getRate())),
+ _start(convertTimeToStreamPos(start, getRate(), isStereo())),
_pos(0, getRate() * (isStereo() ? 2 : 1)),
- _length((end - start).convertToFramerate(getRate() * (isStereo() ? 2 : 1))) {
+ _length(convertTimeToStreamPos(end - start, getRate(), isStereo())) {
assert(_length.totalNumberOfFrames() % (isStereo() ? 2 : 1) == 0);
_parent->seek(_start);
@@ -233,7 +233,7 @@
}
bool SubSeekableAudioStream::seek(const Timestamp &where) {
- _pos = where.convertToFramerate(getRate());
+ _pos = convertTimeToStreamPos(where, getRate(), isStereo());
if (_pos > _length) {
_pos = _length;
return false;
@@ -364,4 +364,15 @@
return new QueuingAudioStreamImpl(rate, stereo);
}
+Timestamp convertTimeToStreamPos(const Timestamp &where, int rate, bool isStereo) {
+ Timestamp result(where.convertToFramerate(rate * (isStereo ? 2 : 1)));
+
+ // When the Stream is a stereo stream, we have to assure
+ // that the sample position is an even number.
+ if (isStereo && (result.totalNumberOfFrames() & 1))
+ return result.addFrames(-1); // We cut off one sample here.
+ else
+ return result;
+}
+
} // End of namespace Audio
Modified: scummvm/trunk/sound/audiostream.h
===================================================================
--- scummvm/trunk/sound/audiostream.h 2010-01-27 05:10:38 UTC (rev 47590)
+++ scummvm/trunk/sound/audiostream.h 2010-01-27 08:08:33 UTC (rev 47591)
@@ -162,9 +162,9 @@
* Tries to load a file by trying all available formats.
* In case of an error, the file handle will be closed, but deleting
* it is still the responsibility of the caller.
- * @param basename a filename without an extension
- * @return an SeekableAudioStream ready to use in case of success;
- * NULL in case of an error (e.g. invalid/nonexisting file)
+ * @param basename a filename without an extension
+ * @return an SeekableAudioStream ready to use in case of success;
+ * NULL in case of an error (e.g. invalid/nonexisting file)
*/
static SeekableAudioStream *openStreamFile(const Common::String &basename);
@@ -337,16 +337,15 @@
*/
QueuingAudioStream *makeQueuingAudioStream(int rate, bool stereo);
-
/**
- * Calculates the sample, which the timestamp describes in a
- * AudioStream with the given framerate.
+ * Converts a point in time to a precise sample offset
+ * with the given parameters.
*
- * @param where point in time
- * @param rate rate of the AudioStream
- * @return sample index
+ * @param where Point in time.
+ * @param rate Rate of the stream.
+ * @param isStereo Is the stream a stereo stream?
*/
-uint32 calculateSampleOffset(const Timestamp &where, int rate);
+Timestamp convertTimeToStreamPos(const Timestamp &where, int rate, bool isStereo);
} // End of namespace Audio
Modified: scummvm/trunk/sound/decoders/flac.cpp
===================================================================
--- scummvm/trunk/sound/decoders/flac.cpp 2010-01-27 05:10:38 UTC (rev 47590)
+++ scummvm/trunk/sound/decoders/flac.cpp 2010-01-27 08:08:33 UTC (rev 47591)
@@ -294,7 +294,7 @@
bool FlacInputStream::seek(const Timestamp &where) {
_sampleCache.bufFill = 0;
_sampleCache.bufReadPos = NULL;
- return seekAbsolute((FLAC__uint64)calculateSampleOffset(where, _streaminfo.sample_rate));
+ return seekAbsolute((FLAC__uint64)convertTimeToStreamPos(where, getRate(), isStereo()).totalNumberOfFrames());
}
int FlacInputStream::readBuffer(int16 *buffer, const int numSamples) {
Modified: scummvm/trunk/sound/decoders/raw.cpp
===================================================================
--- scummvm/trunk/sound/decoders/raw.cpp 2010-01-27 05:10:38 UTC (rev 47590)
+++ scummvm/trunk/sound/decoders/raw.cpp 2010-01-27 08:08:33 UTC (rev 47591)
@@ -41,13 +41,6 @@
((is16Bit ? (isLE ? READ_LE_UINT16(ptr) : READ_BE_UINT16(ptr)) : (*ptr << 8)) ^ (isUnsigned ? 0x8000 : 0))
-// TODO: Get rid of this
-uint32 calculateSampleOffset(const Timestamp &where, int rate) {
- return where.convertToFramerate(rate).totalNumberOfFrames();
-}
-
-
-
#pragma mark -
#pragma mark --- RawMemoryStream ---
#pragma mark -
@@ -110,7 +103,7 @@
template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
bool RawMemoryStream<stereo, is16Bit, isUnsigned, isLE>::seek(const Timestamp &where) {
- const uint8 *ptr = _origPtr + calculateSampleOffset(where, getRate()) * (is16Bit ? 2 : 1) * (stereo ? 2 : 1);
+ const uint8 *ptr = _origPtr + convertTimeToStreamPos(where, getRate(), isStereo()).totalNumberOfFrames() * (is16Bit ? 2 : 1);
if (ptr > _end) {
_ptr = _end;
return false;
@@ -275,7 +268,7 @@
template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
bool RawDiskStream<stereo, is16Bit, isUnsigned, isLE>::seek(const Timestamp &where) {
- const uint32 seekSample = calculateSampleOffset(where, getRate()) * (stereo ? 2 : 1);
+ const uint32 seekSample = convertTimeToStreamPos(where, getRate(), isStereo()).totalNumberOfFrames();
uint32 curSample = 0;
// Search for the disk block in which the specific sample is placed
Modified: scummvm/trunk/sound/decoders/vorbis.cpp
===================================================================
--- scummvm/trunk/sound/decoders/vorbis.cpp 2010-01-27 05:10:38 UTC (rev 47590)
+++ scummvm/trunk/sound/decoders/vorbis.cpp 2010-01-27 08:08:33 UTC (rev 47591)
@@ -169,7 +169,7 @@
}
bool VorbisInputStream::seek(const Timestamp &where) {
- int res = ov_pcm_seek(&_ovFile, calculateSampleOffset(where, getRate()));
+ int res = ov_pcm_seek(&_ovFile, convertTimeToStreamPos(where, getRate(), isStereo()).totalNumberOfFrames());
if (res) {
warning("Error seeking in Vorbis stream (%d)", res);
_pos = _bufferEnd;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list