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
19class SAMPLE_TRACK_API SampleTrack /* not final */
20 : public PlayableTrack
21{
22public:
23 ~SampleTrack() override;
24
25 const TypeInfo &GetTypeInfo() const override;
26 static const TypeInfo &ClassTypeInfo();
27
28 virtual sampleFormat GetSampleFormat() const = 0;
29
32
33 // Old gain is used in playback in linearly interpolating
34 // the gain.
35 virtual float GetOldChannelGain(int channel) const = 0;
36
37 virtual double GetRate() const = 0;
38
40 virtual void GetEnvelopeValues(double *buffer, size_t bufferLen,
41 double t0) const = 0;
42
44 virtual float GetChannelGain(int channel) const = 0;
45
47 virtual size_t GetBestBlockSize(sampleCount t) const = 0;
48
50 virtual size_t GetMaxBlockSize() const = 0;
51
54
56
65 bool GetFloats(float *buffer, sampleCount start, size_t len,
66 fillFormat fill = fillZero, bool mayThrow = true,
67 sampleCount * pNumWithinClips = nullptr) const
68 {
70 return Get(reinterpret_cast<samplePtr>(buffer),
71 floatSample, start, len, fill, mayThrow, pNumWithinClips);
72 }
73
75
79 virtual bool Get(samplePtr buffer, sampleFormat format,
80 sampleCount start, size_t len,
81 fillFormat fill = fillZero,
82 bool mayThrow = true,
83 // Report how many samples were copied from within clips, rather than
84 // filled according to fillFormat; but these were not necessarily one
85 // contiguous range.
86 sampleCount * pNumWithinClips = nullptr) const = 0;
87
101 sampleCount TimeToLongSamples(double t0) const;
107 double LongSamplesToTime(sampleCount pos) const;
108};
109
111
112class SAMPLE_TRACK_API WritableSampleTrack /* not final */
113 : public SampleTrack
114{
115public:
117
118 const TypeInfo &GetTypeInfo() const override;
119 static const TypeInfo &ClassTypeInfo();
120
121 virtual void SetOldChannelGain(int channel, float gain) = 0;
122
129 size_t len, unsigned int stride=1) = 0;
130
132 virtual void Flush() = 0;
133};
134
136
137#endif
int format
Definition: ExportPCM.cpp:56
sampleFormat
Definition: SampleFormat.h:29
@ floatSample
Definition: SampleFormat.h:34
char * samplePtr
Definition: SampleFormat.h:49
const char * constSamplePtr
Definition: SampleFormat.h:50
fillFormat
Definition: SampleFormat.h:53
@ fillZero
Definition: SampleFormat.h:54
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:125
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:909
static const TypeInfo & ClassTypeInfo()
Definition: Track.cpp:1303
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:65
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 sampleCount GetBlockStart(sampleCount t) const =0
This returns a possibly large or negative value.
virtual float GetOldChannelGain(int channel) 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:274
virtual void Flush()=0
Flush must be called after last Append.
virtual void SetOldChannelGain(int channel, float gain)=0
virtual bool Append(constSamplePtr buffer, sampleFormat format, size_t len, unsigned int stride=1)=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:18