Пример #1
0
CL_PCXProvider_Impl::CL_PCXProvider_Impl(
	CL_IODevice &datafile)
{
	image = NULL;

	bool little_endian = datafile.is_little_endian();
	if (!little_endian)
		datafile.set_little_endian_mode();

	read_pcx(datafile);

	if (!little_endian)
		datafile.set_big_endian_mode();

}
void CL_SoundProvider_Wave_Impl::load(CL_IODevice &source)
{
	source.set_little_endian_mode();

	char chunk_id[4];
	source.read(chunk_id, 4);
	if (memcmp(chunk_id, "RIFF", 4))
		throw CL_Exception("Expected RIFF header!");
	cl_ubyte32 chunk_size = source.read_uint32();

	char format_id[4];
	source.read(format_id, 4);
	if (memcmp(format_id, "WAVE", 4))
		throw CL_Exception("Expected WAVE header!");

	cl_ubyte32 subchunk_pos = source.get_position();
	cl_ubyte32 subchunk1_size = find_subchunk("fmt ", source, subchunk_pos, chunk_size);

	cl_ubyte16 audio_format = source.read_uint16();
	num_channels = source.read_uint16();
	frequency = source.read_uint32();
	cl_ubyte32 byte_rate = source.read_uint32();
	cl_ubyte16 block_align = source.read_uint16();
	cl_ubyte16 bits_per_sample = source.read_uint16();

	if (bits_per_sample == 16)
		format = sf_16bit_signed;
	else if (bits_per_sample == 8)
		format = sf_8bit_unsigned;
	else
		throw CL_Exception("Unsupported wave sample format");

	cl_ubyte32 subchunk2_size = find_subchunk("data", source, subchunk_pos, chunk_size);

	data = new char[subchunk2_size];
	source.read(data, subchunk2_size);

	num_samples = subchunk2_size / block_align;
}