Fixed overflow with long audio files
This commit is contained in:
parent
c6c31a831c
commit
faa3f2b4bb
|
@ -2,10 +2,10 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
AudioStreamSegment::AudioStreamSegment(std::unique_ptr<AudioStream> audioStream, const TimeRange& range) :
|
AudioStreamSegment::AudioStreamSegment(std::unique_ptr<AudioStream> audioStream, const TimeRange& range) :
|
||||||
audioStream(std::move(audioStream))
|
audioStream(std::move(audioStream)),
|
||||||
|
sampleOffset(static_cast<int64_t>(range.getStart().count()) * this->audioStream->getSampleRate() / 100),
|
||||||
|
sampleCount(static_cast<int64_t>(range.getLength().count()) * this->audioStream->getSampleRate() / 100)
|
||||||
{
|
{
|
||||||
sampleOffset = range.getStart().count() * this->audioStream->getSampleRate() / 100;
|
|
||||||
sampleCount = range.getLength().count() * this->audioStream->getSampleRate() / 100;
|
|
||||||
seek(0);
|
seek(0);
|
||||||
|
|
||||||
if (sampleOffset < 0 || sampleOffset + sampleCount > this->audioStream->getSampleCount()) {
|
if (sampleOffset < 0 || sampleOffset + sampleCount > this->audioStream->getSampleCount()) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<AudioStream> audioStream;
|
std::unique_ptr<AudioStream> audioStream;
|
||||||
int64_t sampleOffset, sampleCount;
|
const int64_t sampleOffset, sampleCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<AudioStream> createSegment(std::unique_ptr<AudioStream> audioStream, const TimeRange& range);
|
std::unique_ptr<AudioStream> createSegment(std::unique_ptr<AudioStream> audioStream, const TimeRange& range);
|
||||||
|
|
Loading…
Reference in New Issue