Blame src/libmpg123/synth_mono.h

Packit c32a2d
/*
Packit c32a2d
	monosynth.h: generic mono related synth functions 
Packit c32a2d
Packit c32a2d
	copyright 1995-2008 by the mpg123 project - free software under the terms of the LGPL 2.1
Packit c32a2d
	see COPYING and AUTHORS files in distribution or http://mpg123.org
Packit c32a2d
	initially written by Michael Hipp, generalized by Thomas Orgis
Packit c32a2d
Packit c32a2d
	This header is used multiple times to create different variants of these functions.
Packit c32a2d
	See decode.c and synth.h .
Packit c32a2d
	Hint: BLOCK, MONO_NAME, MONO2STEREO_NAME, SYNTH_NAME and SAMPLE_T do vary.
Packit c32a2d
Packit c32a2d
	Thomas looked closely at the decode_1to1, decode_2to1 and decode_4to1 contents, seeing that they are too similar to be separate files.
Packit c32a2d
	This is what resulted...
Packit c32a2d
Packit c32a2d
	Reason to separate this from synth.h:
Packit c32a2d
	There are decoders that have a special synth_1to1 but still can use these generic derivations for the mono stuff.
Packit c32a2d
	It generally makes a good deal of sense to set SYNTH_NAME to opt_synth_1to1(fr) (or opt_synth_2to1(fr), etc.).
Packit c32a2d
*/
Packit c32a2d
Packit c32a2d
/* Mono synth, wrapping over SYNTH_NAME */
Packit c32a2d
int MONO_NAME(real *bandPtr, mpg123_handle *fr)
Packit c32a2d
{
Packit c32a2d
	SAMPLE_T samples_tmp[BLOCK];
Packit c32a2d
	SAMPLE_T *tmp1 = samples_tmp;
Packit c32a2d
	int i,ret;
Packit c32a2d
Packit c32a2d
	/* save buffer stuff, trick samples_tmp into there, decode, restore */
Packit c32a2d
	unsigned char *samples = fr->buffer.data;
Packit c32a2d
	int pnt = fr->buffer.fill;
Packit c32a2d
	fr->buffer.data = (unsigned char*) samples_tmp;
Packit c32a2d
	fr->buffer.fill = 0;
Packit c32a2d
	ret = SYNTH_NAME(bandPtr, 0, fr, 0); /* decode into samples_tmp */
Packit c32a2d
	fr->buffer.data = samples; /* restore original value */
Packit c32a2d
Packit c32a2d
	/* now append samples from samples_tmp */
Packit c32a2d
	samples += pnt; /* just the next mem in frame buffer */
Packit c32a2d
	for(i=0;i<(BLOCK/2);i++)
Packit c32a2d
	{
Packit c32a2d
		*( (SAMPLE_T *)samples) = *tmp1;
Packit c32a2d
		samples += sizeof(SAMPLE_T);
Packit c32a2d
		tmp1 += 2;
Packit c32a2d
	}
Packit c32a2d
	fr->buffer.fill = pnt + (BLOCK/2)*sizeof(SAMPLE_T);
Packit c32a2d
Packit c32a2d
	return ret;
Packit c32a2d
}
Packit c32a2d
Packit c32a2d
/* Mono to stereo synth, wrapping over SYNTH_NAME */
Packit c32a2d
int MONO2STEREO_NAME(real *bandPtr, mpg123_handle *fr)
Packit c32a2d
{
Packit c32a2d
	int i,ret;
Packit c32a2d
	unsigned char *samples = fr->buffer.data;
Packit c32a2d
Packit c32a2d
	ret = SYNTH_NAME(bandPtr,0,fr,1);
Packit c32a2d
	samples += fr->buffer.fill - BLOCK*sizeof(SAMPLE_T);
Packit c32a2d
Packit c32a2d
	for(i=0;i<(BLOCK/2);i++)
Packit c32a2d
	{
Packit c32a2d
		((SAMPLE_T *)samples)[1] = ((SAMPLE_T *)samples)[0];
Packit c32a2d
		samples+=2*sizeof(SAMPLE_T);
Packit c32a2d
	}
Packit c32a2d
Packit c32a2d
	return ret;
Packit c32a2d
}