home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Sound / LAME / src / util.c < prev    next >
C/C++ Source or Header  |  2000-08-01  |  17KB  |  648 lines

  1.  
  2. #include "util.h"
  3. #include <assert.h>
  4.  
  5. #ifdef LAME_STD_PRINT
  6. #include <stdarg.h>
  7. #endif
  8.  
  9. /***********************************************************************
  10. *
  11. *  Global Variable Definitions
  12. *
  13. ***********************************************************************/
  14.  
  15.  
  16. /* 1: MPEG-1, 0: MPEG-2 LSF, 1995-07-11 shn */
  17. int     bitrate_table[2][15] = {
  18.           {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160},
  19.           {0,32,40,48,56,64,80,96,112,128,160,192,224,256,320}};
  20.  
  21.  
  22. enum byte_order NativeByteOrder = order_unknown;
  23.  
  24. /***********************************************************************
  25. *
  26. *  Global Function Definitions
  27. *
  28. ***********************************************************************/
  29. /* Replacement for forward fseek(,,SEEK_CUR), because fseek() fails on pipes */
  30. int fskip(FILE *sf,long num_bytes,int dummy)
  31. {
  32.   char data[1024];
  33.   int nskip = 0;
  34.   while (num_bytes > 0) {
  35.     nskip = (num_bytes>1024) ? 1024 : num_bytes;
  36.     num_bytes -= fread(data,(size_t)1,(size_t)nskip,sf);
  37.   }
  38.   /* return 0 if last read was successful */
  39.   return num_bytes;
  40. }
  41.  
  42.  
  43. FLOAT8 ATHformula(FLOAT8 f)
  44. {
  45.   FLOAT8 ath;
  46.   f  = Max(0.01, f);
  47.   f  = Min(18.0,f);
  48.  
  49.   /* from Painter & Spanias, 1997 */
  50.   /* minimum: (i=77) 3.3kHz = -5db */
  51.   ath =    3.640 * pow(f,-0.8)
  52.          - 6.500 * exp(-0.6*pow(f-3.3,2.0))
  53.          + 0.001 * pow(f,4.0);
  54.   return ath;
  55. }
  56.  
  57.  
  58. /* see for example "Zwicker: Psychoakustik, 1982; ISBN 3-540-11401-7 */
  59. FLOAT8 freq2bark(FLOAT8 freq)
  60. {
  61.   /* input: freq in hz  output: barks */
  62.     freq = freq * 0.001;
  63.     return 13.0*atan(.76*freq) + 3.5*atan(freq*freq/(7.5*7.5));
  64. }
  65.  
  66. /* see for example "Zwicker: Psychoakustik, 1982; ISBN 3-540-11401-7 */
  67. FLOAT8 freq2cbw(FLOAT8 freq)
  68. {
  69.   /* input: freq in hz  output: critical band width */
  70.     freq = freq * 0.001;
  71.     return 25+75*pow(1+1.4*(freq*freq),0.69);
  72. }
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79. /***********************************************************************
  80.  * compute bitsperframe and mean_bits for a layer III frame 
  81.  **********************************************************************/
  82. void getframebits(lame_global_flags *gfp,int *bitsPerFrame, int *mean_bits) {
  83.   int whole_SpF;
  84.   lame_internal_flags *gfc=gfp->internal_flags;
  85.  
  86.   long bit_rate;
  87.   
  88.   if (gfc->bitrate_index) 
  89.     bit_rate = bitrate_table[gfp->version][gfc->bitrate_index];
  90.   else
  91.     bit_rate = gfp->brate;
  92.   
  93.   whole_SpF=((gfp->version+1)*72000L*bit_rate) / gfp->out_samplerate;
  94.   *bitsPerFrame = 8 * (whole_SpF + gfc->padding);
  95.   *mean_bits = (*bitsPerFrame - 8*gfc->sideinfo_len) / gfc->mode_gr;
  96.  
  97. }
  98.  
  99.  
  100.  
  101.  
  102. void display_bitrates(FILE *out_fh)
  103. {
  104.   int index,version;
  105.  
  106.   version = 1;
  107.   fprintf(out_fh,"\n");
  108.   fprintf(out_fh,"MPEG1 layer III samplerates(kHz): 32 44.1 48 \n");
  109.  
  110.   fprintf(out_fh,"bitrates(kbs): ");
  111.   for (index=1;index<15;index++) {
  112.     fprintf(out_fh,"%i ",bitrate_table[version][index]);
  113.   }
  114.   fprintf(out_fh,"\n");
  115.   
  116.   
  117.   version = 0;
  118.   fprintf(out_fh,"\n");
  119.   fprintf(out_fh,"MPEG2 layer III samplerates(kHz): 16 22.05 24 \n");
  120.   fprintf(out_fh,"bitrates(kbs): ");
  121.   for (index=1;index<15;index++) {
  122.     fprintf(out_fh,"%i ",bitrate_table[version][index]);
  123.   }
  124.   fprintf(out_fh,"\n");
  125.  
  126.   version = 0;
  127.   fprintf(out_fh,"\n");
  128.   fprintf(out_fh,"MPEG2.5 layer III samplerates(kHz): 8 11.025 12 \n");
  129.   fprintf(out_fh,"bitrates(kbs): ");
  130.   for (index=1;index<15;index++) {
  131.     fprintf(out_fh,"%i ",bitrate_table[version][index]);
  132.   }
  133.   fprintf(out_fh,"\n");
  134. }
  135.  
  136.  
  137. #define ABS(A) (((A)>0) ? (A) : -(A))
  138.  
  139. int FindNearestBitrate(
  140. int bRate,        /* legal rates from 32 to 448 */
  141. int version,      /* MPEG-1 or MPEG-2 LSF */
  142. int samplerate)   /* convert bitrate in kbps to index */
  143. {
  144.   int     index = 0;
  145.   int     bitrate = 10000;
  146.   
  147.   while( index<15)   {
  148.     if( ABS( bitrate_table[version][index] - bRate) < ABS(bitrate-bRate) ) {
  149.       bitrate = bitrate_table[version][index];
  150.     }
  151.     ++index;
  152.   }
  153.   return bitrate;
  154. }
  155.  
  156.  
  157. /* map samplerate to a valid samplerate
  158.  *
  159.  * Robert.Hegemann@gmx.de 2000-07-01
  160.  */
  161. long validSamplerate(long samplerate)
  162. {
  163.     if (samplerate<= 8000) return  8000;
  164.     if (samplerate<=11025) return 11025;
  165.     if (samplerate<=12000) return 12000;
  166.     if (samplerate<=16000) return 16000;
  167.     if (samplerate<=22050) return 22050;
  168.     if (samplerate<=24000) return 24000;
  169.     if (samplerate<=32000) return 32000;
  170.     if (samplerate<=44100) return 44100;
  171.     
  172.     return 48000;
  173. }
  174.  
  175. int BitrateIndex(
  176. int bRate,        /* legal rates from 32 to 448 */
  177. int version,      /* MPEG-1 or MPEG-2 LSF */
  178. int samplerate)   /* convert bitrate in kbps to index */
  179. {
  180. int     index = 0;
  181. int     found = 0;
  182.  
  183.     while(!found && index<15)   {
  184.         if(bitrate_table[version][index] == bRate)
  185.             found = 1;
  186.         else
  187.             ++index;
  188.     }
  189.     if(found)
  190.         return(index);
  191.     else {
  192.         ERRORF("Bitrate %dkbs not legal for %iHz output sampling.\n",
  193.                 bRate, samplerate);
  194.         return(-1);     /* Error! */
  195.     }
  196. }
  197.  
  198. int SmpFrqIndex(  /* convert samp frq in Hz to index */
  199. long sRate,             /* legal rates 16000, 22050, 24000, 32000, 44100, 48000 */
  200. int  *version)
  201. {
  202.     /* Assign default value */
  203.     *version=0;
  204.  
  205.     if (sRate == 44100L) {
  206.         *version = 1; return(0);
  207.     }
  208.     else if (sRate == 48000L) {
  209.         *version = 1; return(1);
  210.     }
  211.     else if (sRate == 32000L) {
  212.         *version = 1; return(2);
  213.     }
  214.     else if (sRate == 24000L) {
  215.         *version = 0; return(1);
  216.     }
  217.     else if (sRate == 22050L) {
  218.         *version = 0; return(0);
  219.     }
  220.     else if (sRate == 16000L) {
  221.         *version = 0; return(2);
  222.     }
  223.     else if (sRate == 12000L) {
  224.         *version = 0; return(1);
  225.     }
  226.     else if (sRate == 11025L) {
  227.         *version = 0; return(0);
  228.     }
  229.     else if (sRate ==  8000L) {
  230.         *version = 0; return(2);
  231.     }
  232.     else {
  233.         ERRORF("SmpFrqIndex: %ldHz is not a legal sample rate\n", sRate);
  234.         return(-1);     /* Error! */
  235.     }
  236. }
  237.  
  238.  
  239.  
  240.  
  241. /*****************************************************************************
  242. *
  243. *  Routines to determine byte order and swap bytes
  244. *
  245. *****************************************************************************/
  246.  
  247. enum byte_order DetermineByteOrder(void)
  248. {
  249.     char s[ sizeof(long) + 1 ];
  250.     union
  251.     {
  252.         long longval;
  253.         char charval[ sizeof(long) ];
  254.     } probe;
  255.     probe.longval = 0x41424344L;  /* ABCD in ASCII */
  256.     strncpy( s, probe.charval, sizeof(long) );
  257.     s[ sizeof(long) ] = '\0';
  258.     /* fprintf( stderr, "byte order is %s\n", s ); */
  259.     if ( strcmp(s, "ABCD") == 0 )
  260.         return order_bigEndian;
  261.     else
  262.         if ( strcmp(s, "DCBA") == 0 )
  263.             return order_littleEndian;
  264.         else
  265.             return order_unknown;
  266. }
  267.  
  268. void SwapBytesInWords( short *loc, int words )
  269. {
  270.     int i;
  271.     short thisval;
  272.     char *dst, *src;
  273.     src = (char *) &thisval;
  274.     for ( i = 0; i < words; i++ )
  275.     {
  276.         thisval = *loc;
  277.         dst = (char *) loc++;
  278.         dst[0] = src[1];
  279.         dst[1] = src[0];
  280.     }
  281. }
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288. /*****************************************************************************
  289. *
  290. *  bit_stream.c package
  291. *  Author:  Jean-Georges Fritsch, C-Cube Microsystems
  292. *
  293. *****************************************************************************/
  294.  
  295. /********************************************************************
  296.   This package provides functions to write (exclusive or read)
  297.   information from (exclusive or to) the bit stream.
  298.  
  299.   If the bit stream is opened in read mode only the get functions are
  300.   available. If the bit stream is opened in write mode only the put
  301.   functions are available.
  302. ********************************************************************/
  303.  
  304. /*alloc_buffer();      open and initialize the buffer;                    */
  305. /*desalloc_buffer();   empty and close the buffer                         */
  306. /*back_track_buffer();     goes back N bits in the buffer                 */
  307. /*unsigned int get1bit();  read 1 bit from the bit stream                 */
  308. /*unsigned long look_ahead(); grep the next N bits in the bit stream without*/
  309. /*                            changing the buffer pointer                   */
  310. /*putbits(); write N bits from the bit stream */
  311. /*int seek_sync(); return 1 if a sync word was found in the bit stream      */
  312. /*                 otherwise returns 0                                      */
  313.  
  314.  
  315.  
  316. void empty_buffer(Bit_stream_struc *bs)
  317. {
  318.   /* brain damaged ISO buffer type - counts down */
  319.   int minimum=1+bs->buf_byte_idx;    /* end of the buffer to empty */
  320.   if (bs->buf_size-minimum <= 0) return;
  321.   bs->buf_byte_idx = bs->buf_size -1;
  322.   bs->buf_bit_idx = 8;
  323.   
  324.   bs->buf[bs->buf_byte_idx] = 0;  /* what does this do? */
  325. }
  326.  
  327.  
  328. int copy_buffer(char *buffer,int size,Bit_stream_struc *bs)
  329. {
  330.   int minimum = bs->buf_byte_idx + 1;
  331.   if (minimum <= 0) return 0;
  332.   if (size!=0 && minimum>size) return -1; /* buffer is too small */
  333.   memcpy(buffer,bs->buf,(unsigned int)minimum);
  334.   bs->buf_byte_idx = -1;
  335.   bs->buf_bit_idx = 0;
  336.   return minimum;
  337. }
  338.  
  339.  
  340.  
  341.  
  342.  
  343. void init_bit_stream_w(lame_internal_flags *gfc)
  344. {
  345.   Bit_stream_struc* bs = &gfc->bs;
  346.    alloc_buffer(bs, BUFFER_SIZE);
  347.    gfc->h_ptr = gfc->w_ptr = 0;
  348.    gfc->header[gfc->h_ptr].write_timing = 0;
  349.    gfc->bs.buf_byte_idx = -1;
  350.    gfc->bs.buf_bit_idx = 0;
  351.    gfc->bs.totbit = 0;
  352. }
  353.  
  354.  
  355. /*open and initialize the buffer; */
  356. void alloc_buffer(
  357. Bit_stream_struc *bs,   /* bit stream structure */
  358. unsigned int size)
  359. {
  360.    bs->buf = (unsigned char *)       malloc(size);
  361.    bs->buf_size = size;
  362. }
  363.  
  364. /*empty and close mallocs in gfc */
  365. void freegfc(lame_internal_flags *gfc)   /* bit stream structure */
  366. {
  367.    free(gfc->bs.buf);
  368.    free(gfc);
  369. }
  370.  
  371. int putmask[9]={0x0, 0x1, 0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff};
  372.  
  373.  
  374.  
  375.  
  376.  
  377. /*****************************************************************************
  378. *
  379. *  End of bit_stream.c package
  380. *
  381. *****************************************************************************/
  382.  
  383. /* reorder the three short blocks By Takehiro TOMINAGA */
  384. /*
  385.   Within each scalefactor band, data is given for successive
  386.   time windows, beginning with window 0 and ending with window 2.
  387.   Within each window, the quantized values are then arranged in
  388.   order of increasing frequency...
  389. */
  390. void ireorder(int scalefac_band[],int ix_orig[576]) {
  391.   int i,sfb, window, j=0;
  392.   int ix[576];
  393.   for (sfb = 0; sfb < SBMAX_s; sfb++) {
  394.     int start = scalefac_band[sfb];
  395.     int end   = scalefac_band[sfb + 1];
  396.     for (window = 0; window < 3; window++) {
  397.       for (i = start; i < end; ++i) {
  398.     ix[j++] = ix_orig[3*i+window];
  399.       }
  400.     }
  401.   }
  402.   memcpy(ix_orig,ix,576*sizeof(int));
  403. }
  404. void iun_reorder(int scalefac_band[],int ix_orig[576]) {
  405.   int i,sfb, window, j=0;
  406.   int ix[576];
  407.   for (sfb = 0; sfb < SBMAX_s; sfb++) {
  408.     int start = scalefac_band[sfb];
  409.     int end   = scalefac_band[sfb + 1];
  410.     for (window = 0; window < 3; window++) {
  411.       for (i = start; i < end; ++i) {
  412.     ix[3*i+window] = ix_orig[j++];
  413.       }
  414.     }
  415.   }
  416.   memcpy(ix_orig,ix,576*sizeof(int));
  417. }
  418. void freorder(int scalefac_band[],FLOAT8 ix_orig[576]) {
  419.   int i,sfb, window, j=0;
  420.   FLOAT8 ix[576];
  421.   for (sfb = 0; sfb < SBMAX_s; sfb++) {
  422.     int start = scalefac_band[sfb];
  423.     int end   = scalefac_band[sfb + 1];
  424.     for (window = 0; window < 3; window++) {
  425.       for (i = start; i < end; ++i) {
  426.     ix[j++] = ix_orig[3*i+window];
  427.       }
  428.     }
  429.   }
  430.   memcpy(ix_orig,ix,576*sizeof(FLOAT8));
  431. }
  432. void fun_reorder(int scalefac_band[],FLOAT8 ix_orig[576]) {
  433.   int i,sfb, window, j=0;
  434.   FLOAT8 ix[576];
  435.   for (sfb = 0; sfb < SBMAX_s; sfb++) {
  436.     int start = scalefac_band[sfb];
  437.     int end   = scalefac_band[sfb + 1];
  438.     for (window = 0; window < 3; window++) {
  439.       for (i = start; i < end; ++i) {
  440.     ix[3*i+window] = ix_orig[j++];
  441.       }
  442.     }
  443.   }
  444.   memcpy(ix_orig,ix,576*sizeof(FLOAT8));
  445. }
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456. /* resampling via FIR filter, blackman window */
  457. INLINE double blackman(int i,double offset,double fcn,int l)
  458. {
  459.   double bkwn;
  460.   double wcn = (PI * fcn);
  461.   double dly = l / 2.0;
  462.   double x = i-offset;
  463.   if (x<0) x=0;
  464.   if (x>l) x=l;
  465.   bkwn = 0.42 - 0.5 * cos((x * 2) * PI /l)
  466.     + 0.08 * cos((x * 4) * PI /l);
  467.   if (fabs(x-dly)<1e-9) return wcn/PI;
  468.   else 
  469.     return  (sin( (wcn *  ( x - dly))) / (PI * ( x - dly)) * bkwn );
  470. }
  471.  
  472. int fill_buffer_downsample(lame_global_flags *gfp,short int *outbuf,int desired_len,
  473.              short int *inbuf,int len,int *num_used,int ch) {
  474.   
  475.   lame_internal_flags *gfc=gfp->internal_flags;
  476.   FLOAT8 offset,xvalue;
  477.   int i,j=0,k,value;
  478.   int filter_l;
  479.   FLOAT8 fcn,intratio;
  480.   short int *inbuf_old;
  481.  
  482.   intratio=( fabs(gfc->resample_ratio - floor(.5+gfc->resample_ratio)) < .0001 );
  483.   fcn = .90/gfc->resample_ratio;
  484.   if (fcn>.90) fcn=.90;
  485.   filter_l=19;  /* must be odd */
  486.   /* if resample_ratio = int, filter_l should be even */
  487.   filter_l += intratio;
  488.   assert(filter_l +5 < BLACKSIZE);
  489.   
  490.   if (!gfc->fill_buffer_downsample_init) {
  491.     gfc->fill_buffer_downsample_init=1;
  492.     gfc->itime[0]=0;
  493.     gfc->itime[1]=0;
  494.     memset((char *) gfc->inbuf_old, 0, sizeof(short int)*2*BLACKSIZE);
  495.     /* precompute blackman filter coefficients */
  496.     for (j= 0; j<= 2*BPC; ++j) {
  497.       offset=(double)(j-BPC)/(double)(2*BPC);
  498.       for (i=0; i<=filter_l; ++i) {
  499.     gfc->blackfilt[j][i]=blackman(i,offset,fcn,filter_l);
  500.       }
  501.     }
  502.  
  503.   }
  504.   inbuf_old=gfc->inbuf_old[ch];
  505.  
  506.   /* time of j'th element in inbuf = itime + j/ifreq; */
  507.   /* time of k'th element in outbuf   =  j/ofreq */
  508.   for (k=0;k<desired_len;k++) {
  509.     FLOAT8 time0;
  510.     int joff;
  511.  
  512.     time0 = k*gfc->resample_ratio;       /* time of k'th output sample */
  513.     j = floor( time0 -gfc->itime[ch]  );
  514.     if ((j+filter_l/2) >= len) break;
  515.  
  516.     /* blackmon filter.  by default, window centered at j+.5(filter_l%2) */
  517.     /* but we want a window centered at time0.   */
  518.     offset = ( time0 -gfc->itime[ch] - (j + .5*(filter_l%2)));
  519.     assert(fabs(offset)<=.500001);
  520.     joff = floor((offset*2*BPC) + BPC +.5);
  521.  
  522.     xvalue=0;
  523.     for (i=0 ; i<=filter_l ; ++i) {
  524.       int j2 = i+j-filter_l/2;
  525.       int y;
  526.       y = (j2<0) ? inbuf_old[BLACKSIZE+j2] : inbuf[j2];
  527. #define PRECOMPUTE
  528. #ifdef PRECOMPUTE
  529.       xvalue += y*gfc->blackfilt[joff][i];
  530. #else
  531.       if (intratio) 
  532.     xvalue += y*gfc->blackfilt[joff][i];
  533.       else
  534.     xvalue += y*blackman(i,offset,fcn,filter_l);  /* very slow! */
  535. #endif
  536.     }
  537.     value = floor(.5+xvalue);
  538.     if (value > 32767) outbuf[k]=32767;
  539.     else if (value < -32767) outbuf[k]=-32767;
  540.     else outbuf[k]=value;
  541.   }
  542.  
  543.   
  544.   /* k = number of samples added to outbuf */
  545.   /* last k sample used data from j,j+1, or j+1 overflowed buffer */
  546.   /* remove num_used samples from inbuf: */
  547.   *num_used = Min(len,j+filter_l/2);
  548.   gfc->itime[ch] += *num_used - k*gfc->resample_ratio;
  549.   for (i=0;i<BLACKSIZE;i++)
  550.     inbuf_old[i]=inbuf[*num_used + i -BLACKSIZE];
  551.   return k;
  552. }
  553.  
  554.  
  555. /* 4 point interpolation routine for upsampling */
  556. int fill_buffer_upsample(lame_global_flags *gfp,short int *outbuf,int desired_len,
  557.         short int *inbuf,int len,int *num_used,int ch) {
  558.  
  559.   int i,j=0,k,linear,value;
  560.   lame_internal_flags *gfc=gfp->internal_flags;
  561.   short int *inbuf_old;
  562.  
  563.   if (!gfc->fill_buffer_upsample_init) {
  564.     gfc->fill_buffer_upsample_init=1;
  565.     gfc->upsample_itime[0]=0;
  566.     gfc->upsample_itime[1]=0;
  567.     memset((char *) gfc->upsample_inbuf_old, 0, sizeof(short int)*2*OLDBUFSIZE);
  568.   }
  569.  
  570.  
  571.   inbuf_old=gfc->upsample_inbuf_old[ch];
  572.  
  573.   /* if downsampling by an integer multiple, use linear resampling,
  574.    * otherwise use quadratic */
  575.   linear = ( fabs(gfc->resample_ratio - floor(.5+gfc->resample_ratio)) < .0001 );
  576.  
  577.   /* time of j'th element in inbuf = itime + j/ifreq; */
  578.   /* time of k'th element in outbuf   =  j/ofreq */
  579.   for (k=0;k<desired_len;k++) {
  580.     int y0,y1,y2,y3;
  581.     FLOAT8 x0,x1,x2,x3;
  582.     FLOAT8 time0;
  583.  
  584.     time0 = k*gfc->resample_ratio;       /* time of k'th output sample */
  585.     j = floor( time0 -gfc->upsample_itime[ch]  );
  586.     /* itime[ch] + j;    */            /* time of j'th input sample */
  587.     if (j+2 >= len) break;             /* not enough data in input buffer */
  588.  
  589.     x1 = time0-(gfc->upsample_itime[ch]+j);
  590.     x2 = x1-1;
  591.     y1 = (j<0) ? inbuf_old[OLDBUFSIZE+j] : inbuf[j];
  592.     y2 = ((1+j)<0) ? inbuf_old[OLDBUFSIZE+1+j] : inbuf[1+j];
  593.  
  594.     /* linear resample */
  595.     if (linear) {
  596.       outbuf[k] = floor(.5 +  (y2*x1-y1*x2) );
  597.     } else {
  598.       /* quadratic */
  599.       x0 = x1+1;
  600.       x3 = x1-2;
  601.       y0 = ((j-1)<0) ? inbuf_old[OLDBUFSIZE+(j-1)] : inbuf[j-1];
  602.       y3 = ((j+2)<0) ? inbuf_old[OLDBUFSIZE+(j+2)] : inbuf[j+2];
  603.       value = floor(.5 +
  604.             -y0*x1*x2*x3/6 + y1*x0*x2*x3/2 - y2*x0*x1*x3/2 +y3*x0*x1*x2/6
  605.             );
  606.       if (value > 32767) outbuf[k]=32767;
  607.       else if (value < -32767) outbuf[k]=-32767;
  608.       else outbuf[k]=value;
  609.  
  610.       /*
  611.       printf("k=%i  new=%i   [ %i %i %i %i ]\n",k,outbuf[k],
  612.          y0,y1,y2,y3);
  613.       */
  614.     }
  615.   }
  616.  
  617.  
  618.   /* k = number of samples added to outbuf */
  619.   /* last k sample used data from j,j+1, or j+1 overflowed buffer */
  620.   /* remove num_used samples from inbuf: */
  621.   *num_used = Min(len,j+2);
  622.   gfc->upsample_itime[ch] += *num_used - k*gfc->resample_ratio;
  623.   for (i=0;i<OLDBUFSIZE;i++)
  624.     inbuf_old[i]=inbuf[*num_used + i -OLDBUFSIZE];
  625.   return k;
  626. }
  627.  
  628.  
  629. /***********************************************************************
  630. *
  631. *  Message Output
  632. *
  633. ***********************************************************************/
  634.  
  635. #ifdef LAME_STD_PRINT
  636.  
  637. void
  638. lame_errorf(const char * s, ...)
  639. {
  640.   va_list args;
  641.   va_start(args, s);
  642.   vfprintf(stderr, s, args);
  643.   va_end(args);
  644. }
  645.  
  646. #endif
  647.  
  648.