k = 0; spc = NULL;
k = kr = 0; spc = spr = NULL;
static int select_play_sample(Sample *splist,		int nsp, int note, int *vlist, MidiEvent *e){	int ch = e->channel, keynote = e->a & 0x7F;	int32 f, fs, ft, fst, fc, cdiff, diff, mindiff,	sample_link;	int8 tt = channel[ch].temper_type;	uint8 tp = channel[ch].rpnmap[RPN_ADDR_0003];	Sample *sp, *spc;	int16 st;	double ratio;	int i, j, k, nv, nvc, vel;		if (opt_pure_intonation) {		if (current_keysig < 8)			f = freq_table_pureint[current_freq_table][note];		else			f = freq_table_pureint[current_freq_table + 12][note];	} else if (opt_temper_control)		switch (tt) {		case 0:			f = freq_table_tuning[tp][note];			break;		case 1:			if (current_temper_keysig < 8)				f = freq_table_pytha[current_freq_table][note];			else				f = freq_table_pytha[current_freq_table + 12][note];			break;		case 2:			if (current_temper_keysig < 8)				f = freq_table_meantone[current_freq_table						+ ((temper_adj) ? 36 : 0)][note];			else				f = freq_table_meantone[current_freq_table						+ ((temper_adj) ? 24 : 12)][note];			break;		case 3:			if (current_temper_keysig < 8)				f = freq_table_pureint[current_freq_table						+ ((temper_adj) ? 36 : 0)][note];			else				f = freq_table_pureint[current_freq_table						+ ((temper_adj) ? 24 : 12)][note];			break;		default:	/* user-defined temperaments */			if ((tt -= 0x40) >= 0 && tt < 4) {				if (current_temper_keysig < 8)					f = freq_table_user[tt][current_freq_table							+ ((temper_adj) ? 36 : 0)][note];				else					f = freq_table_user[tt][current_freq_table							+ ((temper_adj) ? 24 : 12)][note];			} else				f = freq_table[note];			break;		}	else		f = freq_table[note];	if (opt_temper_control)		fs = (tt) ? freq_table[note] : freq_table_tuning[tp][note];	else		fs = freq_table[note];	vel = e->b;	nv = 0;	for (i = 0, sp = splist; i < nsp; i++, sp++) {		if ((st = sp->scale_tuning) != 100) {	/* SF2 - Scale Tuning */			ratio = (double)st / 100.0f;			ft = sp->root_freq + ((f - sp->root_freq) * ratio + 0.5),			fst = sp->root_freq + ((fs - sp->root_freq) * ratio + 0.5);		} else {ft = f, fst = fs;}		if(channel[ch].drums[keynote] != NULL			&& channel[ch].drums[keynote]->play_note != -1) {			ratio = (double)freq_table[channel[ch].drums[keynote]->play_note]				/ (double)sp->root_freq;			ft = ft * ratio + 0.5, fst = fst * ratio + 0.5;		}		ft_table[i] = ft;		fst_table[i] = fst;		if (sp->low_freq <= fst && sp->high_freq >= fst				&& sp->low_vel <= vel && sp->high_vel >= vel				&& !(sp->inst_type == INST_SF2 && sp->sample_type == SF_SAMPLETYPE_RIGHT)) {			j = vlist[nv] = find_voice(e);			voice[j].orig_frequency = ft;			MYCHECK(voice[j].orig_frequency);			voice[j].sample = sp;			voice[j].status = VOICE_ON;			nv++;		}	}	if (nv == 0) {	/* we must select at least one sample. */		for (i = 0, sp = splist; i < nsp; i++, sp++) {			diff = abs(sp->root_freq - fst_table[i]);			diff_table[i] = diff;		}		mindiff = 0x7fffffff;		k = 0;		spc = NULL;		for (i = 0, sp = splist; i < nsp; i++, sp++) {			diff = diff_table[i];			if (mindiff > diff) {				mindiff = diff;				k = i;				spc = sp;			}		}		j = vlist[nv] = find_voice(e);		voice[j].orig_frequency = ft_table[k];		MYCHECK(voice[j].orig_frequency);		voice[j].sample = spc;		voice[j].status = VOICE_ON;		nv++;	}	nvc = nv;	for (i = 0; i < nvc; i++)	{		spc = voice[vlist[i]].sample;		if (spc->inst_type == INST_SF2 &&			spc->sample_type == SF_SAMPLETYPE_LEFT) {			/* If it's left sample, there must be right sample. */			sample_link = spc->sf_sample_link;			for (j = 0, sp = splist; j < nsp; j++, sp++) {				if (sp->inst_type == INST_SF2 &&					sp->sample_type == SF_SAMPLETYPE_RIGHT &&					sp->sf_sample_index == sample_link) {					/* right sample is found. */					k = vlist[nv] = find_voice(e);					voice[k].orig_frequency = ft_table[j];					MYCHECK(voice[k].orig_frequency);					voice[k].sample = sp;					voice[k].status = VOICE_ON;					nv++;					break;				}			}		}	}	return nv;}