$OpenBSD: patch-playercode_mplayer_c,v 1.4 2002/12/24 21:42:13 pvalchev Exp $
--- playercode/mplayer.c.orig	Mon Jan 21 14:23:56 2002
+++ playercode/mplayer.c	Tue Dec 24 13:45:20 2002
@@ -254,7 +254,7 @@ static int MP_FindEmptyChannel(MODULE *m
 		   Voice_Stopped_internal(t))
 			return t;
 
-	tvol=0xffffffUL;t=0;a=mod->voice;
+	tvol=0xffffffUL;t=-1;a=mod->voice;
 	for (k=0;k<md_sngchn;k++,a++) {
 		/* allow us to take over a nonexisting sample */
 		if (!a->main.s)
@@ -442,24 +442,22 @@ static SWORD ProcessEnvelope(MP_VOICE *a
 			} else
 			/*
 			 * Non looping situations.
-			 * Start to fade if the volume envelope is finished.
 			 */
-			if (p > t->env[t->pts - 1].pos) {
+			if (a != b)
+				v = InterpolateEnv(p, &t->env[a], &t->env[b]);
+			else
 				v = t->env[a].val;
+
+			/*
+			 * Start to fade if the volume envelope is finished.
+			 */
+			if (p >= t->env[t->pts - 1].pos) {
 				if (t->flg & EF_VOLENV) {
 					aout->main.keyoff |= KEY_FADE;
 					if (!v)
 						aout->main.fadevol = 0;
 				}
 			} else {
-				/*
-				 * Regular processing : compute value, progress one step.
-				 */
-				if (a != b)
-					v = InterpolateEnv(p, &t->env[a], &t->env[b]);
-				else
-					v = t->env[a].val;
-
 				p++;
 				/* did pointer reach point b? */
 				if (p >= t->env[b].pos)
