home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * Audio.h
- *
- * Copyright (C) Alberto Vigata - January 2000 - ultraflask@yahoo.com
- *
- * This file is part of FlasKMPEG, a free MPEG to MPEG/AVI converter
- *
- * FlasKMPEG is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * FlasKMPEG is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
- #if !defined(AFX_AUDIO_H__8B6E2FE2_9AC7_11D3_8C3D_00000100CF13__INCLUDED_)
- #define AFX_AUDIO_H__8B6E2FE2_9AC7_11D3_8C3D_00000100CF13__INCLUDED_
-
-
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
-
- #include "..\Demux\Demux.h"
- #include "..\FlasKMPEG.h" // Added by ClassView
- #include "..\BitsGetter.h"
- #include ".\Resampler\Resampler.h"
- #include ".\AudFrameBuffer.h"
- #include "AC3\CAC3Dec.h"
- #include "MPEG\MPEGDec.h"
- #include ".\Utils\AudioCompressor.h"
-
- #define AUDIO_BUFFER_SIZE 40000
- #define PCM_BUFFER_SIZE 96000
- #define AC3_PCM_SAMPLES 1536 //2 channels * 16 bit * 1536 samples
- #define PCM_1SECOND_SIZE 192000
- #define SEQUENCE_END_CODE 0x1B7
- #define AC3_SYNC_WORD 0x0B77
- #define MPEG_SYNC_WORD 0x0FFF
-
- #ifndef ABS
- #define ABS(x) ( (x>0)? x: -x)
- #endif
-
- #define CLK_ERROR(x,y) (ABS( (i64)x - (i64)y) )
- #define CLK_THRESHOLD 250
- #define CLK_THRESHOLD_SPAN 1000
- struct TTimeSpan{
- i64 start;
- i64 end;
- };
-
- struct PESdata{
- PESinfo pInfo;
- ui8 *data;
- ui32 datasize;
- };
-
- struct TReadSpanRunState{
- bool firstTime;
- bool frame_in_course;
- bool header_in_course;
-
- ui64 lastSCR;
- ui32 lastPackBytes;
- ui32 lastMuxrate;
-
- TAudFramePresInfo frame_pInfo;
-
- ui32 frame_size;
- ui32 frame_remaining_bytes;
- ui8 frame_data[65000];
- ui32 out_ptr;
- ui32 in_ptr;
-
- i64 delta;
- PESdata PES;
- };
-
-
- ////////////////////////////////////
- // AC3 frame size tables
- ////////////////////////////////////
- struct TFrameSize
- {
- ui16 bit_rate;
- ui16 frm_size[3];
- };
-
-
-
- class Audio: public CDemux, public CDataSource
- {
- protected:
- CBits *b;
-
- public:
- int subStreamID;
- int streamID;
- i64 PCM_PTS;
-
- int GetSamples(int frame, short **buffer, int nSamples);
-
- char sBitRate[256];
- char sAudioMode[256];
- char sSampleRate[256];
- int sampleRate;
-
- i64 sysClock;
- int SeekAudio(i64 pos);
- int GetAudioDSC(i64 PTS, i64 videoStreamPos);
- int SeekPTS(i64 PTS, i64 searchTop);
- int GetAudio();
- int Stop();
- int Start(char* inputFile, int audioMode);
- int Start(int out_sFreq, i64 PTS, int audioMode);
- int read(char *buffer);
-
- Audio( char *inputFile, int streamID, int subStreamID, int mode);
- ~Audio();
- bool isAC3, isMPEG;
- private:
- int decodeFrame( CAudioFrame *frame ,short *pcm_samples);
- int GetAudioProperties();
- int ParseHeader(ui32 headers_found);
- int FindHeader(ui32 headers_found);
- int RetrieveFrameData();
- int ReadSpanInit();
- void ParseFrameData();
-
- CAC3Dec *AC3Dec;
- CMPEGDec *MPEGDec;
-
- CAudioCompressor AC;
-
- int ReadSpan( TTimeSpan *span, i64 time);
- TReadSpanRunState read_state;
- bool doResampling;
- double sampleTime;
- int zeroSamplesToPad;
- int audioMode;
-
- CAsyncBuffer *decoded_samples_buffer;
- CAsyncBuffer *ResamplerBuffer;
-
- CResampler *resampler;
- CAudFrameBuffer *frameFIFO;
-
- i64 startPTS;
- bool firstPTSfound;
- i64 prevSysClk;
-
- //read() variables. Cannot be static because they can't be shared
- // between object instances
- bool frame_in_progress;
- ui32 fip_remaining_bytes;
- short temp_decoded_frame[1536*2];
- ui32 temp_decoded_ptr;
- i64 aud_clk, tot_n_samples;
-
- // GetAudioDSC()
- i64 firstPTS;
-
- // ParseHeader()
- int header_pos;
- ui8 hdr2, hdr3, mpeg_header[3];
-
- // MPEG audio stuff
- ui8 bit_rate_index;
- ui32 bitrate;
- ui32 mpeg_layer;
- ui8 sampling_frequency;
- ui8 padding_bit;
- ui32 N;
-
-
- int AlignFrame();
- int EndWritingFrame();
-
- bool justStarted;
- bool stopDecoder;
- bool decoderStopped;
- char buffer[AUDIO_BUFFER_SIZE];
- FILE *hOutputFile;
- };
-
- #endif // !defined(AFX_AUDIO_H__8B6E2FE2_9AC7_11D3_8C3D_00000100CF13__INCLUDED_)
-