mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-04 09:56:30 +00:00
- Simplify Audio::calculateSampleOffset.
- Made Audio::calculateSampleOffset accessable from outside audiostream.cpp. - Adapt KYRA's AUDStream to use Audio::calculateSampleOffset. svn-id: r47082
This commit is contained in:
parent
e72707b04e
commit
297a955579
@ -121,7 +121,7 @@ public:
|
||||
|
||||
int getRate() const { return _rate; }
|
||||
|
||||
bool seek(const Audio::Timestamp &);
|
||||
bool seek(const Audio::Timestamp &where);
|
||||
Audio::Timestamp getLength() const { return _length; }
|
||||
private:
|
||||
Common::SeekableReadStream *_stream;
|
||||
@ -356,8 +356,7 @@ int AUDStream::readChunk(int16 *buffer, const int maxSamples) {
|
||||
}
|
||||
|
||||
bool AUDStream::seek(const Audio::Timestamp &where) {
|
||||
// TODO: A more exact implementation would be nice
|
||||
const uint32 seekSample = where.msecs() * getRate() / 1000;
|
||||
const uint32 seekSample = Audio::calculateSampleOffset(where, getRate());
|
||||
|
||||
_stream->seek(_streamStart);
|
||||
_processedSize = 0;
|
||||
|
@ -109,14 +109,8 @@ inline int32 calculatePlayTime(int rate, int samples) {
|
||||
}
|
||||
|
||||
uint32 calculateSampleOffset(const Timestamp &where, int rate) {
|
||||
const uint32 msecs = where.msecs();
|
||||
|
||||
const Timestamp msecStamp(msecs, rate);
|
||||
const uint32 seconds = msecs / 1000;
|
||||
const uint32 millis = msecs % 1000;
|
||||
const uint32 samples = msecStamp.frameDiff(where) + (millis * rate) / 1000;
|
||||
|
||||
return seconds * rate + samples;
|
||||
const Timestamp whereRate = where.convertToFramerate(rate);
|
||||
return whereRate.secs() * rate + whereRate.getNumberOfFrames();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -205,6 +205,15 @@ public:
|
||||
*/
|
||||
AppendableAudioStream *makeAppendableAudioStream(int rate, byte flags);
|
||||
|
||||
/**
|
||||
* Calculates the sample, which the timestamp describes in a
|
||||
* AudioStream with the given framerate.
|
||||
*
|
||||
* @param where point in time
|
||||
* @param rate rate of the AudioStream
|
||||
* @return sample index
|
||||
*/
|
||||
uint32 calculateSampleOffset(const Timestamp &where, int rate);
|
||||
|
||||
} // End of namespace Audio
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user