本文整理汇总了C++中Shared::read方法的典型用法代码示例。如果您正苦于以下问题:C++ Shared::read方法的具体用法?C++ Shared::read怎么用?C++ Shared::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Shared
的用法示例。
在下文中一共展示了Shared::read方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadError
static Ref<Sound> load_wave_data (const Ptr<IData> data)
{
DecoderT decoder = NULL;
Shared<Buffer> buffer = data->buffer();
std::size_t i = 4;
uint32_t chunk_length;
int32_t magic;
i += buffer->read(i, chunk_length, LITTLE);
i += buffer->read(i, magic, BIG);
if (magic != 'WAVE')
throw LoadError("Could not load WAV data");
bool found_header;
uint16_t audio_format, channel_count, block_align, bits_per_sample;
uint32_t sample_frequency, byte_rate;
while (i < buffer->size()) {
i += buffer->read(i, magic, BIG);
i += buffer->read(i, chunk_length, LITTLE);
if (magic == 'fmt ') {
// Decode header
found_header = true;
i += buffer->read(i, audio_format, LITTLE);
i += buffer->read(i, channel_count, LITTLE);
i += buffer->read(i, sample_frequency, LITTLE);
i += buffer->read(i, byte_rate, LITTLE);
i += buffer->read(i, block_align, LITTLE);
i += buffer->read(i, bits_per_sample, LITTLE);
i += chunk_length - 16;
if (audio_format == 1) {
if (bits_per_sample == 8)
// Copy samples verbatim.
decoder = decode_linear_codec;
else
// Use PCM16 decoder - will pass through if endian doesn't need to be converted.
decoder = decode_pcm16_codec;
} else if (audio_format == 7) {
//bits_per_sample *= 2;
//decoder = decode_ulaw_codec;
throw LoadError("Unsupported WAV encoding (ULaw)");
} else {
throw LoadError("Unsupported WAV encoding (Unknown)");
}
} else if (magic == 'data') {
if (!found_header)
throw LoadError("Corrupt or truncated data");
StaticBuffer sample_data(&(*buffer)[i], chunk_length);
DREAM_ASSERT(decoder != NULL);
return decoder(&sample_data, channel_count, bits_per_sample, sample_frequency);
} else {
// Unknown header
i += chunk_length;
}
}
throw LoadError("Corrupt or truncated data");
}