Audacity  2.2.2
ODPCMAliasBlockFile.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  ODPCMAliasBlockFile.cpp
6 
7  Created by Michael Chinen (mchinen)
8  Audacity(R) is copyright (c) 1999-2008 Audacity Team.
9  License: GPL v2. See License.txt.
10 
11 ******************************************************************//*******************************************************************/
30 
31 
32 
33 
34 
35 
36 #ifndef __AUDACITY_ODPCMALIASBLOCKFILE__
37 #define __AUDACITY_ODPCMALIASBLOCKFILE__
38 
39 #include "PCMAliasBlockFile.h"
40 #include "../BlockFile.h"
41 #include "../ondemand/ODTaskThread.h"
42 #include "../DirManager.h"
43 #include <wx/thread.h>
44 
47 {
48  public:
51  wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart,
52  size_t aliasLen, int aliasChannel);
53  ODPCMAliasBlockFile(wxFileNameWrapper &&existingSummaryFileName,
54  wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart,
55  size_t aliasLen, int aliasChannel,
56  float min, float max, float rms, bool summaryAvailable);
57  virtual ~ODPCMAliasBlockFile();
58 
59  //checks to see if summary data has been computed and written to disk yet. Thread safe. Blocks if we are writing summary data.
60  bool IsSummaryAvailable() const override;
61 
63  bool IsSummaryBeingComputed() override { return mSummaryBeingComputed; }
64 
65  //Calls that rely on summary files need to be overidden
66  DiskByteCount GetSpaceUsage() const override;
68  MinMaxRMS GetMinMaxRMS(
69  size_t start, size_t len, bool mayThrow) const override;
71  MinMaxRMS GetMinMaxRMS(bool mayThrow) const override;
73  bool Read256(float *buffer, size_t start, size_t len) override;
75  bool Read64K(float *buffer, size_t start, size_t len) override;
76 
78  BlockFilePtr Copy(wxFileNameWrapper &&fileName) override;
79 
81  void SaveXML(XMLWriter &xmlFile) override;
82 
84  static BlockFilePtr BuildFromXML(DirManager &dm, const wxChar **attrs);
85 
87  void Recover(void) override;
88 
90  void DoWriteSummary();
91 
93  void SetStart(sampleCount startSample){mStart = startSample;}
94 
96  sampleCount GetStart() const {return mStart;}
97 
99  void Lock();
100 
102  void Unlock();
103 
105  void SetClipOffset(sampleCount numSamples){mClipOffset= numSamples;}
106 
108  sampleCount GetClipOffset() const {return mClipOffset;}
109 
110  //returns the number of samples from the beginning of the track that this blockfile starts at
111  sampleCount GetGlobalStart() const {return mClipOffset+mStart;}
112 
113  //returns the number of samples from the beginning of the track that this blockfile ends at
114  sampleCount GetGlobalEnd() const {return mClipOffset+mStart+GetLength();}
115 
116 
117  //Below calls are overrided just so we can take wxlog calls out, which are not threadsafe.
118 
120  size_t ReadData(samplePtr data, sampleFormat format,
121  size_t start, size_t len, bool mayThrow) const override;
122 
124  bool ReadSummary(ArrayOf<char> &data) override;
125 
127  void SetFileName(wxFileNameWrapper &&name) override;
128  GetFileNameResult GetFileName() const override;
129 
130  //when the file closes, it locks the blockfiles, but only conditionally.
131  // It calls this so we can check if it has been saved before.
132  // not balanced by unlocking calls.
133  void CloseLock() override;
134 
136  void LockRead() const override;
138  void UnlockRead() const override;
139 
140 protected:
141  void WriteSummary() override;
142  void *CalcSummary(samplePtr buffer, size_t len,
143  sampleFormat format, ArrayOf<char> &cleanup) override;
144 
145  private:
146 
148 
149  //need to protect this since it is changed from the main thread upon save.
151 
154 
155  //lock the read data - libsndfile can't handle two reads at once?
157 
162 
164  sampleCount mStart;
165 
167  sampleCount mClipOffset;
168 };
169 
170 #endif
171 
Creates and manages BlockFile objects.
Definition: DirManager.h:54
sampleCount mStart
for reporting after task is complete. Only for display use.
GetFileNameResult GetFileName() const override
sets the file name the summary info will be saved in. threadsafe.
An AliasBlockFile that references uncompressed data in an existing file.
ODLock mAliasedFileNameMutex
Also need to protect the aliased file name.
ODPCMAliasBlockFile(wxFileNameWrapper &&baseFileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel)
Constructs a PCMAliasBlockFile, writing the summary to disk.
bool Read256(float *buffer, size_t start, size_t len) override
Returns the 256 byte summary data block.
void DoWriteSummary()
A public interface to WriteSummary.
void SetClipOffset(sampleCount numSamples)
sets the amount of samples the clip associated with this blockfile is offset in the wavetrack (non ef...
bool IsSummaryBeingComputed() override
Returns TRUE if the summary has not yet been written, but is actively being computed and written to d...
bool Read64K(float *buffer, size_t start, size_t len) override
Returns the 64K summary data block.
void Lock()
Locks the blockfile only if it has a file that exists.
static BlockFilePtr BuildFromXML(DirManager &dm, const wxChar **attrs)
Reconstructs from XML a ODPCMAliasBlockFile and reschedules it for OD loading.
BlockFilePtr Copy(wxFileNameWrapper &&fileName) override
Makes NEW ODPCMAliasBlockFile or PCMAliasBlockFile depending on summary availability.
unsigned long long DiskByteCount
Definition: BlockFile.h:152
std::shared_ptr< BlockFile > BlockFilePtr
Definition: BlockFile.h:48
size_t GetLength() const
Definition: BlockFile.h:114
void SetStart(sampleCount startSample)
Sets the value that indicates where the first sample in this block corresponds to the global sequence...
int format
Definition: ExportPCM.cpp:56
sampleCount GetGlobalStart() const
void Recover(void) override
Writes the summary file if summary data is available.
void * CalcSummary(samplePtr buffer, size_t len, sampleFormat format, ArrayOf< char > &cleanup) override
void Unlock()
Unlocks the blockfile only if it has a file that exists.
int min(int a, int b)
bool IsSummaryAvailable() const override
Returns TRUE if this block's complete summary has been computed and is ready (for OD) ...
sampleCount GetStart() const
Gets the value that indicates where the first sample in this block corresponds to the global sequence...
void SetFileName(wxFileNameWrapper &&name) override
sets the file name the summary info will be saved in. threadsafe.
sampleCount mClipOffset
the ODTask needs to know where this blockfile lies in the track, so for convenience, we have this here.
DiskByteCount GetSpaceUsage() const override
const wxChar * name
Definition: Distortion.cpp:94
MinMaxRMS GetMinMaxRMS(size_t start, size_t len, bool mayThrow) const override
Gets extreme values for the specified region.
sampleCount GetGlobalEnd() const
bool ReadSummary(ArrayOf< char > &data) override
Read the summary into a buffer.
void WriteSummary() override
Write the summary to disk, using the derived ReadData() to get the data.
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:22
void UnlockRead() const override
Allows reading on other threads.
void SaveXML(XMLWriter &xmlFile) override
Saves as xml ODPCMAliasBlockFile or PCMAliasBlockFile depending on summary availability.
size_t ReadData(samplePtr data, sampleFormat format, size_t start, size_t len, bool mayThrow) const override
Reads the specified data from the aliased file using libsndfile.
An AliasBlockFile that references uncompressed data in an existing file.
sampleCount GetClipOffset() const
Gets the number of samples the clip associated with this blockfile is offset by.
void LockRead() const override
Prevents a read on other threads.