RingBuffer | A simple ring buffer for ISR-task communication
kandi X-RAY | RingBuffer Summary
kandi X-RAY | RingBuffer Summary
A ring/cyclic buffer suitable for ISR-Task communication. A C++ 17, templated and stack allocated ring buffer for continuous i/o.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of RingBuffer
RingBuffer Key Features
RingBuffer Examples and Code Snippets
/* Create a ring buffer that stores the last 100 records. */
var bunyan = require('bunyan');
var ringbuffer = new bunyan.RingBuffer({ limit: 100 });
var log = bunyan.createLogger({
name: 'foo',
streams: [
{
level: 'info',
Community Discussions
Trending Discussions on RingBuffer
QUESTION
I very new concepts of audio processing and have a basic knowledge of C++, my end goal is to create a means to measure harmonic distortion on line-in audio; my thoughts are to write audio-in stream to a circular buffer, then read from the circular buffer to an FFT function; from the FFT data I can workout audio distortion.
So far I'm using Portaudio to write streamed audio to the circular buffer from it's streaming input callback; I've created a Thread that checks if there's any data in the circular buffer, if there is data, read it into a temporary buffer. As a means of a simple test, I'm merely echo'ing the number of elements to read from the circular buffer, this works but after a second or so, produces an incorrect value for 'read elements available' (18446744073709542400
) followed by a Segmentation error; sample output and my code below:
ANSWER
Answered 2021-Mar-07 at 17:09RingBuffer::readAvailable()
is returning a small negative number as a size_t
. Since size_t
is an unsigned type and because you're using %lu
in the printf
, it's being displayed as though it's a huge unsigned long
. (Somehow your output has extra digits.)
It's possible RingBuffer
has a bug. It seems to assume that that tail index will always be less then or equal to the head index. I'm not an expert in the memory ordering constraints used in lockless code, but it looks to me like it could be a synchronization problem with when it reads the head and tail to compute the amount available.
QUESTION
I'm working on a WASAPI UWP audio application with cpp/winrt which needs to take audio from an input and send it to an output after being processed.
I want to set my audio thread characteristics with AvSetMmThreadCharacteristicsW(L"Pro Audio", &taskIndex)
, but I just noticed this function (and most of avrt.h
) is limited to WINAPI_PARTITION_DESKTOP
and WINAPI_PARTITION_GAMES
.
I think I need this because when my code is integrated into my UWP app, the audio input is full of discontinuity, and I have no issue in my test code which uses the avrt
API.
Is there another way to configure my thread for audio processing?
Edit: here is my test program https://github.com/loics2/test-wasapi. The interesting part happens in the AudioStream
class. I can't share my UWP app, but I can copy as is these classes into a Windows Runtime Component.
Edit 2: here's the audio thread code :
...ANSWER
Answered 2021-Feb-19 at 14:31@IInspectable was right, there's something wrong with my code : the audio processing is done by a library which then calls callbacks with some results.
In my callback, I try to raise a winrt::event
, but it sometimes takes more than 50ms. When it happens, it blocks the audio thread, and creates discontinuity...
QUESTION
This is the defination for my class.
...ANSWER
Answered 2020-Dec-25 at 08:39rings.get()
:
This is getting raw pointer from rings
which gives you RingBuffer *
rings_->ring1_.get()
:
I suppose you mean rings->ring1_.get()
, which first dereferences rings
and then get raw pointer from member ring1_
. It is the same with rings.get()->ring1_.get()
. The final result is a RingBufferLock *
QUESTION
I have an USB CDC interface on a STM32 to which I send messages which can be longer than one single chunk of 64 bytes. This means I get multiple callbacks of CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
where I would have to copy the incoming data into another buffer (e.g. ringbuffer).
My problem is, how do I know if data belongs to a new message or is a continuation of a previous (larger) one? What I can tell is that if less than 64 bytes arrived I can assume that the message is complete. But if exactly 64 bytes are in the buffer I'd technically have to wait if there are no more messages coming. And even then, how long do I have to wait to not mix them up with a new one?
...ANSWER
Answered 2020-Dec-07 at 20:36USB CDC and all serial protocols derived from RS-232 implement stream-based communication, i.e. a potentially endless stream of bytes.
They do not implement message-based communication. Therefore, they have no concept of messages, and no concept of message start and message end.
The lower layers of USB are message based. So you might observe patterns that look like a message-based communication. You might also think that USB CDC is message based because the STM32cube framework exposes a USB API that will deliver more data whenever a low-level USB message has arrived.
But this behavior can only be observed if small chunks of data are sent with pauses in-between and if the USB bus is mostly idle. It collapses if speed is increased or the USB bus becomes busier.
Then your PC will start to merge chunks of data. This can be easily tested by sending 100 times 10 bytes as fast as possible. The first 10 bytes are likely sent in its own packet. But the remaining data will be merged and sent as packets of 64 bytes (except for the last few bytes).
So if you want to have a message-oriented protocol on top of stream-oriented protocol, the two typical approaches are:
Use a delimiter between messages. As an example: If you have a human-readable text protocol, a linefeed is often used as the delimiter. Once you encounter a linefeed character, you know you have a complete message (i.e. line).
Use a length indicator at the end of the message. This is useful for binary protocols. The first two bytes could contain the message length in bytes, encoded as a 16-bit number. So will be obvious when the message is complete.
Also note that a received packet can contain several message, or the end of a message and the start of the next message.
QUESTION
I use the file where I declare and init a struct
...ANSWER
Answered 2020-Nov-08 at 09:50The function ringBufferInit
does not make a sense. In the function testRingBufferPushPopSingle
you already created an object of the type RingBuffer
.
QUESTION
I have a class that is not default-constructable, copy-constructable or copy-assignable. It is move-constructable and move-assignable.
...ANSWER
Answered 2020-Nov-02 at 07:34Your problem lies in the absence of a move assignment operator. Looking at your class, you have defaulted this operation.
Unfortunately, = default
means that you get the default behavior, not that this method is created. This is really confusing.
To make this easier to spot I've recently enabled the following clang warning as error on the code base I'm working on: https://clang.llvm.org/docs/DiagnosticsReference.html#wdefaulted-function-deleted (Maybe GCC has something similar)
Long story short, if you have a base class or member that doesn't allow this operation, your class can't default this.
In this case, you have a reference as a member, as one can't reassign a reference, one can't provide the assignment operator.
Possible workarounds are: store as a raw pointer, or store as std:: reference_wrapper
.
PS: please make your deleted methods public and use = delete
, it will give much better error messages
QUESTION
I'm createing a generic ring buffer and I would like to use array list as internal storage for data and I'd like to allocate array list with defined capacity
.
This is an example using Kotlin ArrayList:
...ANSWER
Answered 2020-Aug-20 at 16:19It's possible to do it this way:
QUESTION
I am trying to input lowercase char and to add it to in.buffer, the other thread should read from in.buffer and make it lowercase and send to out.buffer, and the last one should read from out.buffer and print it.
I am getting error: expected identifier before numeric constant Semaphore m_free(10); error: invalid use of member function ‘Semaphore RingBuffer::m_free(int)’
Why is that?
Thanks
...ANSWER
Answered 2020-Aug-18 at 10:30You can't "call" anything inside a struct
. A struct
contains definitions of its members, not code.
You can initialize a member in a constructor:
QUESTION
I would like to have React Spring animate a property of a material in Three.js.
However, I'm getting an error when I try to do so:
...ANSWER
Answered 2020-Jul-15 at 19:34args is for constructor arguments. if you change an arg, the object will re-instanciate, as in: is the same as
new Foo(123)
. animating something that constructs 60fps is a no go, and it's also not possible with react-spring. in praxis you should find means to mutate things as fast as possible, if you can get away with it animate scale, or make a ring shader whose uniforms you animate.
QUESTION
The VecDeque
declaration:
ANSWER
Answered 2020-Jun-16 at 09:30Spelunking a bit finally led me to the PR in which huonw has the exact same reaction you did:
I find this mapping weird: it seems like tail should be head (as in, that element is the head of the ringbuf) and vice versa.
What's the motivation for having them this way around?
to which the PR author replies that it follows the linux kernel terminology. Which never explains why it's using the terms it does.
The PR also specifically notes that
lo
,nelts
[nb: the old names for these fields] are replaced by a more traditionalhead
andtail
So the answer seems to be "because it follows traditional nomenclature". Might be that one original paper used these terms and it stuck, or could be happenstance. The internets certainly don't seem interested in this question as while the terms show up aplenty explanations don't.
The linux circular buffers document was only added in 2010 so it would be documenting the existing state of affairs, and struct circ_buf
called it that when the Git repo was created back in 2005, so if you want more you'd have to dive into the historical archive and hope there are references there.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install RingBuffer
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page