

/* THIS CODE IS AUTOGENERATED FROM '/build/xmms2/src/xmms2-0.9.5/_build_/../src/xmms/converter.genpy'
 *                   ** DO NOT EDIT **
 */

#include "converter.head.c"

#define READu8(a)  (((guint32)((a)               )) << 24)
#define READs8(a)  (((guint32)((a) +          128)) << 24)
#define READu16(a) (((guint32)((a)               )) << 16)
#define READs16(a) (((guint32)((a) +        32768)) << 16)
#define READs32(a) (((guint32)((a) + 2147483648UL))      )
#define READfloat(a) (((a) + 1.0)*2147483648UL)

#define WRITEu8(a)  ((a) >> 24)
#define WRITEs8(a)  (((a) >> 24) - 128)
#define WRITEu16(a) ((a) >> 16)
#define WRITEs16(a) (((a) >> 16) - 32768)
#define WRITEs32(a) ((a) - 2147483648UL)
#define WRITEfloat(a) ((a)/2147483648.0 - 1.0)





static guint
resample_1_u8_to_1_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u8_to_1_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_u8_to_1_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u8_to_1_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_u8_to_1_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u8_to_1_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_u8_to_1_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u8_to_1_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_u8_to_1_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u8_to_1_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_u8_to_1_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u8_to_1_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s8_to_1_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s8_to_1_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s8_to_1_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s8_to_1_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s8_to_1_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s8_to_1_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s8_to_1_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s8_to_1_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s8_to_1_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s8_to_1_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s8_to_1_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s8_to_1_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_u16_to_1_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u16_to_1_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_u16_to_1_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u16_to_1_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_u16_to_1_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u16_to_1_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_u16_to_1_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u16_to_1_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_u16_to_1_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u16_to_1_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_u16_to_1_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u16_to_1_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s16_to_1_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s16_to_1_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s16_to_1_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s16_to_1_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s16_to_1_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s16_to_1_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s16_to_1_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s16_to_1_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s16_to_1_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s16_to_1_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s16_to_1_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s16_to_1_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s32_to_1_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s32_to_1_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s32_to_1_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s32_to_1_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s32_to_1_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s32_to_1_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s32_to_1_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s32_to_1_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s32_to_1_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s32_to_1_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s32_to_1_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s32_to_1_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_float_to_1_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_float_to_1_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_float_to_1_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_float_to_1_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_float_to_1_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_float_to_1_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_float_to_1_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_float_to_1_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_float_to_1_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_float_to_1_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_float_to_1_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_float_to_1_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);

		out = &out[1];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_u8_to_2_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u8_to_2_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_u8_to_2_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u8_to_2_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_u8_to_2_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u8_to_2_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_u8_to_2_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u8_to_2_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_u8_to_2_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u8_to_2_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_u8_to_2_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u8_to_2_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s8_to_2_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s8_to_2_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s8_to_2_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s8_to_2_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s8_to_2_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s8_to_2_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s8_to_2_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s8_to_2_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s8_to_2_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s8_to_2_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s8_to_2_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s8_to_2_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_u16_to_2_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u16_to_2_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_u16_to_2_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u16_to_2_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_u16_to_2_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u16_to_2_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_u16_to_2_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u16_to_2_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_u16_to_2_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u16_to_2_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_u16_to_2_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_u16_to_2_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s16_to_2_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s16_to_2_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s16_to_2_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s16_to_2_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s16_to_2_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s16_to_2_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s16_to_2_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s16_to_2_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s16_to_2_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s16_to_2_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s16_to_2_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s16_to_2_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s32_to_2_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s32_to_2_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s32_to_2_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s32_to_2_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s32_to_2_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s32_to_2_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s32_to_2_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s32_to_2_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s32_to_2_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s32_to_2_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_s32_to_2_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_s32_to_2_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_float_to_2_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_float_to_2_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_float_to_2_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_float_to_2_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_float_to_2_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_float_to_2_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_float_to_2_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_float_to_2_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_float_to_2_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_float_to_2_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_1_float_to_2_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[1];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[1 * (ipos - 1)];
		}
		buf2 = &buf[1 * ipos];

		/* resample */
		for (i = 0; i < 1; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[0]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 1; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[1*(len-1) + i];
	}
	return n;
}

