f = freq_table_meantone[current_freq_table
f = freq_table_meantone[current_temper_freq_table
static int select_play_sample(Sample *splist,		int nsp, int *note, int *vlist, MidiEvent *e){	int ch = e->channel, kn = e->a & 0x7f, vel = e->b;	int32 f, fs, ft, fst, fc, fr, cdiff, diff, sample_link;	int8 tt = channel[ch].temper_type;	uint8 tp = channel[ch].rpnmap[RPN_ADDR_0003];	Sample *sp, *spc, *spr;	int16 sf, sn;	double ratio;	int i, j, k, nv, nvc;		if (ISDRUMCHANNEL(ch))		f = fs = freq_table[*note];	else {		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 temperament */				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_pure_intonation && opt_temper_control				&& tt == 0 && f != freq_table[*note]) {			*note = log(f / 440000.0) / log(2) * 12 + 69.5;			*note = (*note < 0) ? 0 : ((*note > 127) ? 127 : *note);			fs = freq_table[*note];		} else			fs = freq_table[*note];	}	nv = 0;	for (i = 0, sp = splist; i < nsp; i++, sp++) {		/* GUS/SF2 - Scale Tuning */		if ((sf = sp->scale_factor) != 1024) {			sn = sp->scale_freq;			ratio = pow(2.0, (*note - sn) * (sf - 1024) / 12288.0);			ft = f * ratio + 0.5, fst = fs * ratio + 0.5;		} else			ft = f, fst = fs;		if (ISDRUMCHANNEL(ch) && channel[ch].drums[kn] != NULL)			if ((ratio = get_play_note_ratio(ch, kn)) != 1.0)				ft = ft * ratio + 0.5, fst = fst * ratio + 0.5;		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. */		fr = fc = 0;		spc = spr = NULL;		cdiff = 0x7fffffff;		for (i = 0, sp = splist; i < nsp; i++, sp++) {			/* GUS/SF2 - Scale Tuning */			if ((sf = sp->scale_factor) != 1024) {				sn = sp->scale_freq;				ratio = pow(2.0, (*note - sn) * (sf - 1024) / 12288.0);				ft = f * ratio + 0.5, fst = fs * ratio + 0.5;			} else				ft = f, fst = fs;			if (ISDRUMCHANNEL(ch) && channel[ch].drums[kn] != NULL)				if ((ratio = get_play_note_ratio(ch, kn)) != 1.0)					ft = ft * ratio + 0.5, fst = fst * ratio + 0.5;			diff = abs(sp->root_freq - fst);			if (diff < cdiff) {				if (sp->inst_type == INST_SF2						&& sp->sample_type == SF_SAMPLETYPE_RIGHT) {					fr = ft;	/* reserve */					spr = sp;	/* reserve */				} else {					fc = ft;					spc = sp;					cdiff = diff;				}			}		}		/* If spc is not NULL, a makeshift sample is found. */		/* Otherwise, it's a lonely right sample, but better than nothing. */		j = vlist[nv] = find_voice(e);		voice[j].orig_frequency = (spc) ? fc : fr;		MYCHECK(voice[j].orig_frequency);		voice[j].sample = (spc) ? spc : spr;		voice[j].status = VOICE_ON;		nv++;	}	nvc = nv;	for (i = 0; i < nvc; i++) {		spc = voice[vlist[i]].sample;		/* If it's left sample, there must be right sample. */		if (spc->inst_type == INST_SF2				&& spc->sample_type == SF_SAMPLETYPE_LEFT) {			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. */					/* GUS/SF2 - Scale Tuning */					if ((sf = sp->scale_factor) != 1024) {						sn = sp->scale_freq;						ratio = pow(2.0, (*note - sn) * (sf - 1024) / 12288.0);						ft = f * ratio + 0.5;					} else						ft = f;					if (ISDRUMCHANNEL(ch) && channel[ch].drums[kn] != NULL)						if ((ratio = get_play_note_ratio(ch, kn)) != 1.0)							ft = ft * ratio + 0.5;					k = vlist[nv] = find_voice(e);					voice[k].orig_frequency = ft;					MYCHECK(voice[k].orig_frequency);					voice[k].sample = sp;					voice[k].status = VOICE_ON;					nv++;					break;				}		}	}	return nv;}