JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_SingleThreadedAbstractFifo.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26//==============================================================================
64{
65public:
68
71 : size (sizeIn)
72 {
73 // This class only works properly when the size is a power of two.
74 // Use nextPowerOfTwo() to find a good size, and ensure that your
75 // backing storage is the same size.
77 }
78
80 int getRemainingSpace() const { return size - numReadable; }
81
83 int getNumReadable() const { return numReadable; }
84
86 int getSize() const { return size; }
87
94 {
95 const auto startPos = (readPos + numReadable) & (size - 1);
96 const auto maxToWrite = jmin (getRemainingSpace(), num);
97 const auto firstBlockSize = jmin (maxToWrite, size - startPos);
98
99 numReadable += maxToWrite;
100
101 return { { { startPos, startPos + firstBlockSize }, { 0, maxToWrite - firstBlockSize } } };
102 }
103
110 {
111 const auto startPos = readPos;
112 const auto maxToRead = jmin (numReadable, num);
113 const auto firstBlockSize = jmin (maxToRead, size - startPos);
114
115 readPos = (startPos + maxToRead) & (size - 1);
116 numReadable -= maxToRead;
117
118 return { { { startPos, startPos + firstBlockSize }, { 0, maxToRead - firstBlockSize } } };
119 }
120
121private:
122 int size = 0, readPos = 0, numReadable = 0;
123};
124
125
126} // namespace juce
Encapsulates the logic for a single-threaded FIFO.
SingleThreadedAbstractFifo(int sizeIn)
Creates a SingleThreadedAbstractFifo that can manage a buffer of the specified size.
SingleThreadedAbstractFifo()=default
Creates a SingleThreadedAbstractFifo with no size.
int getRemainingSpace() const
Returns the number of unused elements present in the buffer.
std::array< Range< int >, 2 > read(int num)
Returns two blocks in the buffer from which new items may be read.
int getSize() const
Returns the size of the managed buffer.
std::array< Range< int >, 2 > write(int num)
Returns two blocks in the buffer where new items may be written.
int getNumReadable() const
Returns the number of pending elements present in the buffer.
#define jassert(expression)
Platform-independent assertion macro.
JUCE Namespace.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
constexpr bool isPowerOfTwo(IntegerType value)
Returns true if the specified integer is a power-of-two.