Path: blob/master/libs/mpg123/src/libmpg123/synth_ntom.h
4394 views
/*123This header is used multiple times to create different variants of this function.4Hint: MONO_NAME, MONO2STEREO_NAME, SYNTH_NAME and SAMPLE_T as well as WRITE_SAMPLE do vary.56copyright 1995-2008 by the mpg123 project - free software under the terms of the LGPL 2.17see COPYING and AUTHORS files in distribution or http://mpg123.org8initially written by Michael Hipp, generalized by Thomas Orgis910Well, this is very simple resampling... you may or may not like what you hear.11But it's cheap.12But still, we don't implement a non-autoincrement version of this one.13*/1415/* Note: These mono functions would also work generically,16it's just that they need a runtime calculation for the conversion loop...17The fixed XtoY functions have the chance for loop unrolling... */1819int MONO_NAME(real *bandPtr, mpg123_handle *fr)20{21SAMPLE_T samples_tmp[8*64];22SAMPLE_T *tmp1 = samples_tmp;23size_t i;24int ret;2526size_t pnt = fr->buffer.fill;27unsigned char *samples = fr->buffer.data;28fr->buffer.data = (unsigned char*) samples_tmp;29fr->buffer.fill = 0;30ret = SYNTH_NAME(bandPtr, 0, fr, 1);31fr->buffer.data = samples;3233samples += pnt;34for(i=0;i<(fr->buffer.fill/(2*sizeof(SAMPLE_T)));i++)35{36*( (SAMPLE_T *)samples) = *tmp1;37samples += sizeof(SAMPLE_T);38tmp1 += 2;39}40fr->buffer.fill = pnt + (fr->buffer.fill/2);4142return ret;43}444546int MONO2STEREO_NAME(real *bandPtr, mpg123_handle *fr)47{48size_t i;49int ret;50size_t pnt1 = fr->buffer.fill;51unsigned char *samples = fr->buffer.data + pnt1;5253ret = SYNTH_NAME(bandPtr, 0, fr, 1);5455for(i=0;i<((fr->buffer.fill-pnt1)/(2*sizeof(SAMPLE_T)));i++)56{57((SAMPLE_T *)samples)[1] = ((SAMPLE_T *)samples)[0];58samples+=2*sizeof(SAMPLE_T);59}6061return ret;62}636465int SYNTH_NAME(real *bandPtr,int channel, mpg123_handle *fr, int final)66{67static const int step = 2;68SAMPLE_T *samples = (SAMPLE_T *) (fr->buffer.data + fr->buffer.fill);6970real *b0, **buf; /* (*buf)[0x110]; */71int clip = 0;72int bo1;73int ntom;74#ifndef NO_EQUALIZER75if(fr->have_eq_settings) INT123_do_equalizer(bandPtr,channel,fr->equalizer);76#endif77if(!channel)78{79fr->bo--;80fr->bo &= 0xf;81buf = fr->real_buffs[0];82ntom = fr->INT123_ntom_val[1] = fr->INT123_ntom_val[0];83}84else85{86samples++;87buf = fr->real_buffs[1];88ntom = fr->INT123_ntom_val[1];89}9091if(fr->bo & 0x1)92{93b0 = buf[0];94bo1 = fr->bo;95INT123_dct64(buf[1]+((fr->bo+1)&0xf),buf[0]+fr->bo,bandPtr);96}97else98{99b0 = buf[1];100bo1 = fr->bo+1;101INT123_dct64(buf[0]+fr->bo,buf[1]+fr->bo+1,bandPtr);102}103104{105register int j;106real *window = fr->decwin + 16 - bo1;107108for (j=16;j;j--,window+=0x10)109{110real sum;111112ntom += fr->ntom_step;113if(ntom < NTOM_MUL)114{115window += 16;116b0 += 16;117continue;118}119120sum = REAL_MUL_SYNTH(*window++, *b0++);121sum -= REAL_MUL_SYNTH(*window++, *b0++);122sum += REAL_MUL_SYNTH(*window++, *b0++);123sum -= REAL_MUL_SYNTH(*window++, *b0++);124sum += REAL_MUL_SYNTH(*window++, *b0++);125sum -= REAL_MUL_SYNTH(*window++, *b0++);126sum += REAL_MUL_SYNTH(*window++, *b0++);127sum -= REAL_MUL_SYNTH(*window++, *b0++);128sum += REAL_MUL_SYNTH(*window++, *b0++);129sum -= REAL_MUL_SYNTH(*window++, *b0++);130sum += REAL_MUL_SYNTH(*window++, *b0++);131sum -= REAL_MUL_SYNTH(*window++, *b0++);132sum += REAL_MUL_SYNTH(*window++, *b0++);133sum -= REAL_MUL_SYNTH(*window++, *b0++);134sum += REAL_MUL_SYNTH(*window++, *b0++);135sum -= REAL_MUL_SYNTH(*window++, *b0++);136137while(ntom >= NTOM_MUL)138{139WRITE_SAMPLE(samples,sum,clip);140samples += step;141ntom -= NTOM_MUL;142}143}144145ntom += fr->ntom_step;146if(ntom >= NTOM_MUL)147{148real sum;149sum = REAL_MUL_SYNTH(window[0x0], b0[0x0]);150sum += REAL_MUL_SYNTH(window[0x2], b0[0x2]);151sum += REAL_MUL_SYNTH(window[0x4], b0[0x4]);152sum += REAL_MUL_SYNTH(window[0x6], b0[0x6]);153sum += REAL_MUL_SYNTH(window[0x8], b0[0x8]);154sum += REAL_MUL_SYNTH(window[0xA], b0[0xA]);155sum += REAL_MUL_SYNTH(window[0xC], b0[0xC]);156sum += REAL_MUL_SYNTH(window[0xE], b0[0xE]);157158while(ntom >= NTOM_MUL)159{160WRITE_SAMPLE(samples,sum,clip);161samples += step;162ntom -= NTOM_MUL;163}164}165166b0-=0x10,window-=0x20;167window += bo1<<1;168169for (j=15;j;j--,b0-=0x20,window-=0x10)170{171real sum;172173ntom += fr->ntom_step;174if(ntom < NTOM_MUL)175{176window -= 16;177b0 += 16;178continue;179}180181sum = REAL_MUL_SYNTH(-*(--window), *b0++);182sum -= REAL_MUL_SYNTH(*(--window), *b0++);183sum -= REAL_MUL_SYNTH(*(--window), *b0++);184sum -= REAL_MUL_SYNTH(*(--window), *b0++);185sum -= REAL_MUL_SYNTH(*(--window), *b0++);186sum -= REAL_MUL_SYNTH(*(--window), *b0++);187sum -= REAL_MUL_SYNTH(*(--window), *b0++);188sum -= REAL_MUL_SYNTH(*(--window), *b0++);189sum -= REAL_MUL_SYNTH(*(--window), *b0++);190sum -= REAL_MUL_SYNTH(*(--window), *b0++);191sum -= REAL_MUL_SYNTH(*(--window), *b0++);192sum -= REAL_MUL_SYNTH(*(--window), *b0++);193sum -= REAL_MUL_SYNTH(*(--window), *b0++);194sum -= REAL_MUL_SYNTH(*(--window), *b0++);195sum -= REAL_MUL_SYNTH(*(--window), *b0++);196sum -= REAL_MUL_SYNTH(*(--window), *b0++);197198while(ntom >= NTOM_MUL)199{200WRITE_SAMPLE(samples,sum,clip);201samples += step;202ntom -= NTOM_MUL;203}204}205}206207fr->INT123_ntom_val[channel] = ntom;208if(final) fr->buffer.fill = ((unsigned char *) samples - fr->buffer.data - (channel ? sizeof(SAMPLE_T) : 0));209210return clip;211}212213214