本文整理汇总了C++中SampleBuffer::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ SampleBuffer::empty方法的具体用法?C++ SampleBuffer::empty怎么用?C++ SampleBuffer::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SampleBuffer
的用法示例。
在下文中一共展示了SampleBuffer::empty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Decode
Uint32 SoundFile::Decode(SampleBuffer& buffer, Uint32 length)
{
if (!initconv || !fileOpened)
{
return SOUND_DECODE_ERROR;
}
assert(buffer.empty());
Uint32 max_size = length == 0 ? uncomp_size * conv->len_mult : length;
buffer.resize(max_size);
Uint16 comp_sample_size, uncomp_sample_size;
Uint32 ID;
//if (offset < 12)
// offset = 12;
//file->seekSet(offset);
Uint32 written = 0;
while ((file->tell()+8) < file->fileSize()) {
// Each sample has a header
file->readWord(&comp_sample_size, 1);
file->readWord(&uncomp_sample_size, 1);
file->readDWord(&ID, 1);
if (comp_sample_size > (SOUND_MAX_CHUNK_SIZE)) {
logger->warning("Size data for current sample too large\n");
return SOUND_DECODE_ERROR;
}
// abort if id was wrong */
if (ID != 0xDEAF) {
logger->warning("Sample had wrong ID: %x\n", ID);
return SOUND_DECODE_ERROR;
}
if (written + uncomp_sample_size*conv->len_mult > max_size) {
file->seekCur(-8); // rewind stream back to headers
buffer.resize(written); // Truncate buffer.
return SOUND_DECODE_STREAMING;
}
// compressed data follows header
file->readByte(chunk, comp_sample_size);
if (type == 1) {
SoundUtils::WSADPCM_Decode(tmpbuff, chunk, comp_sample_size, uncomp_sample_size);
} else {
SoundUtils::IMADecode(tmpbuff, chunk, comp_sample_size, imaSample, imaIndex);
}
conv->buf = tmpbuff;
conv->len = uncomp_sample_size;
if (SDL_ConvertAudio(conv) < 0) {
logger->warning("Could not run conversion filter: %s\n", SDL_GetError());
return SOUND_DECODE_ERROR;
}
memcpy(&buffer[written], tmpbuff, uncomp_sample_size*conv->len_mult);
//offset += 8 + comp_sample_size;
written += uncomp_sample_size*conv->len_mult;
}
// Truncate if final sample was too small.
if (written < max_size)
buffer.resize(written);
return SOUND_DECODE_COMPLETED;
}