本文整理汇总了C++中FileReader::Rewind方法的典型用法代码示例。如果您正苦于以下问题:C++ FileReader::Rewind方法的具体用法?C++ FileReader::Rewind怎么用?C++ FileReader::Rewind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileReader
的用法示例。
在下文中一共展示了FileReader::Rewind方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadDIGI
bool CSoundFile::ReadDIGI(FileReader &file, ModLoadingFlags loadFlags)
//--------------------------------------------------------------------
{
file.Rewind();
DIGIFileHeader fileHeader;
if(!file.ReadConvertEndianness(fileHeader)
|| memcmp(fileHeader.signature, "DIGI Booster module\0", 20)
|| !fileHeader.numChannels
|| fileHeader.numChannels > 8
|| fileHeader.lastOrdIndex > 127)
{
return false;
} else if(loadFlags == onlyVerifyHeader)
{
return true;
}
// Globals
InitializeGlobals();
InitializeChannels();
m_nType = MOD_TYPE_DIGI;
m_nChannels = fileHeader.numChannels;
m_nSamples = 31;
m_nSamplePreAmp = 256 / m_nChannels;
madeWithTracker = mpt::String::Print("Digi Booster %1.%2", fileHeader.versionInt >> 4, fileHeader.versionInt & 0x0F);
Order.ReadFromArray(fileHeader.orders, fileHeader.lastOrdIndex + 1);
// Read sample headers
for(SAMPLEINDEX smp = 0; smp < 31; smp++)
{
ModSample &sample = Samples[smp + 1];
sample.Initialize(MOD_TYPE_MOD);
sample.nLength = fileHeader.smpLength[smp];
sample.nLoopStart = fileHeader.smpLoopStart[smp];
sample.nLoopEnd = sample.nLoopStart + fileHeader.smpLoopLength[smp];
if(fileHeader.smpLoopLength[smp])
{
sample.uFlags.set(CHN_LOOP);
}
sample.SanitizeLoops();
sample.nVolume = std::min(fileHeader.smpVolume[smp], uint8(64)) * 4;
sample.nFineTune = MOD2XMFineTune(fileHeader.smpFinetune[smp]);
}
// Read song + sample names
file.ReadString<mpt::String::maybeNullTerminated>(songName, 32);
for(SAMPLEINDEX smp = 1; smp <= 31; smp++)
{
file.ReadString<mpt::String::maybeNullTerminated>(m_szNames[smp], 30);
}
for(PATTERNINDEX pat = 0; pat <= fileHeader.lastPatIndex; pat++)
{
FileReader patternChunk;
if(fileHeader.packEnable)
{
patternChunk = file.ReadChunk(file.ReadUint16BE());
} else
{
patternChunk = file.ReadChunk(4 * 64 * GetNumChannels());
}
if(!(loadFlags & loadPatternData) || Patterns.Insert(pat, 64))
{
continue;
}
if(fileHeader.packEnable)
{
std::vector<uint8> eventMask;
patternChunk.ReadVector(eventMask, 64);
// Compressed patterns are stored in row-major order...
for(ROWINDEX row = 0; row < 64; row++)
{
PatternRow patRow = Patterns[pat].GetRow(row);
uint8 bit = 0x80;
for(CHANNELINDEX chn = 0; chn < GetNumChannels(); chn++, bit >>= 1)
{
if(eventMask[row] & bit)
{
ModCommand &m = patRow[chn];
ReadDIGIPatternEntry(patternChunk, m, *this);
}
}
}
} else
{
// ...but uncompressed patterns are stored in column-major order. WTF!
for(CHANNELINDEX chn = 0; chn < GetNumChannels(); chn++)
示例2: ReadOpusSample
bool CSoundFile::ReadOpusSample(SAMPLEINDEX sample, FileReader &file)
{
file.Rewind();
#if defined(MPT_WITH_OPUSFILE)
int rate = 0;
int channels = 0;
std::vector<int16> raw_sample_data;
FileReader initial = file.GetChunk(65536); // 512 is recommended by libopusfile
if(op_test(NULL, initial.GetRawData<unsigned char>(), initial.GetLength()) != 0)
{
return false;
}
OggOpusFile *of = op_open_memory(file.GetRawData<unsigned char>(), file.GetLength(), NULL);
if(!of)
{
return false;
}
rate = 48000;
channels = op_channel_count(of, -1);
if(rate <= 0 || channels <= 0)
{
op_free(of);
of = NULL;
return false;
}
if(channels > 2 || op_link_count(of) != 1)
{
// We downmix multichannel to stereo as recommended by Opus specification in
// case we are not able to handle > 2 channels.
// We also decode chained files as stereo even if they start with a mono
// stream, which simplifies handling of link boundaries for us.
channels = 2;
}
std::vector<int16> decodeBuf(120 * 48000 / 1000); // 120ms (max Opus packet), 48kHz
bool eof = false;
while(!eof)
{
int framesRead = 0;
if(channels == 2)
{
framesRead = op_read_stereo(of, &(decodeBuf[0]), static_cast<int>(decodeBuf.size()));
} else if(channels == 1)
{
framesRead = op_read(of, &(decodeBuf[0]), static_cast<int>(decodeBuf.size()), NULL);
}
if(framesRead > 0)
{
raw_sample_data.insert(raw_sample_data.end(), decodeBuf.begin(), decodeBuf.begin() + (framesRead * channels));
} else if(framesRead == 0)
{
eof = true;
} else if(framesRead == OP_HOLE)
{
// continue
} else
{
// other errors are fatal, stop decoding
eof = true;
}
}
op_free(of);
of = NULL;
if(raw_sample_data.empty())
{
return false;
}
DestroySampleThreadsafe(sample);
strcpy(m_szNames[sample], "");
Samples[sample].Initialize();
Samples[sample].nC5Speed = rate;
Samples[sample].nLength = raw_sample_data.size() / channels;
Samples[sample].uFlags.set(CHN_16BIT);
Samples[sample].uFlags.set(CHN_STEREO, channels == 2);
Samples[sample].AllocateSample();
std::copy(raw_sample_data.begin(), raw_sample_data.end(), Samples[sample].pSample16);
Samples[sample].Convert(MOD_TYPE_IT, GetType());
Samples[sample].PrecomputeLoops(*this, false);
return Samples[sample].pSample != nullptr;
#else // !MPT_WITH_OPUSFILE
MPT_UNREFERENCED_PARAMETER(sample);
MPT_UNREFERENCED_PARAMETER(file);
return false;
#endif // MPT_WITH_OPUSFILE
//.........这里部分代码省略.........
示例3: Rewind
/**
* Rewind the file to the beginning.
*/
void Rewind() {
file.Rewind();
buffered.Reset();
}
示例4: ReadITQ
bool CSoundFile::ReadITQ(FileReader &file, ModLoadingFlags loadFlags)
//------------------------------------------------------------------
{
file.Rewind();
ITFileHeader fileHeader;
if(!file.ReadConvertEndianness(fileHeader)
|| (memcmp(fileHeader.id, "ITQM", 4))
|| fileHeader.insnum > 0xFF
|| fileHeader.smpnum >= MAX_SAMPLES
|| !file.CanRead(fileHeader.ordnum + (fileHeader.insnum + fileHeader.smpnum + fileHeader.patnum) * 4))
{
return false;
} else if(loadFlags == onlyVerifyHeader)
{
return true;
}
InitializeGlobals();
bool interpretModPlugMade = false;
// OpenMPT crap at the end of file
file.Seek(file.GetLength() - 4);
size_t mptStartPos = file.ReadUint32LE();
if(mptStartPos >= file.GetLength() || mptStartPos < 0x100)
{
mptStartPos = file.GetLength();
}
if(!memcmp(fileHeader.id, "tpm.", 4))
{
// Legacy MPTM files (old 1.17.02.xx releases)
ChangeModTypeTo(MOD_TYPE_MPT);
} else
{
if(mptStartPos <= file.GetLength() - 3 && fileHeader.cwtv > 0x888 && fileHeader.cwtv <= 0xFFF)
{
file.Seek(mptStartPos);
ChangeModTypeTo(file.ReadMagic("228") ? MOD_TYPE_MPT : MOD_TYPE_IT);
} else
{
ChangeModTypeTo(MOD_TYPE_IT);
}
if(GetType() == MOD_TYPE_IT)
{
// Which tracker was used to made this?
if((fileHeader.cwtv & 0xF000) == 0x5000)
{
// OpenMPT Version number (Major.Minor)
// This will only be interpreted as "made with ModPlug" (i.e. disable compatible playback etc) if the "reserved" field is set to "OMPT" - else, compatibility was used.
m_dwLastSavedWithVersion = (fileHeader.cwtv & 0x0FFF) << 16;
if(!memcmp(fileHeader.reserved, "OMPT", 4))
interpretModPlugMade = true;
} else if(fileHeader.cmwt == 0x888 || fileHeader.cwtv == 0x888)
{
// OpenMPT 1.17 and 1.18 (raped IT format)
// Exact version number will be determined later.
interpretModPlugMade = true;
} else if(fileHeader.cwtv == 0x0217 && fileHeader.cmwt == 0x0200 && !memcmp(fileHeader.reserved, "\0\0\0\0", 4))
{
if(memchr(fileHeader.chnpan, 0xFF, sizeof(fileHeader.chnpan)) != NULL)
{
// ModPlug Tracker 1.16 (semi-raped IT format)
m_dwLastSavedWithVersion = MAKE_VERSION_NUMERIC(1, 16, 00, 00);
madeWithTracker = "ModPlug tracker 1.09 - 1.16";
} else
{
// OpenMPT 1.17 disguised as this in compatible mode,
// but never writes 0xFF in the pan map for unused channels (which is an invalid value).
m_dwLastSavedWithVersion = MAKE_VERSION_NUMERIC(1, 17, 00, 00);
madeWithTracker = "OpenMPT 1.17 (compatibility export)";
}
interpretModPlugMade = true;
} else if(fileHeader.cwtv == 0x0214 && fileHeader.cmwt == 0x0202 && !memcmp(fileHeader.reserved, "\0\0\0\0", 4))
{
// ModPlug Tracker b3.3 - 1.09, instruments 557 bytes apart
m_dwLastSavedWithVersion = MAKE_VERSION_NUMERIC(1, 09, 00, 00);
madeWithTracker = "ModPlug tracker b3.3 - 1.09";
interpretModPlugMade = true;
}
} else // case: type == MOD_TYPE_MPT
{
if (fileHeader.cwtv >= verMptFileVerLoadLimit)
{
AddToLog(str_LoadingIncompatibleVersion);
return false;
}
else if (fileHeader.cwtv > verMptFileVer)
{
AddToLog(str_LoadingMoreRecentVersion);
}
}
}
if(GetType() == MOD_TYPE_IT) mptStartPos = file.GetLength();
// Read row highlights
if((fileHeader.special & ITFileHeader::embedPatternHighlights))
//.........这里部分代码省略.........
示例5: void
OPENMPT_NAMESPACE_BEGIN
bool CSoundFile::ReadMO3(FileReader &file, ModLoadingFlags loadFlags)
//-------------------------------------------------------------------
{
file.Rewind();
// No valid MO3 file (magic bytes: "MO3")
if(!file.CanRead(8) || !file.ReadMagic("MO3"))
{
return false;
} else if(loadFlags == onlyVerifyHeader)
{
return true;
}
#ifdef NO_MO3
// As of November 2013, the format revision is 5; Versions > 31 are unlikely to exist in the next few years,
// so we will just ignore those if there's no UNMO3 library to tell us if the file is valid or not
// (avoid log entry with .MOD files that have a song name starting with "MO3".
if(file.ReadUint8() > 31)
{
return false;
}
AddToLog(GetStrI18N("The file appears to be a MO3 file, but this OpenMPT build does not support loading MO3 files."));
return false;
#else
bool result = false; // Result of trying to load the module, false == fail.
// Try to load unmo3 dynamically.
mpt::Library unmo3 = mpt::Library(mpt::LibraryPath::App(MPT_PATHSTRING("unmo3")));
if(!unmo3.IsValid())
{
// Didn't succeed.
AddToLog(GetStrI18N("Loading MO3 file failed because unmo3.dll could not be loaded."));
} else
{
// Library loaded successfully.
#if MPT_OS_WINDOWS
#define UNMO3_API __stdcall
#else
#define UNMO3_API
#endif
typedef uint32 (UNMO3_API * UNMO3_GETVERSION)();
// Decode a MO3 file (returns the same "exit codes" as UNMO3.EXE, eg. 0=success)
// IN: data/len = MO3 data/len
// OUT: data/len = decoded data/len (if successful)
// flags & 1: Don't load samples
typedef int32 (UNMO3_API * UNMO3_DECODE_OLD)(const void **data, uint32 *len);
typedef int32 (UNMO3_API * UNMO3_DECODE)(const void **data, uint32 *len, uint32 flags);
// Free the data returned by UNMO3_Decode
typedef void (UNMO3_API * UNMO3_FREE)(const void *data);
#undef UNMO3_API
UNMO3_GETVERSION UNMO3_GetVersion = nullptr;
UNMO3_DECODE_OLD UNMO3_Decode_Old = nullptr;
UNMO3_DECODE UNMO3_Decode = nullptr;
UNMO3_FREE UNMO3_Free = nullptr;
unmo3.Bind(UNMO3_GetVersion, "UNMO3_GetVersion");
if(UNMO3_GetVersion == nullptr)
{
// Old API version: No "flags" parameter.
unmo3.Bind(UNMO3_Decode_Old, "UNMO3_Decode");
} else
{
unmo3.Bind(UNMO3_Decode, "UNMO3_Decode");
}
unmo3.Bind(UNMO3_Free, "UNMO3_Free");
if((UNMO3_Decode != nullptr || UNMO3_Decode_Old != nullptr) && UNMO3_Free != nullptr)
{
file.Rewind();
const void *stream = file.GetRawData();
uint32 length = mpt::saturate_cast<uint32>(file.GetLength());
int32 unmo3result;
if(UNMO3_Decode != nullptr)
{
unmo3result = UNMO3_Decode(&stream, &length, (loadFlags & loadSampleData) ? 0 : 1);
} else
{
// Old API version: No "flags" parameter.
unmo3result = UNMO3_Decode_Old(&stream, &length);
}
if(unmo3result == 0)
{
// If decoding was successful, stream and length will keep the new pointers now.
FileReader unpackedFile(stream, length);
result = ReadXM(unpackedFile, loadFlags)
|| ReadIT(unpackedFile, loadFlags)
|| ReadS3M(unpackedFile, loadFlags)
|| ReadMTM(unpackedFile, loadFlags)
|| ReadMod(unpackedFile, loadFlags)
|| ReadM15(unpackedFile, loadFlags);
//.........这里部分代码省略.........