Ejemplo n.º 1
0
/* MMDAgent_fgettoken: get token from file pointer */
int MMDAgent_fgettoken(FILE *fp, char *buff)
{
    int i;
    char c;

    c = fgetc(fp);
    if(c == EOF) {
        buff[0] = '\0';
        return 0;
    }

    if(c == '#') {
        for(c = fgetc(fp); c != EOF; c = fgetc(fp))
            if(c == '\n')
                return MMDAgent_fgettoken(fp, buff);
        buff[0] = '\0';
        return 0;
    }

    if(c == ' ' || c == '\t' || c == '\r' || c == '\n')
        return MMDAgent_fgettoken(fp, buff);

    buff[0] = c;
    for(i = 1, c = fgetc(fp); c != EOF && c != '#' && c != ' ' && c != '\t' && c != '\r' && c != '\n'; c = fgetc(fp))
        buff[i++] = c;
    buff[i] = '\0';

    if(c == '#')
        fseek(fp, -1, SEEK_CUR);
    if(c == EOF)
        fseek(fp, 0, SEEK_END);

    return i;
}
Ejemplo n.º 2
0
/* Audio_Thread::startLipsync: start lipsync if HTK label file is existing */
bool Audio_Thread::startLipsync(const char *file)
{
   bool result = false;
   int i;
   char *label;
   size_t len;
   FILE *fp;
   char buff[MMDAGENT_MAXBUFLEN];
   char message[MMDAGENT_MAXBUFLEN];
   int startLen, startTime, endLen, endTime, phonemeLen;
   bool first = true;
   PMDObject *objs;

   len = MMDAgent_strlen(file);
   if(len > 4) {
      label = MMDAgent_strdup(file);
      label[len - 4] = '.';
      label[len - 3] = 'l';
      label[len - 2] = 'a';
      label[len - 1] = 'b';
      fp = MMDAgent_fopen(label, "r");
      if(fp != NULL) {
         /* load HTK label */
         strcpy(message, "");
         while(1) {
            startLen = MMDAgent_fgettoken(fp, buff);
            startTime = MMDAgent_str2int(buff);
            endLen = MMDAgent_fgettoken(fp, buff);
            endTime = MMDAgent_str2int(buff);
            phonemeLen = MMDAgent_fgettoken(fp, buff);
            if(startLen > 0 && endLen > 0 && phonemeLen > 0 && startTime < endTime) {
               if(first)
                  sprintf(message, "%s,%d", buff, (int) ((double) (endTime - startTime) * 1.0E-04 + 0.5));
               else
                  sprintf(message, "%s,%s,%d", message, buff, (int) ((double) (endTime - startTime) * 1.0E-04 + 0.5));
               first = false;
            } else {
               break;
            }
         }
         fclose(fp);
         /* send lipsync message */
         if(first == false) {
            objs = m_mmdagent->getModelList();
            for (i = 0; i < m_mmdagent->getNumModel(); i++) {
               if (objs[i].isEnable() == true && objs[i].allowMotionFileDrop() == true) {
                  m_mmdagent->sendMessage(MMDAGENT_COMMAND_LIPSYNCSTART, "%s|%s", objs[i].getAlias(), message);
                  result = true;
               }
            }
         }
      }
      free(label);
   }

   return result;
}
Ejemplo n.º 3
0
/* LipSync::load: initialize and load lip setting */
bool LipSync::load(const char *file)
{
   int i, j;
   FILE *fp;
   int len;
   char buff[LIPSYNC_MAXBUFLEN];
   bool err = false;

   fp = MMDAgent_fopen(file, "r");
   if(fp == NULL)
      return false;

   /* number of expression */
   len = MMDAgent_fgettoken(fp, buff);
   if(len <= 0) {
      fclose(fp);
      return false;
   }
   m_numMotion = MMDAgent_str2int(buff);
   if(m_numMotion <= 0) {
      fclose(fp);
      clear();
      return false;
   }

   /* motion name */
   m_motion = (char **) malloc(sizeof(char *) * m_numMotion);
   for(i = 0; i < m_numMotion; i++) {
      len = MMDAgent_fgettoken(fp, buff);
      if(len <= 0) err = true;
      m_motion[i] = MMDAgent_strdup(buff);
   }
   if(err == true) {
      fclose(fp);
      clear();
      return false;
   }

   /* number of phone */
   len = MMDAgent_fgettoken(fp, buff);
   if(len <= 0) {
      fclose(fp);
      clear();
      return false;
   }
   m_numPhone = MMDAgent_str2int(buff);
   if(m_numPhone <= 0) {
      fclose(fp);
      clear();
      return false;
   }

   /* phone name, type, and blend rate */
   m_phone = (char **) malloc(sizeof(char *) * m_numPhone);
   m_blendRate = (float **) malloc(sizeof(float *) * m_numPhone);
   for(i = 0; i < m_numPhone; i++) {
      len = MMDAgent_fgettoken(fp, buff);
      if(len <= 0) err = true;
      m_phone[i] = MMDAgent_strdup(buff);
      m_blendRate[i] = (float *) malloc(sizeof(float) * m_numMotion);
      for(j = 0; j < m_numMotion; j++) {
         len = MMDAgent_fgettoken(fp, buff);
         if(len <= 0) err = true;
         m_blendRate[i][j] = MMDAgent_str2float(buff);
         if(m_blendRate[i][j] < 0.0f) err = true;
      }
   }
   if(err == true) {
      fclose(fp);
      clear();
      return false;
   }

   fclose(fp);
   return true;
}