home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2001 September / PC-WELT 9-2001.ISO / software / hw / brennen / flask_src.exe / Audio / AC3 / AC3Dec / rematrix.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-06  |  2.0 KB  |  84 lines

  1. /* 
  2.  *    rematrix.c
  3.  *
  4.  *    Copyright (C) Aaron Holtzman - July 1999
  5.  *
  6.  *  This file is part of ac3dec, a free Dolby AC-3 stream decoder.
  7.  *    
  8.  *  ac3dec is free software; you can redistribute it and/or modify
  9.  *  it under the terms of the GNU General Public License as published by
  10.  *  the Free Software Foundation; either version 2, or (at your option)
  11.  *  any later version.
  12.  *   
  13.  *  ac3dec is distributed in the hope that it will be useful,
  14.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  *  GNU General Public License for more details.
  17.  *   
  18.  *  You should have received a copy of the GNU General Public License
  19.  *  along with GNU Make; see the file COPYING.  If not, write to
  20.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  21.  *
  22.  *
  23.  */
  24.  
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. #include "ac3.h"
  28. #include "ac3_internal.h"
  29.  
  30.  
  31. #include "decode.h"
  32. #include "rematrix.h"
  33.  
  34. struct rematrix_band_s
  35. {
  36.     uint_32 start;
  37.     uint_32 end;
  38. };
  39.  
  40. struct rematrix_band_s rematrix_band[] = { {13,24}, {25,36}, {37 ,60}, {61,252}};
  41.  
  42. static inline uint_32 minAC3(uint_32 a,uint_32 b);
  43.  
  44. static inline uint_32
  45. minAC3(uint_32 a,uint_32 b)
  46. {
  47.     return (a < b ? a : b);
  48. }
  49.  
  50. /* This routine simply does stereo rematixing for the 2 channel 
  51.  * stereo mode */
  52. void rematrix(audblk_t *audblk, stream_samples_t samples)
  53. {
  54.     uint_32 num_bands;
  55.     uint_32 start;
  56.     uint_32 end;
  57.     uint_32 i,j;
  58.     float left,right;
  59.  
  60.     if(!audblk->cplinu || audblk->cplbegf > 2)
  61.         num_bands = 4;
  62.     else if (audblk->cplbegf > 0)
  63.         num_bands = 3;
  64.     else
  65.         num_bands = 2;
  66.  
  67.     for(i=0;i < num_bands; i++)
  68.     {
  69.         if(!audblk->rematflg[i])
  70.             continue;
  71.  
  72.         start = rematrix_band[i].start;
  73.         end = min(rematrix_band[i].end ,12 * audblk->cplbegf + 36);
  74.     
  75.         for(j=start;j < end; j++)
  76.         {
  77.             left  = samples[0][j] + samples[1][j];
  78.             right = samples[0][j] - samples[1][j];
  79.             samples[0][j] = left;
  80.             samples[1][j] = right;
  81.         }
  82.     }
  83. }
  84.