示例#1
0
static void print_probs(FILE *f, vp9_coeff_accum *context_counters,
                        int block_types, const char *header) {
  int type, ref, band, pt, t;

  fprintf(f, "static const vp9_coeff_probs %s = {", header);

  type = 0;
#define Newline(x, spaces) (x ? " " : "\n" spaces)
  do {
    fprintf(f, "%s%s{ /* block Type %d */",
            Comma(type), Newline(type, "  "), type);
    ref = 0;
    do {
      fprintf(f, "%s%s{ /* %s */",
              Comma(band), Newline(band, "    "), ref ? "Inter" : "Intra");
      band = 0;
      do {
        fprintf(f, "%s%s{ /* Coeff Band %d */",
                Comma(band), Newline(band, "      "), band);
        pt = 0;
        do {
          unsigned int branch_ct[ENTROPY_NODES][2];
          unsigned int coef_counts[MAX_ENTROPY_TOKENS + 1];
          vp9_prob coef_probs[ENTROPY_NODES];

          if (pt >= 3 && band == 0)
            break;
          for (t = 0; t < MAX_ENTROPY_TOKENS + 1; ++t)
            coef_counts[t] = context_counters[type][ref][band][pt][t];
          vp9_tree_probs_from_distribution(vp9_coef_tree, coef_probs,
                                           branch_ct, coef_counts, 0);
          branch_ct[0][1] = coef_counts[MAX_ENTROPY_TOKENS] - branch_ct[0][0];
          coef_probs[0] = get_binary_prob(branch_ct[0][0], branch_ct[0][1]);
          fprintf(f, "%s\n      {", Comma(pt));

          t = 0;
          do {
            fprintf(f, "%s %3d", Comma(t), coef_probs[t]);
          } while (++t < ENTROPY_NODES);

          fprintf(f, " }");
        } while (++pt < PREV_COEF_CONTEXTS);
        fprintf(f, "\n      }");
      } while (++band < COEF_BANDS);
      fprintf(f, "\n    }");
    } while (++ref < REF_TYPES);
    fprintf(f, "\n  }");
  } while (++type < block_types);
  fprintf(f, "\n};\n");
}
示例#2
0
文件: json.cpp 项目: urdvr/vabamorf
void CJSONWriter::StringVal(const CFSAString &szStr) {
	Comma();
	m_Stream.WriteChar('\"');
	Text(szStr);
	m_Stream.WriteChar('\"');
	m_Comma[GetLevel()]=COMMA_VAL;
}
示例#3
0
文件: json.cpp 项目: urdvr/vabamorf
void CJSONWriter::FloatVal(double dFloat) {
	Comma();
	CFSAString szStr;
	szStr.Format("%f", dFloat);
	Text(szStr);
	m_Comma[GetLevel()]=COMMA_VAL;
}
示例#4
0
文件: json.cpp 项目: urdvr/vabamorf
void CJSONWriter::IntVal(INTPTR iInt) {
	Comma();
	CFSAString szStr;
	szStr.Format("%zd", iInt);
	Text(szStr);
	m_Comma[GetLevel()]=COMMA_VAL;
}
示例#5
0
static void print_counter(FILE *f, vp9_coeff_accum *context_counters,
                          int block_types, const char *header) {
  int type, ref, band, pt, t;

  fprintf(f, "static const vp9_coeff_count %s = {\n", header);

#define Comma(X) (X ? "," : "")
  type = 0;
  do {
    ref = 0;
    fprintf(f, "%s\n  { /* block Type %d */", Comma(type), type);
    do {
      fprintf(f, "%s\n    { /* %s */", Comma(type), ref ? "Inter" : "Intra");
      band = 0;
      do {
        fprintf(f, "%s\n      { /* Coeff Band %d */", Comma(band), band);
        pt = 0;
        do {
          fprintf(f, "%s\n        {", Comma(pt));

          t = 0;
          do {
            const int64_t x = context_counters[type][ref][band][pt][t];
            const int y = (int) x;

            assert(x == (int64_t) y);  /* no overflow handling yet */
            fprintf(f, "%s %d", Comma(t), y);
          } while (++t < 1 + MAX_ENTROPY_TOKENS);
          fprintf(f, "}");
        } while (++pt < PREV_COEF_CONTEXTS);
        fprintf(f, "\n      }");
      } while (++band < COEF_BANDS);
      fprintf(f, "\n    }");
    } while (++ref < REF_TYPES);
    fprintf(f, "\n  }");
  } while (++type < block_types);
  fprintf(f, "\n};\n");
}
示例#6
0
文件: main.cpp 项目: rousse/vle
static int manage_config_mode(const std::string &configvar, const CmdArgs &args)
{
    int ret = EXIT_SUCCESS;

    try {
        vle::utils::Preferences prefs("vle.conf");

        std::string concat = std::accumulate(args.begin(), args.end(),
                std::string(), Comma());

        if (not prefs.set(configvar, concat))
            throw vle::utils::ArgError(vle::fmt(_("Unknown variable `%1%'")) %
                    configvar);

    } catch (const std::exception &e) {
        std::cerr << vle::fmt(_("Config error: %1%\n")) % e.what();
        ret = EXIT_FAILURE;
    }

    return ret;
}
void print_context_counters()
{

    int type, band, pt, t;

    FILE *const f = fopen("context.c", "w");

    fprintf(f, "#include \"entropy.h\"\n");

    fprintf(f, "\n/* *** GENERATED FILE: DO NOT EDIT *** */\n\n");

    fprintf(f, "int Contexts[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens];\n\n");

    fprintf(f, "const int default_contexts[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens] = {");

# define Comma( X) (X? ",":"")

    type = 0;

    do
    {
        fprintf(f, "%s\n  { /* block Type %d */", Comma(type), type);

        band = 0;

        do
        {
            fprintf(f, "%s\n    { /* Coeff Band %d */", Comma(band), band);

            pt = 0;

            do
            {
                fprintf(f, "%s\n      {", Comma(pt));

                t = 0;

                do
                {
                    const _int64 x = context_counters [type] [band] [pt] [t];
                    const int y = (int) x;

                    assert(x == (_int64) y);  /* no overflow handling yet */
                    fprintf(f, "%s %d", Comma(t), y);

                }
                while (++t < vp8_coef_tokens);

                fprintf(f, "}");
            }
            while (++pt < PREV_COEF_CONTEXTS);

            fprintf(f, "\n    }");

        }
        while (++band < COEF_BANDS);

        fprintf(f, "\n  }");
    }
    while (++type < BLOCK_TYPES);

    fprintf(f, "\n};\n");
    fclose(f);
}
示例#8
0
void LL1Parser::buildRuleTable()
{
	Token DS("$", TokenType::UNDEFINED);
	Token F_D("FUNCTION_DEFINITION", TokenType::UNDEFINED);
	_ruleStack.push(DS);
	_ruleStack.push(F_D);


	list<Token> FUNC;
	list<Token> DDL;
	list<Token> DD;
	list<Token> IDlist;
	//list<Token> ID2;
	list<Token> Lambda;
	list<Token> SEMICOLON;

	/*
	list<Token> SCircle;
	list<Token> SPixel;
	list<Token> SRect;
	list<Token> SDefine;
	list<Token> SID;
	list<Token> SDsign;
	list<Token> SEnd;
	list<Token> Empty;
	*/
	//might somehow need a rule for lambda, not exactly sure how that would be done

	/*
	Token Func("FUNCTION_DEFINITION", TokenType::UNDEFINED);
	Token Line("Line", TokenType::UNDEFINED);
	Token Circle("Circle", TokenType::UNDEFINED);
	Token Pixel("Pixel", TokenType::UNDEFINED);
	Token Rect("Rect", TokenType::UNDEFINED);
	Token Define("Define", TokenType::UNDEFINED);
	Token End("end", TokenType::UNDEFINED);
	Token Dsign("$", TokenType::UNDEFINED);
	*/

	Token Space(" ", TokenType::UNDEFINED);
	

	Token ID("ID", TokenType::VARIABLE);
	Token OpenParen("(", TokenType::UNDEFINED);
	Token ClosedParen(")", TokenType::UNDEFINED);
	Token Func_Args("FUNC_ARGS", TokenType::UNDEFINED);
	Token OpenBracket("{", TokenType::UNDEFINED);
	Token DataDefinitionList("DATA_DEFINITION_LIST", TokenType::UNDEFINED);
	Token ClosedBracket("}", TokenType::UNDEFINED);

	Token IdentifierList("IDENTIFIER_LIST", TokenType::UNDEFINED);

	Token Int("int", TokenType::UNDEFINED);
	Token DataDefinition("DATA_DEFINITION", TokenType::VARIABLE);

	Token Semicolon(";", TokenType::UNDEFINED);

	//Token id2("ID2", TokenType::UNDEFINED);

	Token Comma(",", TokenType::UNDEFINED);

	FUNC.push_back(Int);
	FUNC.push_back(ID);						//FUNCTION_DEFINITION => 'int' IDENTIFIER '(' IDENTIFIER ')' '{' DATA_DEFINITION_LIST '}
	FUNC.push_back(OpenParen);
	FUNC.push_back(ID);
	FUNC.push_back(ClosedParen);
	FUNC.push_back(OpenBracket);
	FUNC.push_back(DataDefinitionList);
	FUNC.push_back(ClosedBracket);

	DDL.push_back(Int); 					//DATA_DEFINITION_LIST => ‘int’ DATA_DEFINITION DATA_DEFINITION_LIST | lambda
	DDL.push_back(DataDefinition);
	DDL.push_back(DataDefinitionList);

	DD.push_back(ID);						//DATA_DEFINITION => IDENTIFIER IDENTIFIER_LIST ';' 
	DD.push_back(IdentifierList);
	DD.push_back(Semicolon);

	IDlist.push_back(Comma); 				//IDENTIFIER_LIST => , IDENTIFIER IDENTIFIER_LIST | lambda
	IDlist.push_back(ID);
	IDlist.push_back(IdentifierList);

	//ID2.push_back(Comma);					
	//ID2.push_back(IdentifierList);

	Lambda.push_back(Space);

	SEMICOLON.push_back(Semicolon);
	//SDsign.push_back(Dsign);

	//SEnd.push_back(Space);

	AddRule("FUNCTION_DEFINITION", "int", FUNC);
	AddRule("DATA_DEFINITION_LIST", "int", DDL);
	AddRule("DATA_DEFINITION_LIST", "}", Lambda);
	AddRule("DATA_DEFINITION_LIST", ";", SEMICOLON);
	AddRule("DATA_DEFINITION", "ID", DD);
	AddRule("IDENTIFIER_LIST", ",", IDlist);
	AddRule("IDENTIFIER_LIST", ";", Lambda);
	//AddRule("ID2", ",", ID2);
	//AddRule("ID2", ";", SPACE);
	//AddRule("S", "$", SDsign);
	//AddRule("S", "end", SEnd);
}
示例#9
0
文件: mcdr.cpp 项目: msdsgn/mcdr
/* ======================================================================= */
BOOL EncodeTrack(PWINDOWHANDLES H, DWORD Index, PCHAR BasePath, HANDLE CDHandle, PCDTRACK CDTrackData, PDWORD DiscCurrent, PDWORD DiscTotal, PDWORD TrackCount)
{
  Log(LOG_WRITE, "Encoding track %u/%u; Sector %u-%u/%u", Index+1, *TrackCount, CDTrackData[Index].Address, CDTrackData[Index].Address + CDTrackData[Index].Length - 1, CDTrackData[Index].Length);

  CHAR MP3FilePath[MAX_PATH];
  CHAR MP3FilePathFancy[MAX_PATH];

  HANDLE MP3FileHandle = INVALID_HANDLE_VALUE;
  static lame_global_flags *GFP = NULL;

  if(OneTrackOnly == 0)
  {
    _snprintf(MP3FilePath, MAX_PATH, "%s\\Track %u.mp3", BasePath, Index + 1);
    MakeFancyPath(MP3FilePath, MP3FilePathFancy, 35);
    SetLabel(H->WT, "Creating file %s...", MP3FilePath);
    MP3FileHandle = CreateFile(MP3FilePath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  }
  else
  {
    _snprintf(MP3FilePath, MAX_PATH, "%s\\Audio.mp3", BasePath, Index + 1);
    MakeFancyPath(MP3FilePath, MP3FilePathFancy, 35);
    switch(OneTrackOnly)
    {
      case 1:
        SetLabel(H->WT, "Creating solid file %s...", MP3FilePath);
        MP3FileHandle = CreateFile(MP3FilePath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
        OneTrackOnly = 2;
        break;
      case 2:
        SetLabel(H->WT, "Re-opening file %s...", MP3FilePath);
        MP3FileHandle = CreateFile(MP3FilePath, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
        if(MP3FileHandle != INVALID_HANDLE_VALUE)
          SetFilePointer(MP3FileHandle, 0, NULL, FILE_END);
        break;
    }
  }

  BOOL Success = TRUE;
  INT EncoderReturnCode = 0;

  if(MP3FileHandle != INVALID_HANDLE_VALUE)
  {
    Log(LOG_WRITE, "Created file %s", MP3FilePath);

    DWORD DiscLastCurrent = *DiscCurrent;
    DWORD SectorTotal = CDTrackData[Index].Length/SECTORS_AT_READ;
    DWORD MP3BytesWritten;

    SendMessage(H->PO, PBM_SETRANGE32, 0, SectorTotal);
    SendMessage(H->PO, PBM_SETPOS, 0, 0);
    SendMessage(H->PA, PBM_SETRANGE32, 0, *DiscTotal);

    if(GFP == NULL)
    {
      GFP = lame_init();

      lame_set_preset(GFP, MP3Quality);
      lame_set_copyright(GFP, 1);
      lame_set_original(GFP, 1);
      lame_set_error_protection(GFP, 1);
      lame_set_extension(GFP, 1);
      lame_set_quality(GFP, Quality);

      EncoderReturnCode = lame_init_params(GFP);
    }

    if(EncoderReturnCode == 0)
    {
      DWORD dwWAVBufferSize=(1152 * lame_get_num_channels(GFP));
      DWORD dwMP3BufferSize=(DWORD)(1.25*(dwWAVBufferSize/lame_get_num_channels(GFP))+7200);
      PBYTE MP3Buffer = new BYTE[dwMP3BufferSize];
      PBYTE CDBuffer = new BYTE[SECTORS_AT_READ * RAW_SECTOR_SIZE];
      INT nOutputSamples;
      DWORD CDBytesWritten;
      RAW_READ_INFO Info;
      Info.TrackMode = CDDA;
      Info.SectorCount = SECTORS_AT_READ;
      DWORD SectorCurrent;
      TCHAR NumWritten[30];
      TCHAR NumWrittenKB[30];

      for(SectorCurrent = 0; SectorCurrent < SectorTotal; ++SectorCurrent, ++*DiscCurrent)
      {
        Info.DiskOffset.QuadPart = (CDTrackData[Index].Address + SectorCurrent*SECTORS_AT_READ) * CD_SECTOR_SIZE;
        MP3BytesWritten = SetFilePointer(MP3FileHandle, 0, NULL, FILE_CURRENT);
        Comma(MP3BytesWritten, NumWritten, sizeof(NumWritten));
        Comma(MP3BytesWritten / 1024, NumWrittenKB, sizeof(NumWrittenKB));
        SetLabel(H->WT, "Encoding track %u of %u and sector %u of %u\nTo %s\nWritten %s bytes (%s KB) to file", Index + 1, *TrackCount, SectorCurrent, SectorTotal - 1, MP3FilePathFancy, NumWritten, NumWrittenKB);
        if(DeviceIoControl(CDHandle, IOCTL_CDROM_RAW_READ, &Info, sizeof(Info), CDBuffer, SECTORS_AT_READ*RAW_SECTOR_SIZE, &CDBytesWritten, NULL) != 0)
        {
          if(EncodeAudioBuffer(CDBuffer, CDBytesWritten, dwWAVBufferSize, MP3FileHandle, MP3Buffer, GFP) == FALSE)
          {
            Log(LOG_WRITE, "Encoding of audio buffer failed");
            Success = FALSE;
            break;
          }
        }
        else
        {
          DWORD ErrorCode = GetLastError();
          if(ErrorCode == ERROR_INVALID_FUNCTION)
          {
            Log(LOG_WRITE, "Track %u is not a valid CDDA track", Index + 1);
            Success = FALSE;
            break;
          }
          else if(ErrorCode != ERROR_INVALID_PARAMETER)
          {
            Log(LOG_WRITE, "Error code %u reading track %u!", ErrorCode, Index + 1);
            Success = FALSE;
            break;
          }
        }
        SendMessage(H->PO, PBM_SETPOS, SectorCurrent, 0);
        SendMessage(H->PA, PBM_SETPOS, *DiscCurrent, 0);
        Percentage = (float)((float)*DiscCurrent / (float)*DiscTotal) * 100;
      }

      if(Success == FALSE)
      {
        *DiscTotal -= SectorTotal;
        SectorTotal = 0;
      }
      else if(OneTrackOnly == 0 || Index+1 == *TrackCount)
      {
        nOutputSamples = lame_encode_flush_nogap(GFP, MP3Buffer, LAME_MAXMP3BUFFER);

        if(nOutputSamples > 0)
        {
          if(WriteFile(MP3FileHandle, MP3Buffer, nOutputSamples, &MP3BytesWritten, NULL) == FALSE)
          {
            Log(LOG_WRITE, "Failed to write %u final bytes to file", nOutputSamples);
            Success = FALSE;
          }
          else if(nOutputSamples != (int)MP3BytesWritten)
          {
            Log(LOG_WRITE, "Written %u final bytes instead of %u bytes to file", MP3BytesWritten, nOutputSamples);
            Success = FALSE;
          }
        }
        else if(nOutputSamples < 0)
        {
          Log(LOG_WRITE, "Error code %d flushing encoded audio buffer", nOutputSamples);
          Success = FALSE;
        }
      }

      *DiscCurrent = DiscLastCurrent + SectorTotal;
      SendMessage(H->PO, PBM_SETPOS, *DiscCurrent, 0);
    }
    else
    {
      Log(LOG_WRITE, "Error code %d initialising audio encoder", EncoderReturnCode);
      Success = FALSE;
    }

    MP3BytesWritten = SetFilePointer(MP3FileHandle, 0, NULL, FILE_CURRENT);
    if(CloseHandle(MP3FileHandle) == FALSE)
    {
      Log(LOG_WRITE, "Error code %u closing file handle");
      Success = FALSE;
    }
    if(OneTrackOnly == 0 && (MP3BytesWritten == 0 || Success == FALSE))
    {
      if(DeleteFile(MP3FilePath) == FALSE)
        Log(LOG_WRITE, "Error code %u deleting file");
      else
        Log(LOG_WRITE, "Deleted the file due to error");
    }
    else Log(LOG_WRITE, "Written %u bytes to file", MP3BytesWritten);
  }
  else
  {
    Log(LOG_WRITE, "Error code %u creating %s", GetLastError(), MP3FilePath);
    Success = FALSE;
  }

  if(EncoderReturnCode == 0 && (OneTrackOnly == 0 || Index+1 == *TrackCount))
  {
    lame_close(GFP);
    GFP = NULL;
  }

  return Success;
}
示例#10
0
文件: json.cpp 项目: urdvr/vabamorf
void CJSONWriter::ArrayStart() {
	Comma();
	m_Comma[GetLevel()]=COMMA_VAL;
	Text("[");
	m_Comma.AddItem(COMMA_KEY);
}
示例#11
0
文件: json.cpp 项目: urdvr/vabamorf
void CJSONWriter::ObjectStart() {
	Comma();
	m_Comma[GetLevel()]=COMMA_VAL;
	Text("{");
	m_Comma.AddItem(COMMA_KEY);
}
示例#12
0
文件: json.cpp 项目: urdvr/vabamorf
void CJSONWriter::NullVal() {
	Comma();
	Text("null");
	m_Comma[GetLevel()]=COMMA_VAL;
}
示例#13
0
文件: json.cpp 项目: urdvr/vabamorf
void CJSONWriter::BoolVal(bool bBool) {
	Comma();
	Text(bBool ? "true" : "false");
	m_Comma[GetLevel()]=COMMA_VAL;
}
示例#14
0
文件: json.cpp 项目: urdvr/vabamorf
void CJSONWriter::Key(const CFSAString &szStr) {
	Comma();
	m_Stream.WriteChar('\"');
	Text(szStr);
	m_Stream.WriteText("\": ");
}