Audacity 3.2.0
SampleTrack.h
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5SampleTrack.h
6@brief abstract Track sub-type that maps times to sample values
7
8Paul Licameli split from WaveTrack.h
9
10**********************************************************************/
11
12#ifndef __AUDACITY_SAMPLE_TRACK__
13#define __AUDACITY_SAMPLE_TRACK__
14
15#include "SampleCount.h"
16#include "SampleFormat.h"
17#include "Track.h"
18
19enum class sampleFormat : unsigned;
20
21class SampleTrack;
22
27>;
28
29class SAMPLE_TRACK_API SampleTrack /* not final */
30 : public PlayableTrack
32{
33public:
35
38 ~SampleTrack() override;
39
40 const TypeInfo &GetTypeInfo() const override;
41 static const TypeInfo &ClassTypeInfo();
42
43 virtual sampleFormat GetSampleFormat() const = 0;
44
47
48 virtual double GetRate() const = 0;
49
52
54 virtual bool HasTrivialEnvelope() const = 0;
55
57 virtual void GetEnvelopeValues(double *buffer, size_t bufferLen,
58 double t0) const = 0;
59
61 virtual float GetChannelGain(int channel) const = 0;
62
64 virtual size_t GetBestBlockSize(sampleCount t) const = 0;
65
67 virtual size_t GetMaxBlockSize() const = 0;
68
71
73
82 bool GetFloats(float *buffer, sampleCount start, size_t len,
83 fillFormat fill = fillZero, bool mayThrow = true,
84 sampleCount * pNumWithinClips = nullptr) const
85 {
87 return Get(reinterpret_cast<samplePtr>(buffer),
88 floatSample, start, len, fill, mayThrow, pNumWithinClips);
89 }
90
92
96 virtual bool Get(samplePtr buffer, sampleFormat format,
97 sampleCount start, size_t len,
98 fillFormat fill = fillZero,
99 bool mayThrow = true,
100 // Report how many samples were copied from within clips, rather than
101 // filled according to fillFormat; but these were not necessarily one
102 // contiguous range.
103 sampleCount * pNumWithinClips = nullptr) const = 0;
104
118 sampleCount TimeToLongSamples(double t0) const;
124 double LongSamplesToTime(sampleCount pos) const;
125};
126
128
129class SAMPLE_TRACK_API WritableSampleTrack /* not final */
130 : public SampleTrack
131{
132public:
137
138 const TypeInfo &GetTypeInfo() const override;
139 static const TypeInfo &ClassTypeInfo();
140
147 size_t len, unsigned int stride=1,
148 sampleFormat effectiveFormat = widestSampleFormat
154 ) = 0;
155
157 virtual void Flush() = 0;
158};
159
161
162#endif
int format
Definition: ExportPCM.cpp:53
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:55
const char * constSamplePtr
Definition: SampleFormat.h:56
constexpr sampleFormat widestSampleFormat
Definition: SampleFormat.h:45
fillFormat
Definition: SampleFormat.h:59
@ fillZero
Definition: SampleFormat.h:60
ClientData::Site< SampleTrack, ClientData::Cloneable< ClientData::UniquePtr >, ClientData::DeepCopying > SampleTrackAttachments
Definition: SampleTrack.h:27
declares abstract base class Track, TrackList, and iterators over TrackList
#define ENUMERATE_TRACK_TYPE(T)
This macro should be called immediately after each definition of a track subtype.
Definition: Track.h:126
Utility to register hooks into a host class that attach client data.
Definition: ClientData.h:220
Subclass & Get(const RegisteredFactory &key)
Get reference to an attachment, creating on demand if not present, down-cast it to Subclass.
Definition: ClientData.h:309
AudioTrack subclass that can also be audibly replayed by the program.
Definition: Track.h:917
static const TypeInfo & ClassTypeInfo()
Definition: Track.cpp:1327
virtual double GetRate() const =0
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
Retrieve samples from a track in floating-point format, regardless of the storage format.
Definition: SampleTrack.h:82
virtual float GetChannelGain(int channel) const =0
Takes gain and pan into account.
~SampleTrack() override
virtual bool Get(samplePtr buffer, sampleFormat format, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const =0
Retrieve samples from a track in a specified format.
virtual void GetEnvelopeValues(double *buffer, size_t bufferLen, double t0) const =0
Fetch envelope values corresponding to uniformly separated sample times starting at the given time.
virtual size_t GetMaxBlockSize() const =0
This returns a nonnegative number of samples meant to size a memory buffer.
virtual bool HasTrivialEnvelope() const =0
virtual sampleCount GetBlockStart(sampleCount t) const =0
This returns a possibly large or negative value.
virtual sampleFormat WidestEffectiveFormat() const =0
virtual size_t GetBestBlockSize(sampleCount t) const =0
This returns a nonnegative number of samples meant to size a memory buffer.
virtual ChannelType GetChannelIgnoringPan() const =0
virtual sampleFormat GetSampleFormat() const =0
virtual const TypeInfo & GetTypeInfo() const =0
ChannelType
Definition: Track.h:282
virtual void Flush()=0
Flush must be called after last Append.
virtual bool Append(constSamplePtr buffer, sampleFormat format, size_t len, unsigned int stride=1, sampleFormat effectiveFormat=widestSampleFormat)=0
Append the sample data to the track. You must call Flush() after the last Append.
~WritableSampleTrack() override
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
@ DeepCopying
point to new sub-objects; these must define a Clone() member; won't compile for std::weak_ptr
Empty argument passed to some public constructors.
Definition: Track.h:233