Audacity 3.2.0
SampleBlock.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5SampleBlock.cpp
6
7**********************************************************************/
8
9
11#include "SampleBlock.h"
12#include "SampleFormat.h"
13
14#include <wx/defs.h>
15
17{
18 auto &factory = Factory::Get();
19 if ( ! factory )
21 return factory( project );
22}
23
25
27 size_t numsamples,
28 sampleFormat srcformat)
29{
30 auto result = DoCreate(src, numsamples, srcformat);
31 if (!result)
34 return result;
35}
36
38 size_t numsamples,
39 sampleFormat srcformat)
40{
41 auto result = DoCreateSilent(numsamples, srcformat);
42 if (!result)
45 return result;
46}
47
49 sampleFormat srcformat,
50 const AttributesList &attrs)
51{
52 auto result = DoCreateFromXML(srcformat, attrs);
53 if (!result)
56 return result;
57}
58
60 sampleFormat srcformat, SampleBlockID id)
61{
62 auto result = DoCreateFromId(srcformat, id);
63 if (!result)
66 return result;
67}
68
70
72 sampleFormat destformat,
73 size_t sampleoffset,
74 size_t numsamples, bool mayThrow)
75{
76 try{ return DoGetSamples(dest, destformat, sampleoffset, numsamples); }
77 catch( ... ) {
78 if( mayThrow )
79 throw;
80 ClearSamples( dest, destformat, 0, numsamples );
81 return 0;
82 }
83}
84
86 size_t start, size_t len, bool mayThrow)
87{
88 try{ return DoGetMinMaxRMS(start, len); }
89 catch( ... ) {
90 if( mayThrow )
91 throw;
92 return {};
93 }
94}
95
97{
98 try{ return DoGetMinMaxRMS(); }
99 catch( ... ) {
100 if( mayThrow )
101 throw;
102 return {};
103 }
104}
105
static RegisteredToolbarFactory factory
std::shared_ptr< SampleBlock > SampleBlockPtr
Definition: CloudSyncDTO.h:25
long long SampleBlockID
Definition: CloudSyncDTO.h:26
MessageBoxException for violation of preconditions or assertions.
#define THROW_INCONSISTENCY_EXCEPTION
Throw InconsistencyException, using C++ preprocessor to identify the source code location.
std::shared_ptr< SampleBlockFactory > SampleBlockFactoryPtr
Definition: SampleBlock.h:31
void ClearSamples(samplePtr dst, sampleFormat format, size_t start, size_t len)
sampleFormat
The ordering of these values with operator < agrees with the order of increasing bit width.
Definition: SampleFormat.h:30
char * samplePtr
Definition: SampleFormat.h:57
const char * constSamplePtr
Definition: SampleFormat.h:58
const auto project
std::vector< Attribute > AttributesList
Definition: XMLTagHandler.h:40
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
CallbackReturn Publish(const SampleBlockCreateMessage &message)
Send a message to connected callbacks.
Definition: Observer.h:207
SampleBlockPtr CreateFromId(sampleFormat srcformat, SampleBlockID id)
Definition: SampleBlock.cpp:59
virtual SampleBlockPtr DoCreateFromXML(sampleFormat srcformat, const AttributesList &attrs)=0
static SampleBlockFactoryPtr New(AudacityProject &project)
Definition: SampleBlock.cpp:16
SampleBlockPtr CreateSilent(size_t numsamples, sampleFormat srcformat)
Definition: SampleBlock.cpp:37
virtual ~SampleBlockFactory()
virtual SampleBlockPtr DoCreateSilent(size_t numsamples, sampleFormat srcformat)=0
SampleBlockPtr Create(constSamplePtr src, size_t numsamples, sampleFormat srcformat)
Definition: SampleBlock.cpp:26
virtual SampleBlockPtr DoCreate(constSamplePtr src, size_t numsamples, sampleFormat srcformat)=0
SampleBlockPtr CreateFromXML(sampleFormat srcformat, const AttributesList &attrs)
Definition: SampleBlock.cpp:48
virtual SampleBlockPtr DoCreateFromId(sampleFormat srcformat, SampleBlockID id)=0
MinMaxRMS GetMinMaxRMS(size_t start, size_t len, bool mayThrow=true)
Gets extreme values for the specified region.
Definition: SampleBlock.cpp:85
virtual MinMaxRMS DoGetMinMaxRMS() const =0
size_t GetSamples(samplePtr dest, sampleFormat destformat, size_t sampleoffset, size_t numsamples, bool mayThrow=true)
Definition: SampleBlock.cpp:71
virtual size_t DoGetSamples(samplePtr dest, sampleFormat destformat, size_t sampleoffset, size_t numsamples)=0
virtual ~SampleBlock()