Fixed corner cases

Handling silences and last mouth shape
This commit is contained in:
Daniel Wolf 2015-12-01 22:28:29 +01:00
parent 7b282ce50f
commit e4b5b39504
2 changed files with 6 additions and 4 deletions

View File

@ -25,6 +25,7 @@ boost::bimap<string, Phone> phonesByName = makeBimap<string, Phone>({
}); });
Phone stringToPhone(const string& s) { Phone stringToPhone(const string& s) {
if (s == "SIL") return Phone::None;
auto it = phonesByName.left.find(s); auto it = phonesByName.left.find(s);
return (it != phonesByName.left.end()) ? it->second : Phone::Unknown; return (it != phonesByName.left.end()) ? it->second : Phone::Unknown;
} }

View File

@ -1,4 +1,5 @@
#include "mouth_animation.h" #include "mouth_animation.h"
#include <boost/utility.hpp>
using std::map; using std::map;
@ -69,10 +70,10 @@ Shape getShape(Phone phone) {
map<centiseconds, Shape> animate(const map<centiseconds, Phone> &phones) { map<centiseconds, Shape> animate(const map<centiseconds, Phone> &phones) {
map<centiseconds, Shape> shapes; map<centiseconds, Shape> shapes;
Shape lastShape = Shape::Invalid; Shape lastShape = Shape::Invalid;
for (auto& pair : phones) { for (auto it = phones.cbegin(); it != phones.cend(); it++) {
Shape shape = getShape(pair.second); Shape shape = getShape(it->second);
if (shape != lastShape) { if (shape != lastShape || next(it) == phones.cend()) {
shapes[pair.first] = shape; shapes[it->first] = shape;
lastShape = shape; lastShape = shape;
} }
} }