本文整理汇总了C++中FileReader::BytesLeft方法的典型用法代码示例。如果您正苦于以下问题:C++ FileReader::BytesLeft方法的具体用法?C++ FileReader::BytesLeft怎么用?C++ FileReader::BytesLeft使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileReader
的用法示例。
在下文中一共展示了FileReader::BytesLeft方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadFixedLineLength
bool SongMessage::ReadFixedLineLength(FileReader &file, const size_t length, const size_t lineLength, const size_t lineEndingLength)
//----------------------------------------------------------------------------------------------------------------------------------
{
FileReader::off_t readLength = std::min(static_cast<FileReader::off_t>(length), file.BytesLeft());
bool success = ReadFixedLineLength(file.GetRawData(), readLength, lineLength, lineEndingLength);
file.Skip(readLength);
return success;
}
示例2: CopyWavChannel
bool CopyWavChannel(ModSample &sample, const FileReader &file, size_t channelIndex, size_t numChannels, SampleConversion conv = SampleConversion())
//-------------------------------------------------------------------------------------------------------------------------------------------------
{
ASSERT(sample.GetNumChannels() == 1);
ASSERT(sample.GetElementarySampleSize() == sizeof(typename SampleConversion::output_t));
const size_t offset = channelIndex * sizeof(typename SampleConversion::input_t) * SampleConversion::input_inc;
if(sample.AllocateSample() == 0 || !file.CanRead(offset))
{
return false;
}
const char *inBuf = file.GetRawData();
CopySample<SampleConversion>(reinterpret_cast<typename SampleConversion::output_t*>(sample.pSample), sample.nLength, 1, inBuf + offset, file.BytesLeft() - offset, numChannels, conv);
return true;
}
示例3: ReadSample
OPENMPT_NAMESPACE_BEGIN
#if MPT_COMPILER_GCC
#if MPT_GCC_AT_LEAST(4,6,0)
#pragma GCC diagnostic push
#endif
#pragma GCC diagnostic ignored "-Wswitch"
#elif MPT_COMPILER_CLANG
#pragma clang diagnostic push
#if MPT_CLANG_AT_LEAST(3,3,0)
#pragma clang diagnostic ignored "-Wswitch"
#else
#pragma clang diagnostic ignored "-Wswitch-enum"
#endif
#endif
// Read a sample from memory
size_t SampleIO::ReadSample(ModSample &sample, FileReader &file) const
//--------------------------------------------------------------------
{
if(sample.nLength < 1 || !file.IsValid())
{
return 0;
}
LimitMax(sample.nLength, MAX_SAMPLE_LENGTH);
const char * const sourceBuf = file.GetRawData();
const FileReader::off_t fileSize = file.BytesLeft(), filePosition = file.GetPosition();
FileReader::off_t bytesRead = 0; // Amount of memory that has been read from file
sample.uFlags.set(CHN_16BIT, GetBitDepth() >= 16);
sample.uFlags.set(CHN_STEREO, GetChannelFormat() != mono);
size_t sampleSize = sample.AllocateSample(); // Target sample size in bytes
if(sampleSize == 0)
{
sample.nLength = 0;
return 0;
}
ASSERT(sampleSize >= sample.GetSampleSizeInBytes());
//////////////////////////////////////////////////////
// 8-Bit / Mono / PCM
if(GetBitDepth() == 8 && GetChannelFormat() == mono)
{
switch(GetEncoding())
{
case signedPCM: // 8-Bit / Mono / Signed / PCM
bytesRead = CopyMonoSample<SC::DecodeInt8>(sample, sourceBuf, fileSize);
break;
case unsignedPCM: // 8-Bit / Mono / Unsigned / PCM
bytesRead = CopyMonoSample<SC::DecodeUint8>(sample, sourceBuf, fileSize);
break;
case deltaPCM: // 8-Bit / Mono / Delta / PCM
case MT2:
bytesRead = CopyMonoSample<SC::DecodeInt8Delta>(sample, sourceBuf, fileSize);
break;
case PCM7to8: // 7 Bit stored as 8-Bit with highest bit unused / Mono / Signed / PCM
bytesRead = CopyMonoSample<SC::DecodeInt7>(sample, sourceBuf, fileSize);
break;
}
}
//////////////////////////////////////////////////////
// 8-Bit / Stereo Split / PCM
else if(GetBitDepth() == 8 && GetChannelFormat() == stereoSplit)
{
switch(GetEncoding())
{
case signedPCM: // 8-Bit / Stereo Split / Signed / PCM
bytesRead = CopyStereoSplitSample<SC::DecodeInt8>(sample, sourceBuf, fileSize);
break;
case unsignedPCM: // 8-Bit / Stereo Split / Unsigned / PCM
bytesRead = CopyStereoSplitSample<SC::DecodeUint8>(sample, sourceBuf, fileSize);
break;
case deltaPCM: // 8-Bit / Stereo Split / Delta / PCM
case MT2:
bytesRead = CopyStereoSplitSample<SC::DecodeInt8Delta>(sample, sourceBuf, fileSize);
break;
}
}
//////////////////////////////////////////////////////
// 8-Bit / Stereo Interleaved / PCM
else if(GetBitDepth() == 8 && GetChannelFormat() == stereoInterleaved)
{
switch(GetEncoding())
{
case signedPCM: // 8-Bit / Stereo Interleaved / Signed / PCM
bytesRead = CopyStereoInterleavedSample<SC::DecodeInt8>(sample, sourceBuf, fileSize);
break;
case unsignedPCM: // 8-Bit / Stereo Interleaved / Unsigned / PCM
bytesRead = CopyStereoInterleavedSample<SC::DecodeUint8>(sample, sourceBuf, fileSize);
break;
case deltaPCM: // 8-Bit / Stereo Interleaved / Delta / PCM
bytesRead = CopyStereoInterleavedSample<SC::DecodeInt8Delta>(sample, sourceBuf, fileSize);
break;
//.........这里部分代码省略.........
示例4: ReadITQ
//.........这里部分代码省略.........
m_nMaxPeriod = 0xF000;
PATTERNINDEX numPats = std::min(static_cast<PATTERNINDEX>(patPos.size()), GetModSpecifications().patternsMax);
if(numPats != patPos.size())
{
// Hack: Notify user here if file contains more patterns than what can be read.
AddToLog(mpt::String::Print(str_PatternSetTruncationNote, patPos.size(), numPats));
}
if(!(loadFlags & loadPatternData))
{
numPats = 0;
}
// Checking for number of used channels, which is not explicitely specified in the file.
for(PATTERNINDEX pat = 0; pat < numPats; pat++)
{
if(patPos[pat] == 0 || !file.Seek(patPos[pat]))
continue;
uint16 len = file.ReadUint16LE();
ROWINDEX numRows = file.ReadUint16LE();
if(numRows < GetModSpecifications().patternRowsMin
|| numRows > GetModSpecifications().patternRowsMax
|| !file.Skip(4))
continue;
FileReader patternData = file.GetChunk(len);
ROWINDEX row = 0;
std::vector<uint8> chnMask(GetNumChannels());
while(row < numRows && patternData.AreBytesLeft())
{
uint8 b = patternData.ReadUint8();
if(!b)
{
row++;
continue;
}
CHANNELINDEX ch = (b & IT_bitmask_patternChanField_c); // 0x7f We have some data grab a byte keeping only 7 bits
if(ch)
{
ch = (ch - 1);// & IT_bitmask_patternChanMask_c; // 0x3f mask of the byte again, keeping only 6 bits
}
if(ch >= chnMask.size())
{
chnMask.resize(ch + 1, 0);
}
if(b & IT_bitmask_patternChanEnabled_c) // 0x80 check if the upper bit is enabled.
{
chnMask[ch] = patternData.ReadUint8(); // set the channel mask for this channel.
}
// Channel used
if(chnMask[ch] & 0x0F) // if this channel is used set m_nChannels
{
if(ch >= GetNumChannels() && ch < MAX_BASECHANNELS)
{
m_nChannels = ch + 1;
}
}
// Now we actually update the pattern-row entry the note,instrument etc.