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:
25 ~SampleTrack() override;
26
27 const TypeInfo &GetTypeInfo() const override;
28 static const TypeInfo &ClassTypeInfo();
29
30 virtual sampleFormat GetSampleFormat() const = 0;
31
34
35 // Old gain is used in playback in linearly interpolating
36 // the gain.
37 virtual float GetOldChannelGain(int channel) const = 0;
38
39 virtual double GetRate() const = 0;
40
42 virtual void GetEnvelopeValues(double *buffer, size_t bufferLen,
43 double t0) const = 0;
44
46 virtual float GetChannelGain(int channel) const = 0;
47
49 virtual size_t GetBestBlockSize(sampleCount t) const = 0;
50
52 virtual size_t GetMaxBlockSize() const = 0;
53
56
58
67 bool GetFloats(float *buffer, sampleCount start, size_t len,
68 fillFormat fill = fillZero, bool mayThrow = true,
69 sampleCount * pNumWithinClips = nullptr) const
70 {
72 return Get(reinterpret_cast<samplePtr>(buffer),
73 floatSample, start, len, fill, mayThrow, pNumWithinClips);
74 }
75
77
81 virtual bool Get(samplePtr buffer, sampleFormat format,
82 sampleCount start, size_t len,
83 fillFormat fill = fillZero,
84 bool mayThrow = true,
85 // Report how many samples were copied from within clips, rather than
86 // filled according to fillFormat; but these were not necessarily one
87 // contiguous range.
88 sampleCount * pNumWithinClips = nullptr) const = 0;
89
103 sampleCount TimeToLongSamples(double t0) const;
109 double LongSamplesToTime(sampleCount pos) const;
110};
111
113
114class SAMPLE_TRACK_API WritableSampleTrack /* not final */
115 : public SampleTrack
116{
117public:
122
123 const TypeInfo &GetTypeInfo() const override;
124 static const TypeInfo &ClassTypeInfo();
125
126 virtual void SetOldChannelGain(int channel, float gain) = 0;
127
134 size_t len, unsigned int stride=1) = 0;
135
137 virtual void Flush() = 0;
138};
139
141
142#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:916
static const TypeInfo & ClassTypeInfo()
Definition: Track.cpp:1326
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:67
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:281
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:19
Empty argument passed to some public constructors.
Definition: Track.h:232