本文整理汇总了C++中SoundData::SetSoundDataOffset方法的典型用法代码示例。如果您正苦于以下问题:C++ SoundData::SetSoundDataOffset方法的具体用法?C++ SoundData::SetSoundDataOffset怎么用?C++ SoundData::SetSoundDataOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SoundData
的用法示例。
在下文中一共展示了SoundData::SetSoundDataOffset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Read
SoundData* WavReader::Read(const String& pFileName)
{
SoundData* newSoundData = GD_NEW(SoundData, this, "SoundData");
newSoundData->SetFileName(pFileName);
Char identifier[5];
identifier[4] = '\0';
// Open the file stream.
std::ifstream fileStream(pFileName.c_str(), std::ios::in | std::ios::binary);
// Read "RIFF"
fileStream.read(identifier, 4);
if(strcmp(identifier, "RIFF") != 0)
throw ResourceImportException( String("The wav file should start with RIFF"), Here );
// Read the total length (filesize - 8).
Int32 fileDataSize;
fileStream.read((Char*)(&fileDataSize), 4);
fileDataSize += 8;
newSoundData->SetFileDataSize(fileDataSize);
// Read "WAVE".
fileStream.read(identifier, 4);
if(strcmp(identifier, "WAVE") != 0)
throw ResourceImportException( String("The wav file should contain the WAVE identifier."), Here );
// Read "fmt_"
fileStream.read(identifier, 4);
if(strcmp(identifier, "fmt ") != 0)
throw ResourceImportException( String("The wav file should contain the fmt_ identifier."), Here );
// Read the Length of the format chunk.
Int32 chunkFileSize;
fileStream.read((Char*)(&chunkFileSize), 4);
// Read a drummy short.
Int16 dummyShort;
fileStream.read((Char*)(&dummyShort), 2);
// Read the number of channels.
Int16 nbChannels;
fileStream.read((Char*)(&nbChannels), 2);
newSoundData->SetNbChannels(nbChannels);
// Read the sample rate.
Int32 sampleRate;
fileStream.read((Char*)(&sampleRate), 4);
newSoundData->SetSampleRate(sampleRate);
// Read the bytes per second.
Int32 bytesPerSecond;
fileStream.read((Char*)(&bytesPerSecond), 4);
newSoundData->SetBytesPerSecond(bytesPerSecond);
// Read the bytes per sample.
Int16 bytesPerSample;
fileStream.read((Char*)(&bytesPerSample), 2);
newSoundData->SetBytesPerSample(bytesPerSample);
// Read the bits per sample.
Int16 bitsPerSample;
fileStream.read((Char*)(&bitsPerSample), 2);
newSoundData->SetBitsPerSample(bitsPerSample);
// Read "data"
fileStream.read(identifier, 4);
if(strcmp(identifier, "data") != 0)
throw ResourceImportException( String("The wav file should contain the data identifier."), Here );
// Read the size of sound data.
Int32 soundDataSize;
fileStream.read((Char*)(&soundDataSize), 4);
newSoundData->SetSoundDataSize(soundDataSize);
newSoundData->SetSoundDataOffset(44);
// Read the data itself.
fileStream.seekg(0, std::ios::beg);
Char* data = GD_NEW_ARRAY(Char, fileDataSize + 1, this, "Data");
data[fileDataSize] = '\0';
fileStream.read(data, fileDataSize);
newSoundData->SetFileData(data);
fileStream.close();
return newSoundData;
}