static guint
convert_1_float_to_2_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[1];

		for (j = 0; j < 1; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[0]);

		out = &out[2];
		in = &in[1];
	}
	return len;
}




static guint
resample_2_u8_to_1_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u8_to_1_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_u8_to_1_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u8_to_1_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_u8_to_1_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u8_to_1_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_u8_to_1_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u8_to_1_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_u8_to_1_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u8_to_1_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_u8_to_1_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u8_to_1_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s8_to_1_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s8_to_1_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s8_to_1_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s8_to_1_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s8_to_1_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s8_to_1_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s8_to_1_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s8_to_1_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s8_to_1_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s8_to_1_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s8_to_1_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s8_to_1_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_u16_to_1_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u16_to_1_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_u16_to_1_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u16_to_1_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_u16_to_1_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u16_to_1_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_u16_to_1_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u16_to_1_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_u16_to_1_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u16_to_1_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_u16_to_1_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u16_to_1_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s16_to_1_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s16_to_1_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s16_to_1_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s16_to_1_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s16_to_1_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s16_to_1_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s16_to_1_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s16_to_1_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s16_to_1_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s16_to_1_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s16_to_1_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s16_to_1_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s32_to_1_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s32_to_1_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s32_to_1_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s32_to_1_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s32_to_1_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s32_to_1_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s32_to_1_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s32_to_1_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s32_to_1_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s32_to_1_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s32_to_1_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s32_to_1_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_float_to_1_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_float_to_1_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_float_to_1_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_float_to_1_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_float_to_1_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_float_to_1_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_float_to_1_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_float_to_1_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_float_to_1_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_float_to_1_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_float_to_1_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[1 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat((temp[0] + temp[1])/2);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_float_to_1_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat((temp[0] + temp[1])/2);

		out = &out[1];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_u8_to_2_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u8_to_2_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_u8_to_2_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u8_to_2_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_u8_to_2_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u8_to_2_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_u8_to_2_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u8_to_2_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_u8_to_2_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u8_to_2_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_u8_to_2_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu8_t *buf = (xmms_sampleu8_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu8 (buf1[i]) + bfrac * READu8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u8_to_2_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu8_t *in = (xmms_sampleu8_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s8_to_2_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s8_to_2_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s8_to_2_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s8_to_2_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s8_to_2_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s8_to_2_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s8_to_2_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s8_to_2_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s8_to_2_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s8_to_2_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s8_to_2_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples8_t *buf = (xmms_samples8_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples8_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples8_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs8 (buf1[i]) + bfrac * READs8 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples8_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s8_to_2_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples8_t *in = (xmms_samples8_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs8 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_u16_to_2_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u16_to_2_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_u16_to_2_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u16_to_2_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_u16_to_2_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u16_to_2_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_u16_to_2_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u16_to_2_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_u16_to_2_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u16_to_2_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_u16_to_2_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_sampleu16_t *buf = (xmms_sampleu16_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_sampleu16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_sampleu16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READu16 (buf1[i]) + bfrac * READu16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_sampleu16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_u16_to_2_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_sampleu16_t *in = (xmms_sampleu16_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READu16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s16_to_2_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s16_to_2_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s16_to_2_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s16_to_2_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s16_to_2_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s16_to_2_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s16_to_2_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s16_to_2_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s16_to_2_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s16_to_2_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s16_to_2_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples16_t *buf = (xmms_samples16_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples16_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples16_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs16 (buf1[i]) + bfrac * READs16 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples16_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s16_to_2_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples16_t *in = (xmms_samples16_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs16 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s32_to_2_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s32_to_2_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s32_to_2_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s32_to_2_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s32_to_2_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s32_to_2_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s32_to_2_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s32_to_2_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s32_to_2_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s32_to_2_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_s32_to_2_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samples32_t *buf = (xmms_samples32_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samples32_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samples32_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READs32 (buf1[i]) + bfrac * READs32 (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samples32_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_s32_to_2_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samples32_t *in = (xmms_samples32_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READs32 (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_float_to_2_u8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_sampleu8_t *outbuf = (xmms_sampleu8_t *) tout;
	xmms_sampleu8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_float_to_2_u8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_sampleu8_t *out = (xmms_sampleu8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu8(temp[0]);
		out[1] = WRITEu8(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_float_to_2_s8 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_samples8_t *outbuf = (xmms_samples8_t *) tout;
	xmms_samples8_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_float_to_2_s8 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_samples8_t *out = (xmms_samples8_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs8(temp[0]);
		out[1] = WRITEs8(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_float_to_2_u16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_sampleu16_t *outbuf = (xmms_sampleu16_t *) tout;
	xmms_sampleu16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_float_to_2_u16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_sampleu16_t *out = (xmms_sampleu16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEu16(temp[0]);
		out[1] = WRITEu16(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_float_to_2_s16 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_samples16_t *outbuf = (xmms_samples16_t *) tout;
	xmms_samples16_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_float_to_2_s16 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_samples16_t *out = (xmms_samples16_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs16(temp[0]);
		out[1] = WRITEs16(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_float_to_2_s32 (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_samples32_t *outbuf = (xmms_samples32_t *) tout;
	xmms_samples32_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_float_to_2_s32 (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_samples32_t *out = (xmms_samples32_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEs32(temp[0]);
		out[1] = WRITEs32(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static guint
resample_2_float_to_2_float (xmms_sample_converter_t *conv, xmms_sample_t *tbuf, guint len, xmms_sample_t *tout)
{
	xmms_samplefloat_t *buf = (xmms_samplefloat_t *) tbuf;
	xmms_samplefloat_t *outbuf = (xmms_samplefloat_t *) tout;
	xmms_samplefloat_t *out;
	guint pos, ipos;
	gint i, n=0;

	pos = conv->offset;

	while (pos < len * conv->interpolator_ratio) {
		guint32 temp[2];
		xmms_samplefloat_t *buf1, *buf2;
		gfloat bfrac = ((gfloat) (pos % (conv->interpolator_ratio))) / (conv->interpolator_ratio);
		gfloat afrac = 1.0 - bfrac;

		ipos = pos / conv->interpolator_ratio;

		if (ipos < 1) {
			buf1 = (xmms_samplefloat_t *)conv->state;
		} else {
			buf1 = &buf[2 * (ipos - 1)];
		}
		buf2 = &buf[2 * ipos];

		/* resample */
		for (i = 0; i < 2; i++) {
			temp[i] = afrac * READfloat (buf1[i]) + bfrac * READfloat (buf2[i]);
		}

		out = &outbuf[2 * n];
		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[1]);


		n++;
		pos += conv->decimator_ratio;
	}

	conv->offset = pos - len * conv->interpolator_ratio;

	for (i = 0; i < 2; i++) {
		((xmms_samplefloat_t *)conv->state)[i] = buf[2*(len-1) + i];
	}
	return n;
}

static guint
convert_2_float_to_2_float (xmms_sample_converter_t *conv, void *tin, guint len, void *tout)
{
	xmms_samplefloat_t *in = (xmms_samplefloat_t *)tin;
	xmms_samplefloat_t *out = (xmms_samplefloat_t *)tout;
	gint i, j;

	/* this code doesn't look optimized,
	but the compiler should fix that */
	for (i = 0; i < len; i++) {
		guint32 temp[2];

		for (j = 0; j < 2; j++) {
			temp[j] = READfloat (in[j]);
		}

		/* convert #channels into out[] */
		out[0] = WRITEfloat(temp[0]);
		out[1] = WRITEfloat(temp[1]);

		out = &out[2];
		in = &in[2];
	}
	return len;
}




static xmms_sample_conv_func_t
xmms_sample_conv_get (guint inchannels, xmms_sample_format_t intype,
                      guint outchannels, xmms_sample_format_t outtype,
                      gboolean resample)
{
	switch(inchannels){
	default: return NULL;
	case 1:
		switch(outchannels){
		default: return NULL;
		case 1:
			switch(intype){
			default: return NULL;
			case XMMS_SAMPLE_FORMAT_U8:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_1_u8_to_1_u8 : convert_1_u8_to_1_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_1_u8_to_1_s8 : convert_1_u8_to_1_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_1_u8_to_1_u16 : convert_1_u8_to_1_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_1_u8_to_1_s16 : convert_1_u8_to_1_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_1_u8_to_1_s32 : convert_1_u8_to_1_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_1_u8_to_1_float : convert_1_u8_to_1_float;
				}
			case XMMS_SAMPLE_FORMAT_S8:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_1_s8_to_1_u8 : convert_1_s8_to_1_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_1_s8_to_1_s8 : convert_1_s8_to_1_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_1_s8_to_1_u16 : convert_1_s8_to_1_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_1_s8_to_1_s16 : convert_1_s8_to_1_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_1_s8_to_1_s32 : convert_1_s8_to_1_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_1_s8_to_1_float : convert_1_s8_to_1_float;
				}
			case XMMS_SAMPLE_FORMAT_U16:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_1_u16_to_1_u8 : convert_1_u16_to_1_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_1_u16_to_1_s8 : convert_1_u16_to_1_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_1_u16_to_1_u16 : convert_1_u16_to_1_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_1_u16_to_1_s16 : convert_1_u16_to_1_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_1_u16_to_1_s32 : convert_1_u16_to_1_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_1_u16_to_1_float : convert_1_u16_to_1_float;
				}
			case XMMS_SAMPLE_FORMAT_S16:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_1_s16_to_1_u8 : convert_1_s16_to_1_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_1_s16_to_1_s8 : convert_1_s16_to_1_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_1_s16_to_1_u16 : convert_1_s16_to_1_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_1_s16_to_1_s16 : convert_1_s16_to_1_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_1_s16_to_1_s32 : convert_1_s16_to_1_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_1_s16_to_1_float : convert_1_s16_to_1_float;
				}
			case XMMS_SAMPLE_FORMAT_S32:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_1_s32_to_1_u8 : convert_1_s32_to_1_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_1_s32_to_1_s8 : convert_1_s32_to_1_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_1_s32_to_1_u16 : convert_1_s32_to_1_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_1_s32_to_1_s16 : convert_1_s32_to_1_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_1_s32_to_1_s32 : convert_1_s32_to_1_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_1_s32_to_1_float : convert_1_s32_to_1_float;
				}
			case XMMS_SAMPLE_FORMAT_FLOAT:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_1_float_to_1_u8 : convert_1_float_to_1_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_1_float_to_1_s8 : convert_1_float_to_1_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_1_float_to_1_u16 : convert_1_float_to_1_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_1_float_to_1_s16 : convert_1_float_to_1_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_1_float_to_1_s32 : convert_1_float_to_1_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_1_float_to_1_float : convert_1_float_to_1_float;
				}
			}
		case 2:
			switch(intype){
			default: return NULL;
			case XMMS_SAMPLE_FORMAT_U8:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_1_u8_to_2_u8 : convert_1_u8_to_2_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_1_u8_to_2_s8 : convert_1_u8_to_2_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_1_u8_to_2_u16 : convert_1_u8_to_2_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_1_u8_to_2_s16 : convert_1_u8_to_2_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_1_u8_to_2_s32 : convert_1_u8_to_2_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_1_u8_to_2_float : convert_1_u8_to_2_float;
				}
			case XMMS_SAMPLE_FORMAT_S8:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_1_s8_to_2_u8 : convert_1_s8_to_2_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_1_s8_to_2_s8 : convert_1_s8_to_2_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_1_s8_to_2_u16 : convert_1_s8_to_2_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_1_s8_to_2_s16 : convert_1_s8_to_2_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_1_s8_to_2_s32 : convert_1_s8_to_2_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_1_s8_to_2_float : convert_1_s8_to_2_float;
				}
			case XMMS_SAMPLE_FORMAT_U16:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_1_u16_to_2_u8 : convert_1_u16_to_2_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_1_u16_to_2_s8 : convert_1_u16_to_2_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_1_u16_to_2_u16 : convert_1_u16_to_2_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_1_u16_to_2_s16 : convert_1_u16_to_2_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_1_u16_to_2_s32 : convert_1_u16_to_2_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_1_u16_to_2_float : convert_1_u16_to_2_float;
				}
			case XMMS_SAMPLE_FORMAT_S16:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_1_s16_to_2_u8 : convert_1_s16_to_2_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_1_s16_to_2_s8 : convert_1_s16_to_2_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_1_s16_to_2_u16 : convert_1_s16_to_2_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_1_s16_to_2_s16 : convert_1_s16_to_2_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_1_s16_to_2_s32 : convert_1_s16_to_2_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_1_s16_to_2_float : convert_1_s16_to_2_float;
				}
			case XMMS_SAMPLE_FORMAT_S32:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_1_s32_to_2_u8 : convert_1_s32_to_2_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_1_s32_to_2_s8 : convert_1_s32_to_2_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_1_s32_to_2_u16 : convert_1_s32_to_2_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_1_s32_to_2_s16 : convert_1_s32_to_2_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_1_s32_to_2_s32 : convert_1_s32_to_2_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_1_s32_to_2_float : convert_1_s32_to_2_float;
				}
			case XMMS_SAMPLE_FORMAT_FLOAT:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_1_float_to_2_u8 : convert_1_float_to_2_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_1_float_to_2_s8 : convert_1_float_to_2_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_1_float_to_2_u16 : convert_1_float_to_2_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_1_float_to_2_s16 : convert_1_float_to_2_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_1_float_to_2_s32 : convert_1_float_to_2_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_1_float_to_2_float : convert_1_float_to_2_float;
				}
			}
		}
	case 2:
		switch(outchannels){
		default: return NULL;
		case 1:
			switch(intype){
			default: return NULL;
			case XMMS_SAMPLE_FORMAT_U8:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_2_u8_to_1_u8 : convert_2_u8_to_1_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_2_u8_to_1_s8 : convert_2_u8_to_1_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_2_u8_to_1_u16 : convert_2_u8_to_1_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_2_u8_to_1_s16 : convert_2_u8_to_1_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_2_u8_to_1_s32 : convert_2_u8_to_1_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_2_u8_to_1_float : convert_2_u8_to_1_float;
				}
			case XMMS_SAMPLE_FORMAT_S8:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_2_s8_to_1_u8 : convert_2_s8_to_1_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_2_s8_to_1_s8 : convert_2_s8_to_1_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_2_s8_to_1_u16 : convert_2_s8_to_1_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_2_s8_to_1_s16 : convert_2_s8_to_1_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_2_s8_to_1_s32 : convert_2_s8_to_1_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_2_s8_to_1_float : convert_2_s8_to_1_float;
				}
			case XMMS_SAMPLE_FORMAT_U16:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_2_u16_to_1_u8 : convert_2_u16_to_1_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_2_u16_to_1_s8 : convert_2_u16_to_1_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_2_u16_to_1_u16 : convert_2_u16_to_1_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_2_u16_to_1_s16 : convert_2_u16_to_1_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_2_u16_to_1_s32 : convert_2_u16_to_1_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_2_u16_to_1_float : convert_2_u16_to_1_float;
				}
			case XMMS_SAMPLE_FORMAT_S16:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_2_s16_to_1_u8 : convert_2_s16_to_1_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_2_s16_to_1_s8 : convert_2_s16_to_1_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_2_s16_to_1_u16 : convert_2_s16_to_1_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_2_s16_to_1_s16 : convert_2_s16_to_1_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_2_s16_to_1_s32 : convert_2_s16_to_1_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_2_s16_to_1_float : convert_2_s16_to_1_float;
				}
			case XMMS_SAMPLE_FORMAT_S32:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_2_s32_to_1_u8 : convert_2_s32_to_1_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_2_s32_to_1_s8 : convert_2_s32_to_1_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_2_s32_to_1_u16 : convert_2_s32_to_1_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_2_s32_to_1_s16 : convert_2_s32_to_1_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_2_s32_to_1_s32 : convert_2_s32_to_1_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_2_s32_to_1_float : convert_2_s32_to_1_float;
				}
			case XMMS_SAMPLE_FORMAT_FLOAT:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_2_float_to_1_u8 : convert_2_float_to_1_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_2_float_to_1_s8 : convert_2_float_to_1_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_2_float_to_1_u16 : convert_2_float_to_1_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_2_float_to_1_s16 : convert_2_float_to_1_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_2_float_to_1_s32 : convert_2_float_to_1_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_2_float_to_1_float : convert_2_float_to_1_float;
				}
			}
		case 2:
			switch(intype){
			default: return NULL;
			case XMMS_SAMPLE_FORMAT_U8:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_2_u8_to_2_u8 : convert_2_u8_to_2_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_2_u8_to_2_s8 : convert_2_u8_to_2_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_2_u8_to_2_u16 : convert_2_u8_to_2_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_2_u8_to_2_s16 : convert_2_u8_to_2_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_2_u8_to_2_s32 : convert_2_u8_to_2_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_2_u8_to_2_float : convert_2_u8_to_2_float;
				}
			case XMMS_SAMPLE_FORMAT_S8:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_2_s8_to_2_u8 : convert_2_s8_to_2_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_2_s8_to_2_s8 : convert_2_s8_to_2_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_2_s8_to_2_u16 : convert_2_s8_to_2_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_2_s8_to_2_s16 : convert_2_s8_to_2_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_2_s8_to_2_s32 : convert_2_s8_to_2_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_2_s8_to_2_float : convert_2_s8_to_2_float;
				}
			case XMMS_SAMPLE_FORMAT_U16:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_2_u16_to_2_u8 : convert_2_u16_to_2_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_2_u16_to_2_s8 : convert_2_u16_to_2_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_2_u16_to_2_u16 : convert_2_u16_to_2_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_2_u16_to_2_s16 : convert_2_u16_to_2_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_2_u16_to_2_s32 : convert_2_u16_to_2_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_2_u16_to_2_float : convert_2_u16_to_2_float;
				}
			case XMMS_SAMPLE_FORMAT_S16:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_2_s16_to_2_u8 : convert_2_s16_to_2_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_2_s16_to_2_s8 : convert_2_s16_to_2_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_2_s16_to_2_u16 : convert_2_s16_to_2_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_2_s16_to_2_s16 : convert_2_s16_to_2_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_2_s16_to_2_s32 : convert_2_s16_to_2_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_2_s16_to_2_float : convert_2_s16_to_2_float;
				}
			case XMMS_SAMPLE_FORMAT_S32:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_2_s32_to_2_u8 : convert_2_s32_to_2_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_2_s32_to_2_s8 : convert_2_s32_to_2_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_2_s32_to_2_u16 : convert_2_s32_to_2_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_2_s32_to_2_s16 : convert_2_s32_to_2_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_2_s32_to_2_s32 : convert_2_s32_to_2_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_2_s32_to_2_float : convert_2_s32_to_2_float;
				}
			case XMMS_SAMPLE_FORMAT_FLOAT:
				switch(outtype){
				default: return NULL;
				case XMMS_SAMPLE_FORMAT_U8:
					return resample ? resample_2_float_to_2_u8 : convert_2_float_to_2_u8;
				case XMMS_SAMPLE_FORMAT_S8:
					return resample ? resample_2_float_to_2_s8 : convert_2_float_to_2_s8;
				case XMMS_SAMPLE_FORMAT_U16:
					return resample ? resample_2_float_to_2_u16 : convert_2_float_to_2_u16;
				case XMMS_SAMPLE_FORMAT_S16:
					return resample ? resample_2_float_to_2_s16 : convert_2_float_to_2_s16;
				case XMMS_SAMPLE_FORMAT_S32:
					return resample ? resample_2_float_to_2_s32 : convert_2_float_to_2_s32;
				case XMMS_SAMPLE_FORMAT_FLOAT:
					return resample ? resample_2_float_to_2_float : convert_2_float_to_2_float;
				}
			}
		}
	}

	return NULL;
}
