Added convenience function Timed<T>.getDuration()

This commit is contained in:
Daniel Wolf 2016-09-29 12:02:00 +02:00
parent f5b7971f52
commit 1f6f6d6175
5 changed files with 16 additions and 8 deletions

View File

@ -37,6 +37,10 @@ public:
return timeRange.getEnd();
}
TimeRange::time_type getDuration() const {
return timeRange.getDuration();
}
void setTimeRange(const TimeRange& timeRange) {
this->timeRange = timeRange;
}
@ -104,6 +108,10 @@ public:
return timeRange.getEnd();
}
TimeRange::time_type getDuration() const {
return timeRange.getDuration();
}
void setTimeRange(const TimeRange& timeRange) {
this->timeRange = timeRange;
}

View File

@ -103,7 +103,7 @@ BoundedTimeline<void> detectVoiceActivity(const AudioClip& inputAudioClip, int m
// Shorten activities. WebRTC adds a bit of buffer at the end.
const centiseconds tail(5);
for (const auto& utterance : Timeline<void>(activity)) {
if (utterance.getTimeRange().getDuration() > tail && utterance.getEnd() < audioDuration) {
if (utterance.getDuration() > tail && utterance.getEnd() < audioDuration) {
activity.clear(utterance.getEnd() - tail, utterance.getEnd());
}
}

View File

@ -189,11 +189,11 @@ Timeline<Shape> animatePauses(const ContinuousTimeline<Shape>& shapes) {
for_each_adjacent(shapes.begin(), shapes.end(), [&](const Timed<Shape>& secondLast, const Timed<Shape>& last, const Timed<Shape>& pause) {
if (pause.getValue() != X) return;
centiseconds lastDuration = last.getTimeRange().getDuration();
centiseconds lastDuration = last.getDuration();
const centiseconds minOpenDuration = 20_cs;
if (isClosed(secondLast.getValue()) && !isClosed(last.getValue()) && lastDuration < minOpenDuration) {
const centiseconds minSpillDuration = 20_cs;
centiseconds spillDuration = std::min(minSpillDuration, pause.getTimeRange().getDuration());
centiseconds spillDuration = std::min(minSpillDuration, pause.getDuration());
result.set(pause.getStart(), pause.getStart() + spillDuration, B);
}
});
@ -214,7 +214,7 @@ ContinuousTimeline<Shape> animate(const BoundedTimeline<Phone> &phones) {
for (const auto& timedPhone : continuousPhones) {
// Animate one phone
optional<Phone> phone = timedPhone.getValue();
centiseconds duration = timedPhone.getTimeRange().getDuration();
centiseconds duration = timedPhone.getDuration();
Timeline<Viseme> phoneVisemes = animate(phone, duration, previousPhoneDuration);
// Result timing is relative to phone. Make absolute.
@ -236,7 +236,7 @@ ContinuousTimeline<Shape> animate(const BoundedTimeline<Phone> &phones) {
Viseme viseme = it->getValue();
// Convert viseme to phone
Shape shape = viseme.getShape(it->getTimeRange().getDuration(), lastShape);
Shape shape = viseme.getShape(it->getDuration(), lastShape);
shapes.set(it->getTimeRange(), shape);
lastShape = shape;

View File

@ -291,7 +291,7 @@ Timeline<void> getNoiseSounds(TimeRange utteranceTimeRange, const Timeline<Phone
const centiseconds minSoundDuration = 12_cs;
for (const auto& unknownSound : Timeline<void>(noiseSounds)) {
bool startsAtZero = unknownSound.getStart() == 0_cs;
bool tooShort = unknownSound.getTimeRange().getDuration() < minSoundDuration;
bool tooShort = unknownSound.getDuration() < minSoundDuration;
if (startsAtZero || tooShort) {
noiseSounds.clear(unknownSound.getTimeRange());
}
@ -428,7 +428,7 @@ BoundedTimeline<Phone> recognizePhones(
};
auto getUtteranceProgressWeight = [](const Timed<void> timedUtterance) {
return timedUtterance.getTimeRange().getDuration().count();
return timedUtterance.getDuration().count();
};
// Perform speech recognition

View File

@ -230,7 +230,7 @@ void testSetter(std::function<void(const Timed<int>&, Timeline<int>&)> set) {
Timed<int> lastElement(centiseconds::min(), centiseconds::min(), std::numeric_limits<int>::min());
for (const auto& element : timeline) {
// No element shound have zero-length
EXPECT_LT(0_cs, element.getTimeRange().getDuration());
EXPECT_LT(0_cs, element.getDuration());
// No two adjacent elements should have the same value; they should have been merged
if (element.getStart() == lastElement.getEnd()) {