00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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