Xeno-rat
Loading...
Searching...
No Matches
NAudio.Utils.CircularBuffer Class Reference

A very basic circular buffer implementation. More...

Collaboration diagram for NAudio.Utils.CircularBuffer:

Public Member Functions

 CircularBuffer (int size)
 Create a new circular buffer.
 
int Write (byte[] data, int offset, int count)
 Writes the specified number of bytes from the input data array to the internal buffer, starting at the specified offset .
 
int Read (byte[] data, int offset, int count)
 Reads data from the buffer into the specified byte array.
 
void Reset ()
 Resets the state of the object.
 
void Advance (int count)
 Advances the read position in the buffer by the specified count.
 

Properties

int MaxLength [get]
 Maximum length of this circular buffer.
 
int Count [get]
 Number of bytes currently stored in the circular buffer.
 

Private Member Functions

void ResetInner ()
 Resets the internal state of the object.
 

Private Attributes

readonly byte[] buffer
 
readonly object lockObject
 
int writePosition
 
int readPosition
 
int byteCount
 

Detailed Description

A very basic circular buffer implementation.

Constructor & Destructor Documentation

◆ CircularBuffer()

NAudio.Utils.CircularBuffer.CircularBuffer ( int size)
inline

Create a new circular buffer.

Parameters
sizeMax buffer size in bytes

Member Function Documentation

◆ Advance()

void NAudio.Utils.CircularBuffer.Advance ( int count)
inline

Advances the read position in the buffer by the specified count.

Parameters
countThe number of positions to advance the read position by.
Exceptions
System.ArgumentOutOfRangeExceptionThrown when the count is negative.

This method advances the read position in the buffer by the specified count. If the count is greater than or equal to the total byte count, it resets the buffer. Otherwise, it decrements the byte count by the specified count, advances the read position, and ensures that the read position wraps around if it exceeds the maximum length.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Read()

int NAudio.Utils.CircularBuffer.Read ( byte[] data,
int offset,
int count )
inline

Reads data from the buffer into the specified byte array.

Parameters
dataThe byte array to which the data will be read.
offsetThe zero-based byte offset in data at which to begin storing the data.
countThe maximum number of bytes to read.
Returns
The total number of bytes read into the buffer.

This method reads data from the internal buffer into the specified byte array. If the specified count is greater than the available bytes in the buffer, it only reads the available bytes. The method handles wrapping around the buffer if necessary and updates the internal state accordingly.

Here is the caller graph for this function:

◆ Reset()

void NAudio.Utils.CircularBuffer.Reset ( )
inline

Resets the state of the object.

This method locks the lockObject and then calls the ResetInner method to reset the state of the object.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ResetInner()

void NAudio.Utils.CircularBuffer.ResetInner ( )
inlineprivate

Resets the internal state of the object.

This method resets the byte count, read position, and write position to their initial values, effectively clearing the internal state of the object.

Here is the caller graph for this function:

◆ Write()

int NAudio.Utils.CircularBuffer.Write ( byte[] data,
int offset,
int count )
inline

Writes the specified number of bytes from the input data array to the internal buffer, starting at the specified offset .

Parameters
dataThe input byte array from which data will be written to the internal buffer.
offsetThe zero-based byte offset in the data array at which to begin copying bytes to the internal buffer.
countThe number of bytes to write to the internal buffer.
Returns
The actual number of bytes written to the internal buffer, which may be less than the specified count if the internal buffer does not have enough space.

This method locks the lockObject to ensure thread safety while writing to the internal buffer. If the specified count is greater than the available space in the internal buffer, only the available space is written. The method first writes to the end of the buffer, and if necessary, wraps around and writes to the start of the buffer to complete the write operation. The total number of bytes written is returned, and the internal byte count is updated accordingly.

Here is the caller graph for this function:

Member Data Documentation

◆ buffer

readonly byte [] NAudio.Utils.CircularBuffer.buffer
private

◆ byteCount

int NAudio.Utils.CircularBuffer.byteCount
private

◆ lockObject

readonly object NAudio.Utils.CircularBuffer.lockObject
private

◆ readPosition

int NAudio.Utils.CircularBuffer.readPosition
private

◆ writePosition

int NAudio.Utils.CircularBuffer.writePosition
private

Property Documentation

◆ Count

int NAudio.Utils.CircularBuffer.Count
get

Number of bytes currently stored in the circular buffer.

◆ MaxLength

int NAudio.Utils.CircularBuffer.MaxLength
get

Maximum length of this circular buffer.


The documentation for this class was generated from the following file: