Audacity  2.2.0
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 
ODLock mReadDataMutex
Definition: ODPCMAliasBlockFile.h:156
Creates and manages BlockFile objects.
Definition: DirManager.h:52
sampleCount mStart
for reporting after task is complete. Only for display use.
Definition: ODPCMAliasBlockFile.h:164
GetFileNameResult GetFileName() const override
sets the file name the summary info will be saved in. threadsafe.
Definition: ODPCMAliasBlockFile.cpp:373
An AliasBlockFile that references uncompressed data in an existing file.
Definition: ODPCMAliasBlockFile.h:46
ODLock mAliasedFileNameMutex
Also need to protect the aliased file name.
Definition: ODPCMAliasBlockFile.h:153
ODPCMAliasBlockFile(wxFileNameWrapper &&baseFileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel)
Constructs a PCMAliasBlockFile, writing the summary to disk.
Definition: ODPCMAliasBlockFile.cpp:49
ODLock mFileNameMutex
Definition: ODPCMAliasBlockFile.h:150
bool Read256(float *buffer, size_t start, size_t len) override
Returns the 256 byte summary data block.
Definition: ODPCMAliasBlockFile.cpp:172
void DoWriteSummary()
A public interface to WriteSummary.
Definition: ODPCMAliasBlockFile.cpp:357
void SetClipOffset(sampleCount numSamples)
sets the amount of samples the clip associated with this blockfile is offset in the wavetrack (non ef...
Definition: ODPCMAliasBlockFile.h:105
bool IsSummaryBeingComputed() override
Returns TRUE if the summary has not yet been written, but is actively being computed and written to d...
Definition: ODPCMAliasBlockFile.h:63
bool mHasBeenSaved
Definition: ODPCMAliasBlockFile.h:161
ODLock mWriteSummaryMutex
Definition: ODPCMAliasBlockFile.h:147
bool Read64K(float *buffer, size_t start, size_t len) override
Returns the 64K summary data block.
Definition: ODPCMAliasBlockFile.cpp:188
void Lock()
Locks the blockfile only if it has a file that exists.
Definition: ODPCMAliasBlockFile.cpp:101
static BlockFilePtr BuildFromXML(DirManager &dm, const wxChar **attrs)
Reconstructs from XML a ODPCMAliasBlockFile and reschedules it for OD loading.
Definition: ODPCMAliasBlockFile.cpp:277
Definition: wxFileNameWrapper.h:16
BlockFilePtr Copy(wxFileNameWrapper &&fileName) override
Makes NEW ODPCMAliasBlockFile or PCMAliasBlockFile depending on summary availability.
Definition: ODPCMAliasBlockFile.cpp:206
ODLock mSummaryAvailableMutex
Definition: ODPCMAliasBlockFile.h:158
bool mSummaryBeingComputed
Definition: ODPCMAliasBlockFile.h:160
virtual ~ODPCMAliasBlockFile()
Definition: ODPCMAliasBlockFile.cpp:75
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...
Definition: ODPCMAliasBlockFile.h:93
int format
Definition: ExportPCM.cpp:56
bool mSummaryAvailable
Definition: ODPCMAliasBlockFile.h:159
sampleCount GetGlobalStart() const
Definition: ODPCMAliasBlockFile.h:111
void Recover(void) override
Writes the summary file if summary data is available.
Definition: ODPCMAliasBlockFile.cpp:339
void * CalcSummary(samplePtr buffer, size_t len, sampleFormat format, ArrayOf< char > &cleanup) override
Definition: ODPCMAliasBlockFile.cpp:455
void Unlock()
Unlocks the blockfile only if it has a file that exists.
Definition: ODPCMAliasBlockFile.cpp:118
int min(int a, int b)
Definition: CompareAudioCommand.cpp:80
bool IsSummaryAvailable() const override
Returns TRUE if this block's complete summary has been computed and is ready (for OD) ...
Definition: ODPCMAliasBlockFile.cpp:347
void CloseLock() override
Definition: ODPCMAliasBlockFile.cpp:109
sampleCount GetStart() const
Gets the value that indicates where the first sample in this block corresponds to the global sequence...
Definition: ODPCMAliasBlockFile.h:96
void SetFileName(wxFileNameWrapper &&name) override
sets the file name the summary info will be saved in. threadsafe.
Definition: ODPCMAliasBlockFile.cpp:365
sampleCount mClipOffset
the ODTask needs to know where this blockfile lies in the track, so for convenience, we have this here.
Definition: ODPCMAliasBlockFile.h:167
DiskByteCount GetSpaceUsage() const override
Definition: ODPCMAliasBlockFile.cpp:82
Definition: ODTaskThread.h:150
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.
Definition: ODPCMAliasBlockFile.cpp:126
sampleCount GetGlobalEnd() const
Definition: ODPCMAliasBlockFile.h:114
bool ReadSummary(ArrayOf< char > &data) override
Read the summary into a buffer.
Definition: ODPCMAliasBlockFile.cpp:520
void WriteSummary() override
Write the summary to disk, using the derived ReadData() to get the data.
Definition: ODPCMAliasBlockFile.cpp:379
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.
Definition: ODPCMAliasBlockFile.cpp:561
void SaveXML(XMLWriter &xmlFile) override
Saves as xml ODPCMAliasBlockFile or PCMAliasBlockFile depending on summary availability.
Definition: ODPCMAliasBlockFile.cpp:241
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.
Definition: ODPCMAliasBlockFile.cpp:498
An AliasBlockFile that references uncompressed data in an existing file.
Definition: PCMAliasBlockFile.h:18
sampleCount GetClipOffset() const
Gets the number of samples the clip associated with this blockfile is offset by.
Definition: ODPCMAliasBlockFile.h:108
void LockRead() const override
Prevents a read on other threads.
Definition: ODPCMAliasBlockFile.cpp:556