Ejemplo n.º 1
0
int WaveFile_Open(WaveFile* This, String* Sorc)
{
    int OpenStatus = File_Open(WStream, Sorc, READONLY);
    if(! OpenStatus)
        return 0;

    char RIFFChars[5];
    char WAVEChars[5];
    char FACTChars[5];
    RIFFChars[4] = 0;
    WAVEChars[4] = 0;
    FACTChars[4] = 0;

    File_Read_Buffer(WStream, RIFFChars, 4); //RIFF
    File_Read_Int(WStream); //Size
    File_Read_Buffer(WStream, WAVEChars, 4); //WAVE

    if(strcmp(RIFFChars, "RIFF"))
        return 0;
    if(strcmp(WAVEChars, "WAVE"))
        return 0;

    File_Read_Int32(WStream); //fmt
    int fmtSize            = File_Read_Int32(WStream);
    File_Read_Int16(WStream); //FormatTag
    Header.Channel         = File_Read_Int16(WStream);
    Header.SamplePerSecond = File_Read_Int32(WStream);
    Header.BytePerSecond   = File_Read_Int32(WStream);
    Header.BlockAlign      = File_Read_Int16(WStream);
    Header.BitPerSample    = File_Read_Int16(WStream);

    if(fmtSize == 16)
    {
        //No extra info
    }else
        File_Read_Int16(WStream); //Extra info
    File_Read_Buffer(WStream, FACTChars, 4);

    if(! strcmp(FACTChars, "fact"))
    {
        int factSize = File_Read_Int32(WStream);
        File_SetPosition(WStream, File_GetPosition(WStream) + factSize + 4);
    }

    Header.DataSize = File_Read_Int32(WStream);
    Header.DataPosition = File_GetPosition(WStream);
    Header.BytePerSample = Header.BitPerSample / 8;
    Header.DataNum = Header.DataSize / Header.BytePerSample / Header.Channel;

    return 1;
}
Ejemplo n.º 2
0
int WaveFile_FetchAll(WaveFile* This, char* Dest)
{
    File_SetPosition(WStream, Header.DataPosition);
    File_Read_Buffer(WStream, Dest, Header.DataSize);
    return Header.DataSize;
}
Ejemplo n.º 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))