/* terminate most inactive voice and give it as a pcm voice.  */
int snd_emu10k1_synth_get_voice(struct snd_emu10k1 *hw)
/* terminate most inactive voice and give it as a pcm voice.  */
int snd_emu10k1_synth_get_voice(struct snd_emu10k1 *hw)
{
	struct snd_emux *emu;
	struct snd_emux_voice *vp;
	struct best_voice best[V_END];
	unsigned long flags;
	int i;
	emu = hw->synth;
	spin_lock_irqsave(&emu->voice_lock, flags);
	lookup_voices(emu, hw, best, 1);
	for (i = 0; i < V_END; i++) {
		if (best[i].voice >= 0) {
			int ch;
			vp = &emu->voices[best[i].voice];
			if ((ch = vp->ch) < 0) {
				continue;
			}
			vp->emu->num_voices--;
			vp->ch = -1;
			vp->state = SNDRV_EMUX_ST_OFF;
			spin_unlock_irqrestore(&emu->voice_lock, flags);
			return ch;
		}
	}
	spin_unlock_irqrestore(&emu->voice_lock, flags);
	return -ENOMEM;
}