CLAM-Development  1.4.0
AudioCodecs_Stream.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #ifndef __AUDIOCODECS_STREAM__
23 #define __AUDIOCODECS_STREAM__
24 
25 #include "DataTypes.hxx"
26 #include "DataTypes.hxx"
27 #include <vector>
28 
29 namespace CLAM
30 {
31 
32  class AudioFile;
33 
34 namespace AudioCodecs
35 {
43  class Stream
44  {
45  public:
46  Stream();
47  virtual ~Stream();
49  virtual void PrepareReading() = 0;
51  virtual void PrepareWriting() = 0;
53  virtual void Dispose() = 0;
56  virtual void SeekTo(unsigned long framePosition) {}
58  virtual unsigned long GetFramePosition() const {return mFramePosition;}
59  protected:
61  virtual void DiskToMemoryTransfer() = 0;
63  virtual void MemoryToDiskTransfer() = 0;
64 
65  public:
67  bool ReadData( int channel, TData* buffer, unsigned nFrames );
69  bool ReadData( TData** buffers, unsigned nFrames );
71  bool ReadData( int* channels, int nchannels,
72  TData** buffers, unsigned nFrames );
73 
75  void WriteData( int channel, const TData* buffer, unsigned nFrames );
77  void WriteData( TData** const buffers, unsigned nFrames );
79  void WriteData( int* channels, int nchannels,
80  TData** const buffers, unsigned nFrames );
81 
82  protected:
83  void SetChannels( unsigned nChannels );
84 
85  protected:
86  unsigned mChannels;
87  std::vector<TData> mInterleavedData;
89  unsigned mFramesLastRead;
90  unsigned long mFramePosition;
91 
92  private:
93  void AdjustInterleavedBuffer( unsigned nFrames );
94  };
95 }
96 
97 }
98 
99 #endif // AudioCodecs_Stream.hxx
100