Audacity 3.2.0
SampleTrackCache.h
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5SampleTrackCache.h
6@brief Buffer results to avoid repeated calls to SampleTrack::Get()
7
8Paul Licameli split from WaveTrack.h
9
10**********************************************************************/
11
12#ifndef __AUDACITY_SAMPLE_TRACK_CACHE__
13#define __AUDACITY_SAMPLE_TRACK_CACHE__
14
15#include "SampleCount.h"
16#include "SampleFormat.h"
17#include <memory>
18
19class SampleTrack;
20
22
24class SAMPLE_TRACK_API SampleTrackCache {
25public:
27 : mBufferSize(0)
28 , mOverlapBuffer()
29 , mNValidBuffers(0)
30 {
31 }
32
33 explicit SampleTrackCache(const std::shared_ptr<const SampleTrack> &pTrack)
34 : mBufferSize(0)
35 , mOverlapBuffer()
36 , mNValidBuffers(0)
37 {
38 SetTrack(pTrack);
39 }
41
42 const std::shared_ptr<const SampleTrack>& GetTrack() const { return mPTrack; }
43 void SetTrack(const std::shared_ptr<const SampleTrack> &pTrack);
44
46
49 const float *GetFloats(sampleCount start, size_t len, bool mayThrow);
50
51private:
52 void Free();
53
54 struct Buffer {
58
59 Buffer() : start(0), len(0) {}
60 void Free() { data.reset(); start = 0; len = 0; }
61 sampleCount end() const { return start + len; }
62
63 void swap ( Buffer &other )
64 {
65 data .swap ( other.data );
66 std::swap( start, other.start );
67 std::swap( len, other.len );
68 }
69 };
70
71 std::shared_ptr<const SampleTrack> mPTrack;
73 Buffer mBuffers[2];
76};
77
78#endif
A short-lived object, during whose lifetime, the contents of the WaveTrack are assumed not to change.
GrowableSampleBuffer mOverlapBuffer
const std::shared_ptr< const SampleTrack > & GetTrack() const
std::shared_ptr< const SampleTrack > mPTrack
SampleTrackCache(const std::shared_ptr< const SampleTrack > &pTrack)
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:753
void swap(Buffer &other)
sampleCount end() const