Пример #1
0
bool File::read()
{
  if (!m_Stream.good())
    return false;

  if (m_Stream.tellg() > 0)
    m_Stream.seekg(0);

  //read header data
  if (!readHeader())
  {
    return false;
  }

  //read directory tree (old format)
  if (!readDirectoryTree())
    return false;

  //read hint lines (old format)
  if (!readHintLines())
    return false;

  //read chunks
  return readChunkData();
}
Пример #2
0
AudioPacket* WavFileConfig::parse(FileHandle handle)
{
	UInt32 chunkSize, chunkPos;
	UInt32 filetype;
	findChunk(handle, fourccRIFF, chunkSize, chunkPos);
	readRIFFHeader(handle, &filetype, chunkPos);
	AerAssert(filetype == fourccWAVE);

	AudioFormat format;
	findChunk(handle, fourccFMT, chunkSize, chunkPos);
	readAudioFormat(handle, &format, chunkPos);

	// fill out the audio data buffer with the contents of the fourData chunk
	AudioPacket* pack = new AudioPacket();
	pack->format = format;
	AudioData* data = &pack->data;
	findChunk(handle, fourccDATA, chunkSize, chunkPos);
	data->audioData = new Byte[chunkSize];
	readChunkData(handle, data->audioData, chunkSize, chunkPos);
	data->audioDataSize = chunkSize;

	return pack;
}
Пример #3
0
WavReader::SoundData * WavReader::loadInternal(const char * filename)
{
    IW_CALLSTACK("WavReader::load");

	this->filename = filename;

    SoundData * data = NULL; // Object to return

    // Open file
    s3eFile* pFile = IwFileOpenPrefixed(filename, "rb");
    IwAssertMsg(SOUND, pFile, ("Could not load file %s", filename));
    if (!pFile)
        return NULL;

    // Read RIFF header - Gives the file size and checks that this is a WAVE
    // file as expected
    RIFFHeader riffHeader;
    if ((s3eFileRead(&riffHeader, sizeof(RIFFHeader), 1, pFile) != 1)
        || (strncmp(riffHeader.typeID, "RIFF", 4) != 0)
        || (strncmp(riffHeader.subTypeID, "WAVE", 4) != 0))
    {
        IwAssertMsg(SOUND, false, ("Invalid header in %s (RIFF Header)", filename));
        s3eFileClose(pFile);
        return NULL;
    }

    // Read in RIFF chunks until we reach the end of the file
    // Read the RIFF chunk header. This tells us what type of chunk follows.
    RIFFChunkHeader chunkHeader;
    bool readData = false;
    uint32 fileSize = s3eFileGetSize(pFile);

    while (readChunkHeader(chunkHeader, *(s3eFile*)pFile))
    {
        uint32 chunkStartPos = s3eFileTell(pFile);

        // Next action depends on chunk type. The order of this is important and we may fail
        // if an unexpected chunk type is found
        if (!strncmp(chunkHeader.typeID, "fmt ", 4))
        {
            // Read WAVE info chunk
            if (!readChunkFormat(chunkHeader, data, *(s3eFile*)pFile))
            {
                s3eFileClose(pFile);
                return NULL;
            }
        }
        else if (!strncmp(chunkHeader.typeID, "data", 4))
        {
            if (!readChunkData(chunkHeader, data, *(s3eFile*)pFile))
            {
                s3eFileClose(pFile);
                return NULL;
            }
            readData = true;
        }
        else if (!strncmp(chunkHeader.typeID, "fact", 4))
        {
            if (!readChunkFact(chunkHeader, data, *(s3eFile*)pFile))
            {
                s3eFileClose(pFile);
                return NULL;
            }
        }
        else
        {
            // Unknown chunk type
            // Make a proper string from the chunk type info
            char typeID[5];
            strncpy(typeID, chunkHeader.typeID, 4);
            typeID[4] = 0;  // Terminate

            const char* g_IgnoreTypes = "LIST" //LIST is just copyright info etc.
                "DISP";  //DISP seems to be info about what package exported it

            IwAssertMsg(SOUND, strstr(g_IgnoreTypes, typeID), ("Unhandled chunk type '%s' in %s. Ignoring this data.", typeID, filename));
        }

        // Exit if at end of file
        if (chunkStartPos + chunkHeader.length >= fileSize)
            break;

        // Move to next chunk
        s3eFileSeek(pFile, chunkStartPos + chunkHeader.length, S3E_FILESEEK_SET);
    }

    // Check that we have read the sample data
    IwAssertMsg(SOUND, readData, ("No data chunk read in %s", filename));
    s3eFileClose(pFile);
    return data;
}