本文整理汇总了C++中FileReader::AreBytesLeft方法的典型用法代码示例。如果您正苦于以下问题:C++ FileReader::AreBytesLeft方法的具体用法?C++ FileReader::AreBytesLeft怎么用?C++ FileReader::AreBytesLeft使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileReader
的用法示例。
在下文中一共展示了FileReader::AreBytesLeft方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IMAADPCMUnpack16
// Note: Only works for mono samples.
bool IMAADPCMUnpack16(int16 *target, SmpLength sampleLen, FileReader file, uint16 blockAlign)
//-------------------------------------------------------------------------------------------
{
static const int32 IMAIndexTab[8] = { -1, -1, -1, -1, 2, 4, 6, 8 };
static const int32 IMAUnpackTable[90] =
{
7, 8, 9, 10, 11, 12, 13, 14,
16, 17, 19, 21, 23, 25, 28, 31,
34, 37, 41, 45, 50, 55, 60, 66,
73, 80, 88, 97, 107, 118, 130, 143,
157, 173, 190, 209, 230, 253, 279, 307,
337, 371, 408, 449, 494, 544, 598, 658,
724, 796, 876, 963, 1060, 1166, 1282, 1411,
1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024,
3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484,
7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794,
32767, 0
};
if((sampleLen < 4) || (!target) || (blockAlign < 5) || (blockAlign > file.GetLength()))
return false;
SmpLength nPos = 0;
while((nPos < sampleLen) && file.CanRead(5))
{
int32 value = file.ReadIntLE<int16>();
int32 nIndex = file.ReadIntLE<uint8>();
nIndex = Clamp(nIndex, 0, 89);
file.Skip(1);
target[nPos++] = (int16)value;
for(uint32 i = 0; (i < (blockAlign - 4u) * 2u) && (nPos < sampleLen) && file.AreBytesLeft(); i++)
{
uint8 delta;
if(i & 1)
{
delta = (file.ReadIntLE<uint8>() >> 4) & 0x0F;
} else
{
delta = file.ReadIntLE<uint8>() & 0x0F;
file.SkipBack(1);
}
int32 v = IMAUnpackTable[nIndex] >> 3;
if (delta & 1) v += IMAUnpackTable[nIndex] >> 2;
if (delta & 2) v += IMAUnpackTable[nIndex] >> 1;
if (delta & 4) v += IMAUnpackTable[nIndex];
if (delta & 8) value -= v; else value += v;
nIndex += IMAIndexTab[delta & 7];
nIndex = Clamp(nIndex, 0, 88);
target[nPos++] = static_cast<int16>(Clamp(value, -32768, 32767));
}
示例2: ReadAMSPattern
// Read AMS or AMS2 (newVersion = true) pattern. At least this part of the format is more or less identical between the two trackers...
static void ReadAMSPattern(CPattern &pattern, bool newVersion, FileReader &patternChunk, CSoundFile &sndFile)
//-----------------------------------------------------------------------------------------------------------
{
enum
{
emptyRow = 0xFF, // No commands on row
endOfRowMask = 0x80, // If set, no more commands on this row
noteMask = 0x40, // If set, no note+instr in this command
channelMask = 0x1F, // Mask for extracting channel
// Note flags
readNextCmd = 0x80, // One more command follows
noteDataMask = 0x7F, // Extract note
// Command flags
volCommand = 0x40, // Effect is compressed volume command
commandMask = 0x3F, // Command or volume mask
};
// Effect translation table for extended (non-Protracker) effects
static const ModCommand::COMMAND effTrans[] =
{
CMD_S3MCMDEX, // Forward / Backward
CMD_PORTAMENTOUP, // Extra fine slide up
CMD_PORTAMENTODOWN, // Extra fine slide up
CMD_RETRIG, // Retrigger
CMD_NONE,
CMD_TONEPORTAVOL, // Toneporta with fine volume slide
CMD_VIBRATOVOL, // Vibrato with fine volume slide
CMD_NONE,
CMD_PANNINGSLIDE,
CMD_NONE,
CMD_VOLUMESLIDE, // Two times finder volume slide than Axx
CMD_NONE,
CMD_CHANNELVOLUME, // Channel volume (0...127)
CMD_PATTERNBREAK, // Long pattern break (in hex)
CMD_S3MCMDEX, // Fine slide commands
CMD_NONE, // Fractional BPM
CMD_KEYOFF, // Key off at tick xx
CMD_PORTAMENTOUP, // Porta up, but uses all octaves (?)
CMD_PORTAMENTODOWN, // Porta down, but uses all octaves (?)
CMD_NONE,
CMD_NONE,
CMD_NONE,
CMD_NONE,
CMD_NONE,
CMD_NONE,
CMD_NONE,
CMD_GLOBALVOLSLIDE, // Global volume slide
CMD_NONE,
CMD_GLOBALVOLUME, // Global volume (0... 127)
};
static ModCommand dummy;
for(ROWINDEX row = 0; row < pattern.GetNumRows(); row++)
{
PatternRow baseRow = pattern.GetRow(row);
while(patternChunk.AreBytesLeft())
{
const uint8 flags = patternChunk.ReadUint8();
if(flags == emptyRow)
{
break;
}
const CHANNELINDEX chn = (flags & channelMask);
ModCommand &m = chn < pattern.GetNumChannels() ? baseRow[chn] : dummy;
bool moreCommands = true;
if(!(flags & noteMask))
{
// Read note + instr
uint8 note = patternChunk.ReadUint8();
moreCommands = (note & readNextCmd) != 0;
note &= noteDataMask;
if(note == 1)
{
m.note = NOTE_KEYOFF;
} else if(note >= 2 && note <= 121 && newVersion)
{
m.note = note - 2 + NOTE_MIN;
} else if(note >= 12 && note <= 108 && !newVersion)
{
m.note = note + 12 + NOTE_MIN;
}
m.instr = patternChunk.ReadUint8();
}
while(moreCommands)
{
// Read one more effect command
ModCommand origCmd = m;
const uint8 command = patternChunk.ReadUint8(), effect = (command & commandMask);
moreCommands = (command & readNextCmd) != 0;
if(command & volCommand)
{
m.volcmd = VOLCMD_VOLUME;
//.........这里部分代码省略.........
示例3: ReadITProject
//.........这里部分代码省略.........
SAMPLEINDEX realSample = static_cast<SAMPLEINDEX>(file.ReadUint32LE());
ITSample sampleHeader;
file.ReadConvertEndianness(sampleHeader);
size = file.ReadUint32LE();
if(realSample >= 1 && realSample <= GetNumSamples() && !memcmp(sampleHeader.id, "IMPS", 4) && (loadFlags & loadSampleData))
{
sampleHeader.ConvertToMPT(Samples[realSample]);
mpt::String::Read<mpt::String::nullTerminated>(m_szNames[realSample], sampleHeader.name);
// Read sample data
sampleHeader.GetSampleFormat().ReadSample(Samples[realSample], file);
} else
{
file.Skip(size);
}
}
// Load instruments
for(INSTRUMENTINDEX ins = 0; ins < GetNumInstruments(); ins++)
{
if(instrPaths[ins].empty())
continue;
if(!file.GetFileName().empty())
{
instrPaths[ins] = instrPaths[ins].RelativePathToAbsolute(file.GetFileName().GetPath());
}
#ifdef MODPLUG_TRACKER
else if(GetpModDoc() != nullptr)
{
instrPaths[ins] = instrPaths[ins].RelativePathToAbsolute(GetpModDoc()->GetPathNameMpt().GetPath());
}
const bool mayNormalize = TrackerSettings::Instance().m_MayNormalizeSamplesOnLoad;
#else
const bool mayNormalize = false;
#endif // MODPLUG_TRACKER
InputFile f(instrPaths[ins]);
FileReader file = GetFileReader(f);
if(!ReadInstrumentFromFile(ins + 1, file, mayNormalize))
{
AddToLog(LogWarning, MPT_USTRING("Unable to open instrument: ") + instrPaths[ins].ToUnicode());
}
}
// Extra info data
uint32 code = file.ReadUint32LE();
// Embed instruments' header [v1.01]
if(version >= 0x00000101 && (songFlags & ITP_ITPEMBEDIH) && code == MAGIC4BE('E', 'B', 'I', 'H'))
{
code = file.ReadUint32LE();
INSTRUMENTINDEX ins = 1;
while(ins <= GetNumInstruments() && file.AreBytesLeft())
{
if(code == MAGIC4BE('M', 'P', 'T', 'S'))
{
break;
} else if(code == MAGIC4BE('S', 'E', 'P', '@') || code == MAGIC4BE('M', 'P', 'T', 'X'))
{
// jump code - switch to next instrument
ins++;
} else
{
ReadExtendedInstrumentProperty(Instruments[ins], code, file);
}
code = file.ReadUint32LE();
}
}
// Song extensions
if(code == MAGIC4BE('M', 'P', 'T', 'S'))
{
file.SkipBack(4);
LoadExtendedSongProperties(MOD_TYPE_IT, file);
}
m_nType = MOD_TYPE_IT;
m_nMaxPeriod = 0xF000;
m_nMinPeriod = 8;
UpgradeModFlags();
// Before OpenMPT 1.20.01.09, the MIDI macros were always read from the file, even if the "embed" flag was not set.
if(m_dwLastSavedWithVersion >= MAKE_VERSION_NUMERIC(1,20,01,09) && !m_SongFlags[SONG_EMBEDMIDICFG])
{
m_MidiCfg.Reset();
} else if(!m_MidiCfg.IsMacroDefaultSetupUsed())
{
m_SongFlags.set(SONG_EMBEDMIDICFG);
}
madeWithTracker = "OpenMPT " + MptVersion::ToStr(m_dwLastSavedWithVersion);
return true;
#endif // MPT_EXTERNAL_SAMPLES
}
示例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.