Ejemplo n.º 1
0
slong shn_uchar_to_slong_le(uchar *buf)
/* converts 4 bytes stored in little-endian format to an slong */
{
	return (slong)shn_uchar_to_ulong_le(buf);
}
Ejemplo n.º 2
0
Archivo: wave.c Proyecto: kode54/cog-1
int shn_verify_header(shn_file *this_shn)
{
	ulong l;
	int cur = 0;

/*	if (0 == is_valid_file(this_shn))
	{
		shn_debug(this_shn->config, "while processing '%s': something went wrong while opening this file, see above",this_shn->wave_header.filename);
		return 0;
	}*/

	if (this_shn->vars.bytes_in_header < CANONICAL_HEADER_SIZE) {
		shn_debug(this_shn->config, "while processing '%s': header is only %d bytes (should be at least %d bytes)",
			this_shn->wave_header.filename,this_shn->vars.bytes_in_header,CANONICAL_HEADER_SIZE);
		return 0;
	}

	if (WAVE_RIFF != shn_uchar_to_ulong_le(this_shn->vars.header+cur))
	{
		if (AIFF_FORM == shn_uchar_to_ulong_le(this_shn->vars.header+cur))
			shn_debug(this_shn->config, "while processing '%s': file contains AIFF data, which is currently not supported",this_shn->wave_header.filename);
		else
			shn_debug(this_shn->config, "while processing '%s': WAVE header is missing RIFF tag - possible corrupt file",this_shn->wave_header.filename);
		return 0;
	}
	cur += 4;

	this_shn->wave_header.chunk_size = shn_uchar_to_ulong_le(this_shn->vars.header+cur);
	cur += 4;

	if (WAVE_WAVE != shn_uchar_to_ulong_le(this_shn->vars.header+cur))
	{
		shn_debug(this_shn->config, "while processing '%s': WAVE header is missing WAVE tag",this_shn->wave_header.filename);
		return 0;
	}
	cur += 4;

	for (;;)
	{
		cur += 4;

		l = shn_uchar_to_ulong_le(this_shn->vars.header+cur);
		cur += 4;

		if (WAVE_FMT == shn_uchar_to_ulong_le(this_shn->vars.header+cur-8))
			break;

		cur += l;
	}

	if (l < 16)
	{
		shn_debug(this_shn->config, "while processing '%s': fmt chunk in WAVE header was too short",this_shn->wave_header.filename);
		return 0;
	}

	this_shn->wave_header.wave_format = shn_uchar_to_ushort_le(this_shn->vars.header+cur);
	cur += 2;

	switch (this_shn->wave_header.wave_format)
	{
		case WAVE_FORMAT_PCM:
			break;
		default:
			shn_debug(this_shn->config, "while processing '%s': unsupported format 0x%04x (%s) - only PCM data is supported at this time",
				this_shn->wave_header.filename,this_shn->wave_header.wave_format,shn_format_to_str(this_shn->wave_header.wave_format));
                        return 0;
	}

	this_shn->wave_header.channels = shn_uchar_to_ushort_le(this_shn->vars.header+cur);
	cur += 2;
	this_shn->wave_header.samples_per_sec = shn_uchar_to_ulong_le(this_shn->vars.header+cur);
	cur += 4;
	this_shn->wave_header.avg_bytes_per_sec = shn_uchar_to_ulong_le(this_shn->vars.header+cur);
	cur += 4;
	this_shn->wave_header.block_align = shn_uchar_to_ushort_le(this_shn->vars.header+cur);
	cur += 2;
	this_shn->wave_header.bits_per_sample = shn_uchar_to_ushort_le(this_shn->vars.header+cur);
	cur += 2;

	if (this_shn->wave_header.bits_per_sample != 8 && this_shn->wave_header.bits_per_sample != 16)
	{
		shn_debug(this_shn->config, "while processing '%s': bits per sample is neither 8 nor 16",this_shn->wave_header.filename);
		return 0;
	}

	l -= 16;

	if (l > 0)
		cur += l;

	for (;;)
	{
		cur += 4;

		l = shn_uchar_to_ulong_le(this_shn->vars.header+cur);
		cur += 4;

		if (WAVE_DATA == shn_uchar_to_ulong_le(this_shn->vars.header+cur-8))
			break;

		cur += l;
	}

	this_shn->wave_header.rate = ((uint)this_shn->wave_header.samples_per_sec *
				      (uint)this_shn->wave_header.channels *
				      (uint)this_shn->wave_header.bits_per_sample) / 8;
	this_shn->wave_header.header_size = cur;
	this_shn->wave_header.data_size = l;
	this_shn->wave_header.total_size = this_shn->wave_header.chunk_size + 8;
	this_shn->wave_header.length = this_shn->wave_header.data_size / this_shn->wave_header.rate;
	this_shn->wave_header.exact_length = (double)this_shn->wave_header.data_size / (double)this_shn->wave_header.rate;

	if (this_shn->wave_header.channels == CD_CHANNELS &&
	    this_shn->wave_header.bits_per_sample == CD_BITS_PER_SAMPLE &&
	    this_shn->wave_header.samples_per_sec == CD_SAMPLES_PER_SEC &&
	    this_shn->wave_header.avg_bytes_per_sec == CD_RATE &&
	    this_shn->wave_header.rate == CD_RATE)
	{
		if (this_shn->wave_header.data_size < CD_MIN_BURNABLE_SIZE)
			this_shn->wave_header.problems |= PROBLEM_CD_BUT_TOO_SHORT;
		if (this_shn->wave_header.data_size % CD_BLOCK_SIZE != 0)
			this_shn->wave_header.problems |= PROBLEM_CD_BUT_BAD_BOUND;
	}
	else
		this_shn->wave_header.problems |= PROBLEM_NOT_CD_QUALITY;

	if (this_shn->wave_header.header_size != CANONICAL_HEADER_SIZE)
		this_shn->wave_header.problems |= PROBLEM_HEADER_NOT_CANONICAL;

	if ((ulong)this_shn->wave_header.header_size + this_shn->wave_header.data_size > this_shn->wave_header.total_size)
		this_shn->wave_header.problems |= PROBLEM_HEADER_INCONSISTENT;

	if ((ulong)this_shn->wave_header.header_size + this_shn->wave_header.data_size < this_shn->wave_header.total_size)
		this_shn->wave_header.problems |= PROBLEM_EXTRA_CHUNKS;

	shn_length_to_str(this_shn);

	/* header looks ok */
	return 1;
}