Beispiel #1
0
static int CRC32_Str_Compare(const char* Sorc, UInt Correct)
{
    UInt CRC = CRC32Sum(Sorc, strlen(Sorc), 0);
    if(CRC != Correct)
    {
        fprintf(stderr, "[Error] CRC32 worked out a wrong result: %08x\n"
                        "Correct is %08x.\n", CRC, Correct);
        return 0;
    }
    return 1;
}
Beispiel #2
0
static float __CRC32_SpeedTest_Core__(UInt TestCount, UInt TestSize)
{
    if(TestSize % 4)
    {
        fprintf(stderr, "[Error] TestSize must be muiltipie of 4!\n");
        return -1.0f;
    }
    
    struct timeval bgn, end;
    
    char** Data = RAlign(8, sizeof(char**) * TestCount);
    for(int i = 0; i < TestCount; ++ i)
    {
        Data[i] = RAlign(8, TestSize);
        for(int j = 0; j < TestSize; ++ j)
        {
            gettimeofday(& bgn, NULL);
            srand(bgn.tv_usec);
            Data[i][j] = (int)rand();
        }
    }
    
    gettimeofday(& bgn, NULL);
    
    for(int i = 0; i < TestCount; ++ i)
        CRC32Sum(Data[i], TestSize, 0);
    
    gettimeofday(& end, NULL);
    
    for(int i = 0; i < TestCount; ++ i)
        free(Data[i]);
    free(Data);
    
    float t = ((float)(end.tv_usec - bgn.tv_usec)) / 1000000.0f;
    
    printf("    SpeedTest Nr = %d, Time = %f.\n", ++ SPTNr, t);
    
    return t;
}
Beispiel #3
0
int RUCE_RUDB_Load(RUCE_DB_Entry* Dest, String* Path)
{
    File Sorc;
    File_Ctor(& Sorc);
    if(! File_Open(& Sorc, Path, READONLY))
        return -1;
    
    int ReverseEndian = 0;
    
    int64_t FLen = File_GetLength(& Sorc);
    if(FLen < 48)
        return -1;
    char CBuffer[8];
    uint32_t Header[4];
    uint64_t DataSize;
    File_Read_Buffer(& Sorc, Header, 12);
    if(Header[0] != RUDB_Header)
    {
        Endian_Switch_Array_UInt32(Header, 4);
        ReverseEndian = 1;
    }
    if(Header[0] != RUDB_Header)
        return -2;
    if(Header[2] > RUDB_VERSION)
        return -3;
    File_Read_Buffer(& Sorc, CBuffer, 4);
    if(strncmp(CBuffer, "DATA", 4))
        return -4;
    
    File_Read_Buffer(& Sorc, & DataSize, 8);
    
    if(DataSize < 8)
        return -5;
    
    char* Data = malloc(DataSize);
    File_Read_Buffer(& Sorc, Data, DataSize);
    
    if(Header[1] != CRC32Sum(Data, DataSize, 0))
        return -6;
    
    memcpy(& (Dest -> HopSize), Data, 8);
    Data += 8;
    if(ReverseEndian)
        Endian_Switch_Array_Int32(& (Dest -> HopSize), 2);
    
    while(Data != Data + DataSize)
    {
        if(! strncmp(Data, "FRME", 4))
        {
            Data += 4;
            memcpy(Header, Data, 4);
            Data += 4;
            if(ReverseEndian)
                Endian_Switch_UInt32(Header);
            int OldSize = Dest -> FrameList_Index + 1;
            Array_Resize(RUCE_DB_Frame, 
                         Dest -> FrameList, 
                         OldSize + Header[0]);
            for(int i = 0 + OldSize; i < Header[0] + OldSize; ++i)
            {
                RUCE_DB_Frame_Ctor(& (Dest -> FrameList[i]));
                if(strncmp(Data, "FRMB", 4))
                    return -255;
                Data += 4;
                memcpy(& (Dest -> FrameList[i].Position), Data, 4);
                Data += 4;
                int Cnt;
                memcpy(& Cnt, Data, 4);
                Data += 4;
                if(ReverseEndian)
                {
                    Endian_Switch_Int32(& (Dest -> FrameList[i].Position));
                    Endian_Switch_Int32(& Cnt);
                }
                Array_Resize(float, Dest -> FrameList[i].Freq, Cnt);
                Array_Resize(float, Dest -> FrameList[i].Ampl, Cnt);
                Array_Resize(float, Dest -> FrameList[i].Phse, Cnt);
                Dest -> FrameList[i].Freq_Index = Cnt - 1;
                Dest -> FrameList[i].Ampl_Index = Cnt - 1;
                Dest -> FrameList[i].Phse_Index = Cnt - 1;
                if(Dest -> FrameList[i].Noiz)
                    free(Dest -> FrameList[i].Noiz);
                Dest -> FrameList[i].Noiz = RAlloc_Float(Dest -> NoizSize);
                memcpy(Dest -> FrameList[i].Freq, Data, Cnt * 4);
                Data += Cnt * 4;
                memcpy(Dest -> FrameList[i].Ampl, Data, Cnt * 4);
                Data += Cnt * 4;
                memcpy(Dest -> FrameList[i].Phse, Data, Cnt * 4);
                Data += Cnt * 4;
                memcpy(Dest -> FrameList[i].Noiz, Data, Dest -> NoizSize * 4);
                Data += Dest -> NoizSize * 4;
                if(ReverseEndian)
                {
                    Endian_Switch_Array_Float(Dest -> FrameList[i].Freq, Cnt);
                    Endian_Switch_Array_Float(Dest -> FrameList[i].Ampl, Cnt);
                    Endian_Switch_Array_Float(Dest -> FrameList[i].Phse, Cnt);
                    Endian_Switch_Array_Float(Dest -> FrameList[i].Noiz, 
                                              Dest -> NoizSize);
                }
            }
        }
        else if(! strncmp(Data, "PULS", 4))