home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2001 September / PC-WELT 9-2001.ISO / software / hw / brennen / flask_src.exe / Audio / AC3 / CAC3Dec.cpp next >
Encoding:
C/C++ Source or Header  |  2000-05-06  |  2.1 KB  |  98 lines

  1. /* 
  2.  *  CAC3Dec.cpp 
  3.  *
  4.  *    Copyright (C) Alberto Vigata - January 2000
  5.  *
  6.  *  This file is part of FlasKMPEG, a free MPEG to MPEG/AVI converter
  7.  *    
  8.  *  FlasKMPEG 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.  *  FlasKMPEG 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. #include "CAC3Dec.h"
  25. extern "C"{
  26. #include "AC3Dec/ac3.h"
  27. }
  28.  
  29. //////////////////////////////////////////////////////////////////////
  30. // CAC3Dec Class
  31. //////////////////////////////////////////////////////////////////////
  32.  
  33.  
  34. // Globals
  35. ac3_frame_t *ac3_frame;
  36. ac3_config_t ac3_config;
  37. short        *framedata;
  38. int           datasize;
  39. bool          initialized;
  40.  
  41. #define FRAME_SIZE 256*6*4
  42.  
  43. void fill_buffer(unsigned char **start,unsigned char **end)
  44. {
  45.     uint_32 bytes_read;
  46.     *start = (unsigned char *)framedata;
  47.     bytes_read = datasize;
  48.     *end= *start + bytes_read;
  49. }
  50.  
  51.  
  52.  
  53. CAC3Dec::CAC3Dec()
  54. {
  55.     initialized = false;
  56. }
  57.  
  58. CAC3Dec::~CAC3Dec()
  59. {
  60.     initialized = false;
  61. }
  62.  
  63. void InitAC3Dec(){
  64.     ac3_config.fill_buffer_callback = fill_buffer;
  65.     ac3_config.num_output_ch = 2;
  66.     ac3_config.flags = 0;
  67.  
  68.     ac3_init(&ac3_config);
  69. }
  70. int CAC3Dec::Init()
  71. {
  72.     if(!initialized){
  73.         InitAC3Dec();
  74.         initialized = true;
  75.     }
  76.     return 1;
  77. }
  78.  
  79. int CAC3Dec::End()
  80. {
  81.  
  82.     return 1;
  83. }
  84.  
  85.  
  86. int CAC3Dec::decodeFrame(short *framedata, int datasize, short *buffer)
  87. {
  88.     ::framedata= framedata;
  89.     ::datasize = datasize;
  90.     if(ac3_frame=ac3_decode_frame())
  91.         memcpy(buffer, ac3_frame->audio_data, FRAME_SIZE);
  92.     else
  93.         memset(buffer, 0, FRAME_SIZE );
  94.  
  95.     return FRAME_SIZE;
  96.  
  97. }
  98.