Path: blob/master/libs/mpg123/src/libmpg123/synth_8bit.h
4394 views
/*1synth_8bit.h: Wrappers over optimized synth_xtoy for converting signed short to 8bit.23copyright 1995-2008 by the mpg123 project - free software under the terms of the LGPL 2.14see COPYING and AUTHORS files in distribution or http://mpg123.org5initially written by Michael Hipp, code generalized to the wrapper by Thomas Orgis67Only variable is the BLOCK size to choose 1to1, 2to1 or 4to1.8Oh, and the names: BASE_SYNTH_NAME, SYNTH_NAME, MONO_NAME, MONO2STEREO_NAME9(p.ex. opt_synth_1to1(fr), INT123_synth_1to1_8bit, INT123_synth_1to1_8bit_mono, ...).10*/1112int SYNTH_NAME(real *bandPtr, int channel, mpg123_handle *fr, int final)13{14short samples_tmp[BLOCK];15short *tmp1 = samples_tmp + channel;16int i,ret;1718unsigned char *samples = fr->buffer.data;19int pnt = fr->buffer.fill;20fr->buffer.data = (unsigned char*) samples_tmp;21fr->buffer.fill = 0;22ret = BASE_SYNTH_NAME(bandPtr, channel, fr , 0);23fr->buffer.data = samples;2425samples += channel + pnt;26for(i=0;i<(BLOCK/2);i++)27{28*samples = fr->conv16to8[*tmp1>>AUSHIFT];29samples += 2;30tmp1 += 2;31}32fr->buffer.fill = pnt + (final ? BLOCK : 0 );3334return ret;35}3637int MONO_NAME(real *bandPtr, mpg123_handle *fr)38{39short samples_tmp[BLOCK];40short *tmp1 = samples_tmp;41int i,ret;4243unsigned char *samples = fr->buffer.data;44int pnt = fr->buffer.fill;45fr->buffer.data = (unsigned char*) samples_tmp;46fr->buffer.fill = 0;47ret = BASE_SYNTH_NAME(bandPtr, 0, fr, 0);48fr->buffer.data = samples;4950samples += pnt;51for(i=0;i<(BLOCK/2);i++)52{53*samples++ = fr->conv16to8[*tmp1>>AUSHIFT];54tmp1+=2;55}56fr->buffer.fill = pnt + BLOCK/2;5758return ret;59}6061int MONO2STEREO_NAME(real *bandPtr, mpg123_handle *fr)62{63short samples_tmp[BLOCK];64short *tmp1 = samples_tmp;65int i,ret;6667unsigned char *samples = fr->buffer.data;68int pnt = fr->buffer.fill;69fr->buffer.data = (unsigned char*) samples_tmp;70fr->buffer.fill = 0;71ret = BASE_SYNTH_NAME(bandPtr, 0, fr, 0);72fr->buffer.data = samples;7374samples += pnt;75for(i=0;i<(BLOCK/2);i++)76{77*samples++ = fr->conv16to8[*tmp1>>AUSHIFT];78*samples++ = fr->conv16to8[*tmp1>>AUSHIFT];79tmp1 += 2;80}81fr->buffer.fill = pnt + BLOCK;8283return ret;84}858687