void Syllable::SetPitchContour(vector<double> c) { pitchContour = c; onset->SetPitchContour(subVec(c, 0, onset->GetDuration()-1)); nuclei->SetPitchContour(subVec(c, onset->GetDuration(), onset->GetDuration()+nuclei->GetDuration()-1)); coda->SetPitchContour(subVec(c, onset->GetDuration()+nuclei->GetDuration(), this->GetDuration()-1)); }
void SRIStylizer::Stylize(Utterance* u) { DUMP(__PRETTY_FUNCTION__); vector<double> tmpPitchContour = u->GetPitchContour(); int pitchContourLength = tmpPitchContour.size(); vector<double> stylizedPitchContour = Vector_Zeros(pitchContourLength); vector<double> tmp_axe; for(int s=0; s<u->GetNumberOfSyllables(); s++) { if(u->GetSyllable(s)->GetPrevPause() != 0 || s==0) { // the region for stylization includes all the frames between two pauses int stylizeRegionBeginTime = u->GetSyllable(s)->GetNuclei()->GetBeginTime(); s++; while(s!=u->GetNumberOfSyllables() && u->GetSyllable(s)->GetPrevPause()==0) s++; s--; int stylizeRegionEndTime = u->GetSyllable(s)->GetNuclei()->GetEndTime(); vector<double> tmpStylizedPitchContour = PiecewiseLinearApprox(subVec(tmpPitchContour,stylizeRegionBeginTime,stylizeRegionEndTime-1)); if(!tmpStylizedPitchContour.empty()) { for(int i=0;i<stylizeRegionEndTime-stylizeRegionBeginTime;i++) stylizedPitchContour[stylizeRegionBeginTime+i]=tmpStylizedPitchContour[i]; } } } u->SetPitchContour(stylizedPitchContour); }
std::vector<ChebSegment> CFunctionToBspline::CFunctionToBsplineImpl::approxSegment(double umin, double umax, int depth) { // to estimate the error, we do a chebycheff approximation at higher // degree and evaluate the coefficients int K = _degree + 4; double alpha = 0.5; math_Vector cx = cheb_approx(_xfunc, K+1, umin, umax); math_Vector cy = cheb_approx(_yfunc, K+1, umin, umax); math_Vector cz = cheb_approx(_zfunc, K+1, umin, umax); // estimate error double errx=0., erry = 0., errz = 0.; for (int i = _degree+1; i < K+1; ++i) { errx += fabs(cx(i)); erry += fabs(cy(i)); errz += fabs(cz(i)); } double error = sqrt(errx*errx + erry*erry + errz*errz); if (error < _tol || depth >= _maxDepth) { // we can use this approximation, store to structure ChebSegment seg(_degree); seg.cx = subVec(cx, 0, _degree); seg.cy = subVec(cy, 0, _degree); seg.cz = subVec(cz, 0, _degree); seg.error = error; seg.umin = umin; seg.umax = umax; std::vector<ChebSegment> list; list.push_back(seg); return list; } else { // we have to split the range in two parts and do the approximation for each of them std::vector<ChebSegment> list1 = approxSegment(umin, umin + (umax-umin)*alpha, depth + 1); std::vector<ChebSegment> list2 = approxSegment(umin + (umax-umin)*alpha, umax, depth + 1); // combine lists list1.insert(list1.end(), list2.begin(), list2.end()); return list1; } }
std::vector<std::tm> TaskTokenizer::findAndRemoveDate(std::vector<std::string> &lineArr) { TaskTokenizer ct; std::vector<std::tm> output; try { for (size_t i = lineArr.size() - 1; i > 0; i--) { if (ParserLibrary::inStringArray(DEADLINE_INDICATOR, ParserLibrary::tolowercase(lineArr.at(i)))) { std::vector<std::string> subVec(lineArr.begin() + i + 1, lineArr.end()); std::tm time = DateTimeParser::toDateFormat(subVec); output.push_back(time); lineArr.erase(lineArr.begin() + i, lineArr.end()); return output; } else if (SCHEDULE_INDICATOR == ParserLibrary::tolowercase(lineArr.at(i))) { std::vector<std::string> subVec(lineArr.begin() + i + 1, lineArr.end()); for (size_t j = 0; j < subVec.size(); j++) { if (ParserLibrary::inStringArray(SCHEDULE_SEPARATOR, ParserLibrary::tolowercase(subVec.at(j)))) { std::vector<std::string> startDateArr(subVec.begin(), subVec.begin() + j); std::vector<std::string> endDateArr(subVec.begin() + j + 1, subVec.end()); std::tm startdate = DateTimeParser::toDateFormat(startDateArr); std::tm enddate = DateTimeParser::toDateFormat(endDateArr); output.push_back(startdate); output.push_back(enddate); lineArr.erase(lineArr.begin() + i, lineArr.end()); return output; } } } } } catch (std::invalid_argument e) { // do nothing } return output; }
// Create gibs (called each time an object is destroyed) // oa: array of objects to put gibs into // o: object to create gibs form // flags: state to begin gibs in void initGib(object *oa, object *o, int flags) { int i; for (i=0; i<o->size; i++) { object gib; vector *gv = (vector*)malloc(sizeof(vector)*2); gib.verts = gv; gv->x = o->verts[i].x; gv->y = o->verts[i].y; gv++; if (i==o->size-1) { gv->x = o->verts[0].x; gv->y = o->verts[0].y; } else { gv->x = o->verts[i+1].x; gv->y = o->verts[i+1].y; } vector mid = makeVec((gib.verts[0].x+gib.verts[1].x)/2.0, (gib.verts[0].y+gib.verts[1].y)/2.0); gib.pos = localToWorld(&mid, o); // vector dv = subVec(&(gib.pos), &(o->pos)); gib.verts[0] = subVec(&mid, &(gib.verts[0])); gib.verts[1] = subVec(&mid, &(gib.verts[1])); gib.size = 2; gib.dir = upVec(); gib.ang = o->ang; gib.turn = 1.0+0.5*cos((float)rand()); vector vel = makeVec(sin((float)rand()), cos((float)rand())); gib.vel = scaleVec(&vel, 0.2+cos(rand())); gib.spd = 2.0; gib.type = GIB; gib.mode = GL_LINES; gib.state = flags; gib.lifetime = 0.5; oa[i] = gib; } }
// Collisions void checkCollisions(void) { // Laser->asteroid collisions int li; for (li=0; li<MAXSHOTS; li++) { object *l = LAZORZ+li; // If shot is inactive, skip if (!(l->state & LAZER_ACTIVE)) continue; int a; // Else check all asteroids for a collision for (a = 0; a < MAXASTEROIDS; a++) { // Get distance vector from laser to asteroid centre vector dv = subVec(&(l->pos), &((asteroids+a)->pos)); if (asteroids[a].state & ASTEROID_ACTIVE // Asteroid active? && lengthVec(&dv) < asteroids[a].radius //Laser close enough? && pointPolygonCollide(asteroids+a, &(l->pos))) {//Collision? // Kill asteroid and deactivate laser shot initGib(asteroidGibs[a], asteroids+a, GIB_ACTIVE); killAsteroid(asteroids+a); l->state &= !LAZER_ACTIVE; break; } } } // // Missile->asteroid collisions // if (missile.state & MISSILE_ACTIVE) { // int si; // // Check eack vertex of the ship for a collision // for (si=0; si<missile.size; si++) { // int a; // // Get world coordinate of ship vertex // vector sv = localToWorld(missile.verts+si, &missile); // // Check all asteroids for collision // for (a = 0; a < MAXASTEROIDS; a++) { // // Skip if asteroid is not active (destroyed) // if (!(asteroids[a].state & ASTEROID_ACTIVE)) continue; // // Get distance vector // vector dv = subVec( &sv, &((asteroids+a)->pos)); // if (lengthVec(&dv) < asteroids[a].radius //Close enough? // && pointPolygonCollide(asteroids+a, &sv)) {//Collision? // // Kill asteroid and ship, display lose message // killAsteroid(asteroids+a); // // initGib(shipGibs, &ship, GIB_ACTIVE); // initGib(asteroidGibs[a], asteroids+a, GIB_ACTIVE); // // initMessage(); // missile.state &= !MISSILE_ACTIVE; // break; // } // } // } // } // Ship->asteroid collisions int si; object *ship; for ( si = 0; si < MAXSHIPS; si++ ) { ship = ships+si; if ( !(ship->state & ( SHIP_DED | SHIP_INACTIVE)) ) { int si; // Check eack vertex of the ship for a collision for (si=0; si<ship->size; si++) { int a; // Get world coordinate of ship vertex vector sv = localToWorld(ship->verts+si, ship); // Check all asteroids for collision for (a = 0; a < MAXASTEROIDS; a++) { // Skip if asteroid is not active (destroyed) if (!(asteroids[a].state & ASTEROID_ACTIVE)) continue; // Get distance vector vector dv = subVec( &sv, &((asteroids+a)->pos)); if (lengthVec(&dv) < asteroids[a].radius //Close enough? && pointPolygonCollide(asteroids+a, &sv)) {//Collision? // Kill asteroid and ship, display lose message killAsteroid(asteroids+a); initGib(shipGibs+si*ship->size, ship, GIB_ACTIVE); initGib(asteroidGibs[a], asteroids+a, GIB_ACTIVE); initMessage(); ship->state += SHIP_DED; break; } } } } } }
// both incoming files should be PAA'd already DTWData DTWaFile(std::string dataFile, std::string queryFile) { std::ifstream data(getPAAFilename(dataFile).c_str()); // bigger file std::ifstream query(getPAAFilename(queryFile).c_str()); // smaller file if (!data) { std::cout << "ERROR: ifstream failed on " << dataFile << ": " << strerror(errno) << std::endl; return DTWData(); } if (!query) { std::cout << "ERROR: ifstream failed on " << queryFile << ": " << strerror(errno) << std::endl; return DTWData(); } std::string dataTimePoints; std::string queryData; std::vector<double> dataVector; std::vector<double> queryVector; int curTimeSeries = -1; int bestMatchTimeSeries = 1; int bestMatchIdx = 1; int bestMatchBlkSz = 2; double bestMatchDistance = std::numeric_limits<double>::max(); // turn query into vector std::getline(query, queryData); std::size_t prev = 0, pos; while ((pos = queryData.find_first_of(" ,", prev)) != std::string::npos) { if (pos > prev) queryVector.push_back(stod(queryData.substr(prev, pos-prev))); prev = pos+1; } if (prev < queryData.length()) queryVector.push_back(stod(queryData.substr(prev, std::string::npos))); while (dataTimePoints.empty() && data.good()) std::getline(data, dataTimePoints); while (data.good()) { // get the next data timeseries curTimeSeries++; // split the timeseries numbers on space or comma std::size_t prev = 0, pos; while ((pos = dataTimePoints.find_first_of(" ,", prev)) != std::string::npos) { if (pos > prev) dataVector.push_back(stod(dataTimePoints.substr(prev, pos-prev))); prev = pos+1; } if (prev < dataTimePoints.length()) dataVector.push_back(stod(dataTimePoints.substr(prev, std::string::npos))); // run through all combinations from query for (int blkSz = 2; blkSz <= (int)dataVector.size(); blkSz++) { for (int startIdx = 0; startIdx+blkSz <= (int)dataVector.size(); startIdx++) { std::vector<double> subVec(dataVector.begin()+startIdx, dataVector.begin()+startIdx+blkSz); double newBest = std::min(simpleDTW(queryVector, subVec), bestMatchDistance); if (newBest != bestMatchDistance) { bestMatchDistance = newBest; bestMatchIdx = startIdx; bestMatchBlkSz = blkSz; bestMatchTimeSeries = curTimeSeries; } } } // get the next data timeseries dataVector.clear(); dataTimePoints = ""; while (dataTimePoints.empty() && data.good()) std::getline(data, dataTimePoints); } return DTWData(bestMatchDistance, bestMatchTimeSeries, bestMatchIdx, bestMatchBlkSz); }