forked from Sneeds-Feed-and-Seed/sneedacity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRingBuffer.h
55 lines (39 loc) · 1.29 KB
/
RingBuffer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**********************************************************************
Sneedacity: A Digital Audio Editor
RingBuffer.h
Dominic Mazzoni
*******************************************************************/
#ifndef __SNEEDACITY_RING_BUFFER__
#define __SNEEDACITY_RING_BUFFER__
#include "SampleFormat.h"
#include <atomic>
class RingBuffer final : public NonInterferingBase {
public:
RingBuffer(sampleFormat format, size_t size);
~RingBuffer();
//
// For the writer only:
//
size_t AvailForPut();
//! Does not apply dithering
size_t Put(samplePtr buffer, sampleFormat format, size_t samples,
// optional number of trailing zeroes
size_t padding = 0);
size_t Clear(sampleFormat format, size_t samples);
//
// For the reader only:
//
size_t AvailForGet();
//! Does not apply dithering
size_t Get(samplePtr buffer, sampleFormat format, size_t samples);
size_t Discard(size_t samples);
private:
size_t Filled( size_t start, size_t end );
size_t Free( size_t start, size_t end );
// Align the two atomics to avoid false sharing
NonInterfering< std::atomic<size_t> > mStart { 0 }, mEnd{ 0 };
const size_t mBufferSize;
sampleFormat mFormat;
SampleBuffer mBuffer;
};
#endif /* __SNEEDACITY_RING_BUFFER__ */