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 #include "Array.hxx" 00037 00038 namespace CLAM 00039 { 00040 00041 namespace AudioCodecs 00042 { 00043 class OggVorbisAudioStream : public Stream 00044 { 00045 00046 public: 00047 OggVorbisAudioStream(); 00048 OggVorbisAudioStream( const AudioFile& file ); 00049 00050 ~OggVorbisAudioStream(); 00051 00052 void SetFOI( const AudioFile& file ); 00053 00054 void PrepareReading(); 00055 void PrepareWriting(); 00056 void PrepareReadWrite(); 00057 void Dispose(); 00058 00059 protected: 00060 void AudioFileToNative( const AudioFile& file ); 00061 void DiskToMemoryTransfer(); 00062 void MemoryToDiskTransfer(); 00063 00064 void VorbisI_EncoderSetup(); 00065 void WriteBitstreamHeader(); 00066 00067 void DoVorbisAnalysis(); 00068 void PushAnalysisBlocksOntoOggStream(); 00069 void ConsumeDecodedSamples(); 00070 00071 protected: 00072 std::string mName; 00073 FILE* mFileHandle; 00074 OggVorbis_File mNativeFileParams; 00075 int mCurrentSection; 00076 bool mValidFileParams; 00077 00078 // Structs needed for Vorbis encoding 00079 vorbis_info mStreamInfo; 00080 vorbis_comment mFileComments; 00081 00082 ogg_stream_state mOggStreamState; // os 00083 ogg_page mOggPage; // og 00084 ogg_packet mOggPacket; // op 00085 vorbis_dsp_state mDSPState; // vd 00086 vorbis_block mVorbisBlock; // vb 00087 00088 int mEncodedSampleRate; 00089 int mEncodedChannels; 00090 bool mEncoding; 00091 int mOffset; 00092 00093 static const TSize mMaxBlockSize; 00094 static const TSize mAnalysisWindowSize; 00095 Array<TInt16> mBlockBuffer; 00096 std::vector<std::deque<TData> > mEncodeBuffer; 00097 std::deque<TInt16> mDecodeBuffer; 00098 00099 TSize mLastBytesRead; 00100 }; 00101 } 00102 00103 } 00104 00105 #endif // OggVorbisAudioStream.hxx 00106