当前位置: 首页>>代码示例>>C++>>正文


C++ Shared::read方法代码示例

本文整理汇总了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");
		}
开发者ID:kurocha,项目名称:dream-audio-openal,代码行数:66,代码来源:Sound.cpp


注:本文中的Shared::read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。