aboutsummaryrefslogtreecommitdiff
path: root/audio
diff options
context:
space:
mode:
Diffstat (limited to 'audio')
-rw-r--r--audio/audiostream.cpp38
-rw-r--r--audio/audiostream.h10
-rw-r--r--audio/decoders/quicktime.cpp39
3 files changed, 50 insertions, 37 deletions
diff --git a/audio/audiostream.cpp b/audio/audiostream.cpp
index 1c5c435359..6e185702f0 100644
--- a/audio/audiostream.cpp
+++ b/audio/audiostream.cpp
@@ -386,4 +386,42 @@ Timestamp convertTimeToStreamPos(const Timestamp &where, int rate, bool isStereo
return Timestamp(result.secs(), result.numberOfFrames(), result.framerate());
}
+/**
+ * An AudioStream wrapper that cuts off the amount of samples read after a
+ * given time length is reached.
+ */
+class LimitingAudioStream : public AudioStream {
+public:
+ LimitingAudioStream(AudioStream *parentStream, const Audio::Timestamp &length, DisposeAfterUse::Flag disposeAfterUse) :
+ _parentStream(parentStream), _samplesRead(0), _disposeAfterUse(disposeAfterUse),
+ _totalSamples(length.convertToFramerate(getRate()).totalNumberOfFrames() * getChannels()) {}
+
+ ~LimitingAudioStream() {
+ if (_disposeAfterUse == DisposeAfterUse::YES)
+ delete _parentStream;
+ }
+
+ int readBuffer(int16 *buffer, const int numSamples) {
+ // Cap us off so we don't read past _totalSamples
+ int samplesRead = _parentStream->readBuffer(buffer, MIN<int>(numSamples, _totalSamples - _samplesRead));
+ _samplesRead += samplesRead;
+ return samplesRead;
+ }
+
+ bool endOfData() const { return _parentStream->endOfData() || _samplesRead >= _totalSamples; }
+ bool isStereo() const { return _parentStream->isStereo(); }
+ int getRate() const { return _parentStream->getRate(); }
+
+private:
+ int getChannels() const { return isStereo() ? 2 : 1; }
+
+ AudioStream *_parentStream;
+ DisposeAfterUse::Flag _disposeAfterUse;
+ uint32 _totalSamples, _samplesRead;
+};
+
+AudioStream *makeLimitingAudioStream(AudioStream *parentStream, const Timestamp &length, DisposeAfterUse::Flag disposeAfterUse) {
+ return new LimitingAudioStream(parentStream, length, disposeAfterUse);
+}
+
} // End of namespace Audio
diff --git a/audio/audiostream.h b/audio/audiostream.h
index 801f13d9d9..d6d4a16280 100644
--- a/audio/audiostream.h
+++ b/audio/audiostream.h
@@ -356,6 +356,16 @@ QueuingAudioStream *makeQueuingAudioStream(int rate, bool stereo);
*/
Timestamp convertTimeToStreamPos(const Timestamp &where, int rate, bool isStereo);
+/**
+ * Factory function for an AudioStream wrapper that cuts off the amount of samples read after a
+ * given time length is reached.
+ *
+ * @param parentStream The stream to limit
+ * @param length The time length to limit the stream to
+ * @param disposeAfterUse Whether the parent stream object should be destroyed on destruction of the returned stream
+ */
+AudioStream *makeLimitingAudioStream(AudioStream *parentStream, const Timestamp &length, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES);
+
} // End of namespace Audio
#endif
diff --git a/audio/decoders/quicktime.cpp b/audio/decoders/quicktime.cpp
index 8874a61c2e..5276cfc530 100644
--- a/audio/decoders/quicktime.cpp
+++ b/audio/decoders/quicktime.cpp
@@ -62,41 +62,6 @@ private:
};
/**
- * An AudioStream wrapper that cuts off the amount of samples read after a
- * given time length is reached.
- */
-class LimitingAudioStream : public AudioStream {
-public:
- LimitingAudioStream(AudioStream *parentStream, const Audio::Timestamp &length,
- DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES) :
- _parentStream(parentStream), _samplesRead(0), _disposeAfterUse(disposeAfterUse),
- _totalSamples(length.convertToFramerate(getRate()).totalNumberOfFrames() * getChannels()) {}
-
- ~LimitingAudioStream() {
- if (_disposeAfterUse == DisposeAfterUse::YES)
- delete _parentStream;
- }
-
- int readBuffer(int16 *buffer, const int numSamples) {
- // Cap us off so we don't read past _totalSamples
- int samplesRead = _parentStream->readBuffer(buffer, MIN<int>(numSamples, _totalSamples - _samplesRead));
- _samplesRead += samplesRead;
- return samplesRead;
- }
-
- bool endOfData() const { return _parentStream->endOfData() || _samplesRead >= _totalSamples; }
- bool isStereo() const { return _parentStream->isStereo(); }
- int getRate() const { return _parentStream->getRate(); }
-
-private:
- int getChannels() const { return isStereo() ? 2 : 1; }
-
- AudioStream *_parentStream;
- DisposeAfterUse::Flag _disposeAfterUse;
- uint32 _totalSamples, _samplesRead;
-};
-
-/**
* An AudioStream wrapper that forces audio to be played in mono.
* It currently just ignores the right channel if stereo.
*/
@@ -263,7 +228,7 @@ void QuickTimeAudioDecoder::QuickTimeAudioTrack::queueAudio(const Timestamp &len
_skipSamples = Timestamp();
}
- queueStream(new LimitingAudioStream(new SilentAudioStream(getRate(), isStereo()), editLength), editLength);
+ queueStream(makeLimitingAudioStream(new SilentAudioStream(getRate(), isStereo()), editLength), editLength);
_curEdit++;
enterNewEdit(nextEditTime);
} else {
@@ -289,7 +254,7 @@ void QuickTimeAudioDecoder::QuickTimeAudioTrack::queueAudio(const Timestamp &len
// we move on to the next edit
if (trackPosition >= nextEditTime || _curChunk >= _parentTrack->chunkCount) {
chunkLength = nextEditTime.convertToFramerate(getRate()) - getCurrentTrackTime();
- stream = new LimitingAudioStream(stream, chunkLength);
+ stream = makeLimitingAudioStream(stream, chunkLength);
_curEdit++;
enterNewEdit(nextEditTime);