Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.         monosynth.h: generic mono related synth functions
  3.  
  4.         copyright 1995-2008 by the mpg123 project - free software under the terms of the LGPL 2.1
  5.         see COPYING and AUTHORS files in distribution or http://mpg123.org
  6.         initially written by Michael Hipp, generalized by Thomas Orgis
  7.  
  8.         This header is used multiple times to create different variants of these functions.
  9.         See decode.c and synth.h .
  10.         Hint: BLOCK, MONO_NAME, MONO2STEREO_NAME, SYNTH_NAME and SAMPLE_T do vary.
  11.  
  12.         Thomas looked closely at the decode_1to1, decode_2to1 and decode_4to1 contents, seeing that they are too similar to be separate files.
  13.         This is what resulted...
  14.  
  15.         Reason to separate this from synth.h:
  16.         There are decoders that have a special synth_1to1 but still can use these generic derivations for the mono stuff.
  17.         It generally makes a good deal of sense to set SYNTH_NAME to opt_synth_1to1(fr) (or opt_synth_2to1(fr), etc.).
  18. */
  19.  
  20. /* Mono synth, wrapping over SYNTH_NAME */
  21. int MONO_NAME(real *bandPtr, mpg123_handle *fr)
  22. {
  23.         SAMPLE_T samples_tmp[BLOCK];
  24.         SAMPLE_T *tmp1 = samples_tmp;
  25.         int i,ret;
  26.  
  27.         /* save buffer stuff, trick samples_tmp into there, decode, restore */
  28.         unsigned char *samples = fr->buffer.data;
  29.         int pnt = fr->buffer.fill;
  30.         fr->buffer.data = (unsigned char*) samples_tmp;
  31.         fr->buffer.fill = 0;
  32.         ret = SYNTH_NAME(bandPtr, 0, fr, 0); /* decode into samples_tmp */
  33.         fr->buffer.data = samples; /* restore original value */
  34.  
  35.         /* now append samples from samples_tmp */
  36.         samples += pnt; /* just the next mem in frame buffer */
  37.         for(i=0;i<(BLOCK/2);i++)
  38.         {
  39.                 *( (SAMPLE_T *)samples) = *tmp1;
  40.                 samples += sizeof(SAMPLE_T);
  41.                 tmp1 += 2;
  42.         }
  43.         fr->buffer.fill = pnt + (BLOCK/2)*sizeof(SAMPLE_T);
  44.  
  45.         return ret;
  46. }
  47.  
  48. /* Mono to stereo synth, wrapping over SYNTH_NAME */
  49. int MONO2STEREO_NAME(real *bandPtr, mpg123_handle *fr)
  50. {
  51.         int i,ret;
  52.         unsigned char *samples = fr->buffer.data;
  53.  
  54.         ret = SYNTH_NAME(bandPtr,0,fr,1);
  55.         samples += fr->buffer.fill - BLOCK*sizeof(SAMPLE_T);
  56.  
  57.         for(i=0;i<(BLOCK/2);i++)
  58.         {
  59.                 ((SAMPLE_T *)samples)[1] = ((SAMPLE_T *)samples)[0];
  60.                 samples+=2*sizeof(SAMPLE_T);
  61.         }
  62.  
  63.         return ret;
  64. }
  65.