CLAM-Development
1.1
|
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 #ifndef __AUDIOCODECS_STREAM__ 00023 #define __AUDIOCODECS_STREAM__ 00024 00025 #include "DataTypes.hxx" 00026 #include "Array.hxx" 00027 #include "DataTypes.hxx" 00028 #include <vector> 00029 00030 namespace CLAM 00031 { 00032 00033 class AudioFile; 00034 00035 namespace AudioCodecs 00036 { 00044 class Stream 00045 { 00046 public: 00047 Stream(); 00048 virtual ~Stream(); 00049 00050 virtual void SetFOI( const AudioFile& ) = 0; 00051 virtual void PrepareReading() = 0; 00052 virtual void PrepareWriting() = 0; 00053 virtual void PrepareReadWrite() = 0; 00054 virtual void Dispose() = 0; 00055 00056 void DeactivateStrictStreaming(); 00057 void ActivateStrictStreaming(); 00058 bool StrictStreaming() const; 00059 00060 bool ReadData( int channel, TData* ptr, TSize howmany ); 00061 bool ReadData( int* channels, int nchannels, 00062 TData** samples, TSize howmany ); 00063 00064 void WriteData( int channel, const TData* ptr, TSize howmany ); 00065 void WriteData( int* channels, int nchannels, 00066 TData** const samples, TSize howmany ); 00067 00068 bool WasSomethingRead() const; 00069 00070 00071 00072 protected: 00073 virtual void DiskToMemoryTransfer() = 0; 00074 virtual void MemoryToDiskTransfer() = 0; 00075 00076 bool AllChannelsConsumed(); 00077 void ResetConsumedChannels(); 00078 void MarkAllChannelsAsConsumed(); 00079 00080 bool AllChannelsProduced(); 00081 void ResetProducedChannels(); 00082 void MarkAllChannelsAsProduced(); 00083 00084 void SetChannels( TSize nChannels ); 00085 00086 protected: 00087 TSize mChannels; 00088 std::vector<bool> mChannelsConsumed; 00089 std::vector<bool> mChannelsProduced; 00090 bool mStrictStreaming; 00091 DataArray mInterleavedData; 00092 DataArray mInterleavedDataOut; 00093 bool mEOFReached; 00094 TSize mFramesToRead; 00095 TSize mFramesToWrite; 00096 TSize mFramesLastRead; 00097 00098 private: 00099 void CheckForFileReading( TSize samplesToRead ); 00100 void PrepareFileWriting( TSize samplesToWrite ); 00101 00102 static bool HandleReAllocation( DataArray& buffer, TSize newSize ); 00103 00104 }; 00105 00106 00107 inline bool Stream::WasSomethingRead() const 00108 { 00109 return mFramesLastRead != 0; 00110 } 00111 00112 // inline methods 00113 inline void Stream::ActivateStrictStreaming() 00114 { 00115 mStrictStreaming = true; 00116 } 00117 00118 inline void Stream::DeactivateStrictStreaming() 00119 { 00120 mStrictStreaming = false; 00121 } 00122 00123 inline bool Stream::StrictStreaming() const 00124 { 00125 return mStrictStreaming; 00126 } 00127 00128 } 00129 00130 } 00131 00132 #endif // AudioCodecs_Stream.hxx 00133