OggVorbisAudioStream.hxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 #if USE_OGGVORBIS != 1
00023 #error USE_OGGVORBIS was not set to 1 in your settings.cfg file, but you are including files that require this. Please fix your settings.cfg
00024 #endif
00025 
00026 #ifndef __OGGVORBISAUDIOSTREAM__
00027 #define __OGGVORBISAUDIOSTREAM__
00028 
00029 #include <string>
00030 #include <vorbis/vorbisfile.h>
00031 #include <vorbis/vorbisenc.h>
00032 #include <deque>
00033 #include <vector>
00034 #include "AudioCodecs_Stream.hxx"
00035 #include "DataTypes.hxx"
00036 
00037 namespace CLAM
00038 {
00039 
00040 namespace AudioCodecs
00041 {
00042         class OggVorbisAudioStream : public Stream
00043         {
00044 
00045         public:
00046                 OggVorbisAudioStream( const AudioFile& file );
00047                 ~OggVorbisAudioStream();
00048 
00049                 void PrepareReading();
00050                 void PrepareWriting();
00051                 void Dispose();
00052                 void SeekTo(unsigned long framePosition);
00053 
00054         protected:
00055                 void DiskToMemoryTransfer();
00056                 void MemoryToDiskTransfer();
00057 
00058         private:
00059                 void VorbisI_EncoderSetup();
00060                 void WriteBitstreamHeader();
00061 
00062                 void DoVorbisAnalysis();
00063                 void PushAnalysisBlocksOntoOggStream();
00064                 void ConsumeDecodedSamples();
00065                 
00066         protected:
00067                 std::string      mName;
00068                 FILE*            mFileHandle;
00069                 OggVorbis_File   mNativeFileParams;
00070                 int              mCurrentSection;
00071                 bool             mValidFileParams;
00072 
00073                 // Structs needed for Vorbis encoding
00074                 vorbis_info        mStreamInfo;
00075                 vorbis_comment     mFileComments;
00076 
00077                 ogg_stream_state   mOggStreamState; // os
00078                 ogg_page           mOggPage;        // og
00079                 ogg_packet         mOggPacket;      // op
00080                 vorbis_dsp_state   mDSPState;       // vd
00081                 vorbis_block       mVorbisBlock;    // vb
00082                 
00083                 int                mEncodedSampleRate;
00084                 bool               mEncoding;
00085 
00086                 static const unsigned     mMaxBlockSize;
00087                 static const unsigned     mAnalysisWindowSize;
00088                 std::vector<TInt16>       mBlockBuffer;
00089                 std::vector<std::deque<TData> >       mEncodeBuffer;
00090                 std::deque<TInt16>      mDecodeBuffer;
00091                 
00092                 TSize                   mLastBytesRead;
00093         };
00094 }
00095 
00096 }
00097 
00098 #endif // OggVorbisAudioStream.hxx
00099 
Generated by  doxygen 1.6.3