home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2001 September / PC-WELT 9-2001.ISO / software / hw / brennen / flask_src.exe / Audio / Audio.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-08  |  4.6 KB  |  197 lines

  1.  
  2. /* 
  3.  *  Audio.h
  4.  *
  5.  *    Copyright (C) Alberto Vigata - January 2000 - ultraflask@yahoo.com
  6.  *
  7.  *  This file is part of FlasKMPEG, a free MPEG to MPEG/AVI converter
  8.  *    
  9.  *  FlasKMPEG is free software; you can redistribute it and/or modify
  10.  *  it under the terms of the GNU General Public License as published by
  11.  *  the Free Software Foundation; either version 2, or (at your option)
  12.  *  any later version.
  13.  *   
  14.  *  FlasKMPEG is distributed in the hope that it will be useful,
  15.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  *  GNU General Public License for more details.
  18.  *   
  19.  *  You should have received a copy of the GNU General Public License
  20.  *  along with GNU Make; see the file COPYING.  If not, write to
  21.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  22.  *
  23.  */
  24.  
  25. #if !defined(AFX_AUDIO_H__8B6E2FE2_9AC7_11D3_8C3D_00000100CF13__INCLUDED_)
  26. #define AFX_AUDIO_H__8B6E2FE2_9AC7_11D3_8C3D_00000100CF13__INCLUDED_
  27.  
  28.  
  29. #if _MSC_VER > 1000
  30. #pragma once
  31. #endif // _MSC_VER > 1000
  32.  
  33. #include "..\Demux\Demux.h"
  34. #include "..\FlasKMPEG.h"    // Added by ClassView
  35. #include "..\BitsGetter.h"
  36. #include ".\Resampler\Resampler.h"
  37. #include ".\AudFrameBuffer.h"
  38. #include "AC3\CAC3Dec.h"    
  39. #include "MPEG\MPEGDec.h"
  40. #include ".\Utils\AudioCompressor.h"
  41.  
  42. #define  AUDIO_BUFFER_SIZE 40000
  43. #define  PCM_BUFFER_SIZE 96000
  44. #define AC3_PCM_SAMPLES 1536 //2 channels * 16 bit * 1536 samples
  45. #define   PCM_1SECOND_SIZE 192000
  46. #define   SEQUENCE_END_CODE       0x1B7
  47. #define   AC3_SYNC_WORD    0x0B77
  48. #define   MPEG_SYNC_WORD   0x0FFF
  49.  
  50. #ifndef ABS
  51. #define ABS(x)         ( (x>0)? x: -x)
  52. #endif
  53.  
  54. #define CLK_ERROR(x,y) (ABS( (i64)x - (i64)y) )
  55. #define CLK_THRESHOLD       250
  56. #define CLK_THRESHOLD_SPAN  1000
  57. struct TTimeSpan{
  58.     i64  start;
  59.     i64  end;
  60. };
  61.  
  62. struct PESdata{
  63.     PESinfo         pInfo;
  64.      ui8           *data;
  65.     ui32            datasize;
  66. };
  67.  
  68. struct TReadSpanRunState{
  69.     bool    firstTime;
  70.     bool    frame_in_course;
  71.     bool    header_in_course;
  72.  
  73.     ui64    lastSCR;
  74.     ui32    lastPackBytes;
  75.     ui32    lastMuxrate;
  76.  
  77.     TAudFramePresInfo frame_pInfo;
  78.  
  79.     ui32    frame_size;
  80.     ui32    frame_remaining_bytes;
  81.     ui8     frame_data[65000];
  82.     ui32    out_ptr;
  83.     ui32    in_ptr;
  84.  
  85.      i64    delta;
  86.     PESdata PES;
  87. };
  88.  
  89.  
  90. ////////////////////////////////////
  91. //    AC3  frame size tables
  92. ////////////////////////////////////
  93. struct TFrameSize
  94. {
  95.     ui16 bit_rate;
  96.     ui16 frm_size[3];
  97. };
  98.  
  99.  
  100.  
  101. class Audio: public CDemux, public CDataSource
  102. {
  103. protected:
  104.     CBits *b;
  105.  
  106. public:
  107.     int subStreamID;
  108.     int streamID;
  109.     i64 PCM_PTS;
  110.  
  111.     int GetSamples(int frame, short **buffer, int nSamples);
  112.  
  113.     char   sBitRate[256];
  114.     char   sAudioMode[256];
  115.     char   sSampleRate[256];
  116.     int    sampleRate;
  117.  
  118.     i64 sysClock;
  119.     int SeekAudio(i64 pos);
  120.     int GetAudioDSC(i64 PTS, i64 videoStreamPos);
  121.     int SeekPTS(i64 PTS, i64 searchTop);
  122.     int GetAudio();
  123.     int Stop();
  124.     int Start(char* inputFile, int audioMode);
  125.     int Start(int out_sFreq, i64 PTS, int audioMode);
  126.     int read(char *buffer);
  127.  
  128.     Audio( char *inputFile, int streamID, int subStreamID, int mode);
  129.     ~Audio();
  130.     bool   isAC3, isMPEG;
  131. private:
  132.     int decodeFrame( CAudioFrame *frame ,short *pcm_samples);
  133.     int GetAudioProperties();
  134.     int ParseHeader(ui32 headers_found);
  135.     int FindHeader(ui32 headers_found);
  136.     int RetrieveFrameData();
  137.     int ReadSpanInit();
  138.     void ParseFrameData();
  139.  
  140.     CAC3Dec  *AC3Dec;
  141.     CMPEGDec *MPEGDec;
  142.  
  143.     CAudioCompressor AC;
  144.  
  145.     int                 ReadSpan( TTimeSpan *span, i64 time);
  146.     TReadSpanRunState   read_state;
  147.     bool doResampling;
  148.     double sampleTime;
  149.     int zeroSamplesToPad;
  150.     int audioMode;
  151.     
  152.     CAsyncBuffer *decoded_samples_buffer;
  153.     CAsyncBuffer *ResamplerBuffer;
  154.  
  155.     CResampler          *resampler;
  156.     CAudFrameBuffer     *frameFIFO;
  157.  
  158.     i64 startPTS;
  159.     bool firstPTSfound;
  160.     i64 prevSysClk;
  161.  
  162.     //read() variables. Cannot be static because they can't be shared
  163.     //                  between object instances
  164.     bool  frame_in_progress;
  165.     ui32  fip_remaining_bytes;
  166.     short temp_decoded_frame[1536*2];
  167.     ui32  temp_decoded_ptr;
  168.      i64  aud_clk, tot_n_samples;
  169.  
  170.     // GetAudioDSC()
  171.     i64 firstPTS;
  172.  
  173.     // ParseHeader()
  174.     int header_pos;
  175.     ui8 hdr2, hdr3, mpeg_header[3];
  176.  
  177.     // MPEG audio stuff
  178.     ui8  bit_rate_index;
  179.     ui32 bitrate;
  180.     ui32 mpeg_layer;
  181.     ui8  sampling_frequency;
  182.     ui8  padding_bit;
  183.     ui32 N;
  184.  
  185.  
  186.     int        AlignFrame();
  187.     int    EndWritingFrame();
  188.  
  189.     bool   justStarted;
  190.     bool   stopDecoder;
  191.     bool   decoderStopped;
  192.     char   buffer[AUDIO_BUFFER_SIZE];        
  193.     FILE            *hOutputFile;
  194. };
  195.  
  196. #endif // !defined(AFX_AUDIO_H__8B6E2FE2_9AC7_11D3_8C3D_00000100CF13__INCLUDED_)
  197.