本文整理汇总了C++中FileReader::GetChunk方法的典型用法代码示例。如果您正苦于以下问题:C++ FileReader::GetChunk方法的具体用法?C++ FileReader::GetChunk怎么用?C++ FileReader::GetChunk使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileReader
的用法示例。
在下文中一共展示了FileReader::GetChunk方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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.GetChunk(file.ReadUint16BE());
} else
{
patternChunk = file.GetChunk(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: ReadITQ
//.........这里部分代码省略.........
// Another non-conforming application is unmo3 < v2.4.0.1, which doesn't set the special bit
// at all, but still writes the two edit history length bytes (zeroes)...
if(file.ReadUint16LE() != 0)
{
// These were not zero bytes -> We're in the wrong place!
file.SkipBack(2);
madeWithTracker = "UNMO3";
}
}
// Reading MIDI Output & Macros
if(m_SongFlags[SONG_EMBEDMIDICFG] && file.Read(m_MidiCfg))
{
m_MidiCfg.Sanitize();
}
// Ignore MIDI data. Fixes some files like denonde.it that were made with old versions of Impulse Tracker (which didn't support Zxx filters) and have Zxx effects in the patterns.
if(fileHeader.cwtv < 0x0214)
{
MemsetZero(m_MidiCfg.szMidiSFXExt);
MemsetZero(m_MidiCfg.szMidiZXXExt);
m_SongFlags.set(SONG_EMBEDMIDICFG);
}
if(file.ReadMagic("MODU"))
{
madeWithTracker = "BeRoTracker";
}
// Read pattern names: "PNAM"
FileReader patNames;
if(file.ReadMagic("PNAM"))
{
patNames = file.GetChunk(file.ReadUint32LE());
}
m_nChannels = GetModSpecifications().channelsMin;
// Read channel names: "CNAM"
if(file.ReadMagic("CNAM"))
{
FileReader chnNames = file.GetChunk(file.ReadUint32LE());
const CHANNELINDEX readChns = std::min(MAX_BASECHANNELS, static_cast<CHANNELINDEX>(chnNames.GetLength() / MAX_CHANNELNAME));
m_nChannels = readChns;
for(CHANNELINDEX i = 0; i < readChns; i++)
{
chnNames.ReadString<mpt::String::maybeNullTerminated>(ChnSettings[i].szName, MAX_CHANNELNAME);
}
}
// Read mix plugins information
if(file.CanRead(9))
{
LoadMixPlugins(file);
}
// Read Song Message
if(fileHeader.special & ITFileHeader::embedSongMessage)
{
if(fileHeader.msglength > 0 && file.Seek(fileHeader.msgoffset))
{
// Generally, IT files should use CR for line endings. However, ChibiTracker uses LF. One could do...
// if(itHeader.cwtv == 0x0214 && itHeader.cmwt == 0x0214 && itHeader.reserved == ITFileHeader::chibiMagic) --> Chibi detected.
// But we'll just use autodetection here:
songMessage.Read(file, fileHeader.msglength, SongMessage::leAutodetect);
}