type_size = 8 + (chunk_size & 1); 
static int import_aiff_load(char *sample_file, Instrument *inst){	struct timidity_file	*tf;	char			buf[12];	int				chunk_size, type_index;	int				compressed;	int32			chunk_flags;	AIFFCommonChunk	common;	AIFFSoundDataChunk	sound;	GeneralInstrumentInfo	inst_info;	AIFFLoopInfo	loop_info;	AIFFMarkerData	*marker_data;		if ((tf = open_file(sample_file, 1, OF_NORMAL)) == NULL)		return 1;	if (tf_read(buf, 12, 1, tf) != 1			|| memcmp(&buf[0], "FORM", 4) != 0 || memcmp(&buf[8], "AIF", 3) != 0			|| (buf[8 + 3] != 'F' && buf[8 + 3] != 'C'))	{		close_file(tf);		return 1;	}	compressed = buf[8 + 3] == 'C';	ctl->cmsg(CMSG_INFO, VERB_NOISY, "Loading AIFF: %s", sample_file);	type_index = 4;	chunk_flags = 0;	sound.inst = inst;	sound.common = &common;	marker_data = NULL;	for(;;) {		if (tf_read(&buf[type_index], 8, 1, tf) != 1)			break;		chunk_size = BE_LONG(*(int32 *)&buf[4 + 4]);		if (memcmp(&buf[4 + 0], "COMM", 4) == 0)		{			if (chunk_flags & AIFF_CHUNKFLAG_COMMON)			{				chunk_flags |= AIFF_CHUNKFLAG_DUPCHUNK;				break;			}			if (chunk_size < 18)	/* too small */				break;			if (!read_AIFFCommonChunk(tf, &common, chunk_size, compressed))				break;			chunk_flags |= AIFF_CHUNKFLAG_COMMON;		}		else if (memcmp(&buf[4 + 0], "SSND", 4) == 0)		{			if (chunk_flags & AIFF_CHUNKFLAG_SOUND)			{				chunk_flags |= AIFF_CHUNKFLAG_DUPCHUNK;				break;			}			if (chunk_flags & AIFF_CHUNKFLAG_COMMON)			{				if (!read_AIFFSoundDataChunk(tf, &sound, chunk_size, 0))					break;				chunk_flags |= AIFF_CHUNKFLAG_SOUNDREAD;			}			else if (!read_AIFFSoundDataChunk(tf, &sound, chunk_size, 1))				break;			chunk_flags |= AIFF_CHUNKFLAG_SOUND;		}		else if (memcmp(&buf[4 + 0], "INST", 4) == 0)		{			if (chunk_flags & AIFF_CHUNKFLAG_INSTRUMENT)			{				chunk_flags |= AIFF_CHUNKFLAG_DUPCHUNK;				break;			}			else if (!read_AIFFInstumentChunk(tf, &inst_info, &loop_info, chunk_size))				break;			chunk_flags |= AIFF_CHUNKFLAG_INSTRUMENT;		}		else if (memcmp(&buf[4 + 0], "MARK", 4) == 0)		{			if (chunk_flags & AIFF_CHUNKFLAG_MARKER)			{				chunk_flags |= AIFF_CHUNKFLAG_DUPCHUNK;				break;			}			else if (chunk_size < 2 || !read_AIFFMarkerChunk(tf, &marker_data, chunk_size))				break;			chunk_flags |= AIFF_CHUNKFLAG_MARKER;		}		else if (inst->instname == NULL && memcmp(&buf[4 + 0], "NAME", 4) == 0)		{			inst->instname = malloc(chunk_size + 1);			if (tf_read(inst->instname, chunk_size, 1, tf) != 1)			{				chunk_flags |= AIFF_CHUNKFLAG_READERR;				break;			}			inst->instname[chunk_size] = '\0';		}		else if (tf_seek(tf, chunk_size, SEEK_CUR) == -1)			break;		/* no need to check format version chunk */		type_index = 4 - (chunk_size & 1);	}	if (chunk_flags & AIFF_CHUNKFLAG_FAILED			|| (chunk_flags & AIFF_CHUNKFLAG_REQUIRED) != AIFF_CHUNKFLAG_REQUIRED)	{		if (marker_data != NULL)			free(marker_data);		close_file(tf);		return -1;	}	if (!(chunk_flags & AIFF_CHUNKFLAG_SOUNDREAD))	{		if (!read_AIFFSoundDataChunk(tf, &sound, 0, 2))		{			if (marker_data != NULL)				free(marker_data);			close_file(tf);			return 1;		}	}	if (chunk_flags & AIFF_CHUNKFLAG_INSTRUMENT)	{		apply_GeneralInstrumentInfo(inst->samples, inst->sample, &inst_info);		if ((loop_info.mode == 1 || loop_info.mode == 2)				&& chunk_flags & AIFF_CHUNKFLAG_MARKER && marker_data != NULL)		{			Sample			*sample;			int				i;			uint32			loopStart, loopEnd;			uint8			loopMode;						if (AIFFGetMarkerPosition(loop_info.beginID, marker_data, &loopStart)					&& AIFFGetMarkerPosition(loop_info.endID, marker_data, &loopEnd))			{				loopMode = (loop_info.mode == 1) ? MODES_LOOPING : (MODES_LOOPING | MODES_PINGPONG);				loopStart <<= FRACTION_BITS;				loopEnd <<= FRACTION_BITS;				if (loopStart <= loopEnd)				{					for(i = 0; i < inst->samples; i++)					{						sample = &inst->sample[i];						sample->loop_start = loopStart;						sample->loop_end = loopEnd;						sample->modes |= loopMode;					}				}			}		}	}	if (marker_data != NULL)		free(marker_data);	close_file(tf);	return 0;}
4357	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4357/f07b17d6cb813000cb5ad3c2502ea8726afeac01/smplfile.c/buggy/timidity/smplfile.c