/* convert envelope parameters */ sample->envelope_offset[0] = to_offset(65535); sample->envelope_rate[0] = sp->attack;  sample->envelope_offset[1] = to_offset(65534); sample->envelope_rate[1] = sp->hold;  sample->envelope_offset[2] = to_offset(sp->sustain); sample->envelope_rate[2] = sp->decay;  sample->envelope_offset[3] = 0; sample->envelope_rate[3] = sp->release;  sample->envelope_offset[4] = 0; sample->envelope_rate[4] = sp->release;  sample->envelope_offset[5] = 0; sample->envelope_rate[5] = sp->release;  /* convert modulation envelope parameters */ sample->modenv_offset[0] = to_offset(65535); sample->modenv_rate[0] = sp->modattack;  sample->modenv_offset[1] = to_offset(65534); sample->modenv_rate[1] = sp->modhold;  sample->modenv_offset[2] = to_offset(sp->modsustain); sample->modenv_rate[2] = sp->moddecay;  sample->modenv_offset[3] = 0; sample->modenv_rate[3] = sp->modrelease;  sample->modenv_offset[4] = 0; sample->modenv_rate[4] = sp->modrelease;  sample->modenv_offset[5] = 0; sample->modenv_rate[5] = sp->modrelease;  
static Instrument *load_from_file(SFInsts *rec, InstList *ip){	SampleList *sp;	Instrument *inst;	int i;	int32 len;	if(ip->pat.bank == 128)	    ctl->cmsg(CMSG_INFO, VERB_NOISY,		      "Loading SF Drumset %d %d: %s",		      ip->pat.preset + progbase, ip->pat.keynote,		      rec->inst_namebuf[ip->pr_idx]);	else	    ctl->cmsg(CMSG_INFO, VERB_NOISY,		      "Loading SF Tonebank %d %d: %s",		      ip->pat.bank, ip->pat.preset + progbase,		      rec->inst_namebuf[ip->pr_idx]);	inst = (Instrument *)safe_malloc(sizeof(Instrument));/*	inst->instname = (char *)safe_malloc(strlen(rec->inst_namebuf[ip->pr_idx]));	strcpy(inst->instname,rec->inst_namebuf[ip->pr_idx]);*/	inst->instname = rec->inst_namebuf[ip->pr_idx];	inst->type = INST_SF2;	inst->samples = ip->samples;	inst->sample = (Sample *)safe_malloc(sizeof(Sample) * ip->samples);	memset(inst->sample, 0, sizeof(Sample) * ip->samples);	for (i = 0, sp = ip->slist; i < ip->samples && sp; i++, sp = sp->next) {		Sample *sample = inst->sample + i;		int32 j;#ifndef LITTLE_ENDIAN		int32 k;		int16 *tmp, s;#endif		ctl->cmsg(CMSG_INFO, VERB_DEBUG,			  "[%d] Rate=%d LV=%d HV=%d "			  "Low=%d Hi=%d Root=%d Pan=%d",			  sp->start, sp->v.sample_rate, 			  sp->v.low_vel, sp->v.high_vel, 			  sp->v.low_freq, sp->v.high_freq, sp->v.root_freq,			  sp->v.panning);		memcpy(sample, &sp->v, sizeof(Sample));		/* convert envelope parameters */		sample->envelope_offset[0] = to_offset(65535);		sample->envelope_rate[0] = sp->attack;		sample->envelope_offset[1] = to_offset(65534);		sample->envelope_rate[1] = sp->hold;		sample->envelope_offset[2] = to_offset(sp->sustain);		sample->envelope_rate[2] = sp->decay;		sample->envelope_offset[3] = 0;		sample->envelope_rate[3] = sp->release;		sample->envelope_offset[4] = 0;		sample->envelope_rate[4] = sp->release;		sample->envelope_offset[5] = 0;		sample->envelope_rate[5] = sp->release;		/* convert modulation envelope parameters */		sample->modenv_offset[0] = to_offset(65535);		sample->modenv_rate[0] = sp->modattack;		sample->modenv_offset[1] = to_offset(65534);		sample->modenv_rate[1] = sp->modhold;		sample->modenv_offset[2] = to_offset(sp->modsustain);		sample->modenv_rate[2] = sp->moddecay;		sample->modenv_offset[3] = 0;		sample->modenv_rate[3] = sp->modrelease;		sample->modenv_offset[4] = 0;		sample->modenv_rate[4] = sp->modrelease;		sample->modenv_offset[5] = 0;		sample->modenv_rate[5] = sp->modrelease;		if(i > 0 && (!sample->note_to_use ||			     (sample->modes & MODES_LOOPING)))		{		    SampleList *sps;		    Sample *found, *s;		    found = NULL;		    for(j = 0, sps = ip->slist, s = inst->sample; j < i && sps;			j++, sps = sps->next, s++)		    {			if(s->data == NULL)			    break;			if(sp->start == sps->start)			{			    if(sp->cutoff_freq != sps->cutoff_freq ||			       sp->resonance != sps->resonance)				continue;			    if(antialiasing_allowed)			    {				 if(sample->data_length != s->data_length ||				    sample->sample_rate != s->sample_rate)				     continue;			    }			    if(s->note_to_use && !(s->modes & MODES_LOOPING))				continue;			    found = s;			    break;			}		    }		    if(found)		    {			sample->data = found->data;			sample->data_alloced = 0;			ctl->cmsg(CMSG_INFO, VERB_DEBUG, " * Cached");			continue;		    }		}		sample->data = (sample_t *)safe_malloc(sp->len + 2 * 3);		sample->data_alloced = 1;		ctl->cmsg(CMSG_INFO, VERB_DEBUG_SILLY,			  "Data: %d %d V=%g, envofs: %d %d %d %d %d %d",			  sp->start, sp->start + sp->len,			  sample->volume,			  sample->envelope_offset[0] >> 22,			  sample->envelope_offset[1] >> 22,			  sample->envelope_offset[2] >> 22,			  sample->envelope_offset[3] >> 22,			  sample->envelope_offset[4] >> 22,			  sample->envelope_offset[5] >> 22);		tf_seek(rec->tf, sp->start, SEEK_SET);		tf_read(sample->data, sp->len, 1, rec->tf);#ifndef LITTLE_ENDIAN		tmp = (int16*)sample->data;		k = sp->len / 2;		for (j = 0; j < k; j++) {			s = LE_SHORT(*tmp);			*tmp++ = s;		}#endif		/* set a small blank loop at the tail for avoiding abnormal loop. */		len = sp->len / 2;		sample->data[len] = sample->data[len + 1] = sample->data[len + 2] = 0;		if(sp->cutoff_freq > 0) {sample->cutoff_freq = sp->cutoff_freq;}		if(sp->resonance > 0) {sample->resonance = sp->resonance;}		if (antialiasing_allowed)		    antialiasing((int16 *)sample->data,				 sample->data_length >> FRACTION_BITS,				 sample->sample_rate,				 play_mode->rate);		/* resample it if possible */		if (sample->note_to_use && !(sample->modes & MODES_LOOPING))			pre_resample(sample);#ifdef LOOKUP_HACK		/* squash the 16-bit data into 8 bits. */		{			uint8 *gulp,*ulp;			int16 *swp;			int l = sample->data_length >> FRACTION_BITS;			gulp = ulp = (uint8 *)safe_malloc(l + 1);			swp = (int16 *)sample->data;			while (l--)				*ulp++ = (*swp++ >> 8) & 0xFF;			free(sample->data);			sample->data=(sample_t *)gulp;		}#endif	}	return inst;}
4357	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4357/6158fd5fefa958969b8c6a163c85781e3fd80559/sndfont.c/buggy/timidity/sndfont.c