Better animation of pauses in speech

This commit is contained in:
Daniel Wolf
2016-08-05 19:34:57 +02:00
parent 1c50ece142
commit c65c8b4eb3
3 changed files with 88 additions and 1 deletions

View File

@@ -164,6 +164,36 @@ Timeline<Shape> createTweens(ContinuousTimeline<Shape> shapes) {
return tweens;
}
Timeline<Shape> animatePauses(const ContinuousTimeline<Shape>& shapes) {
Timeline<Shape> result;
// Don't close mouth for short pauses
for (const auto& timedShape : shapes) {
if (timedShape.getValue() != X) continue;
const centiseconds maxPausedOpenMouthDuration = 35cs;
const TimeRange timeRange = timedShape.getTimeRange();
if (timeRange.getLength() <= maxPausedOpenMouthDuration) {
result.set(timeRange, B);
}
}
// Keep mouth open into pause if it just opened
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 lastLength = last.getTimeRange().getLength();
const centiseconds minOpenDuration = 20cs;
if (isClosed(secondLast.getValue()) && !isClosed(last.getValue()) && lastLength < minOpenDuration) {
const centiseconds minSpillDuration = 20cs;
centiseconds spillDuration = std::min(minSpillDuration, pause.getTimeRange().getLength());
result.set(pause.getStart(), pause.getStart() + spillDuration, B);
}
});
return result;
}
ContinuousTimeline<Shape> animate(const BoundedTimeline<Phone> &phones) {
// Convert phones to continuous timeline so that silences aren't skipped when iterating
ContinuousTimeline<optional<Phone>> continuousPhones(phones.getRange(), boost::none);
@@ -204,6 +234,12 @@ ContinuousTimeline<Shape> animate(const BoundedTimeline<Phone> &phones) {
shapes.set(it->getTimeRange(), shape);
}
// Animate pauses
Timeline<Shape> pauses = animatePauses(shapes);
for (const auto& pause : pauses) {
shapes.set(pause);
}
// Create inbetweens for smoother animation
Timeline<Shape> tweens = createTweens(shapes);
for (const auto& tween : tweens) {