wavelength 1.0.0
Loading...
Searching...
No Matches
StreamBuffer Class Referenceabstract

The ring buffer the EE streams samples into. More...

#include <streambuffer.h>

Inheritance diagram for StreamBuffer:
Collaboration diagram for StreamBuffer:

Public Member Functions

 StreamBuffer (unsigned int size)
 Allocate the buffer.
 ~StreamBuffer () override
 Free the buffer.
void SetStatusAddress (void *address)
 Record the EE address that receives the free space, and write 1 there.
void Write (const void *data, unsigned int size, bool endOfStream) override
 Append bytes and schedule a notification.
void Notify () override
 Send the free space to the EE when a notification is scheduled and the space is positive.
 StreamBuffer (int nSize)
 Allocate a cleared buffer.
virtual ~StreamBuffer ()
 Free the buffer.
virtual void Add (const char *pData, int nBytes, int bLast)
 Append bytes behind the write head, wrapping at the end of the buffer.
virtual void Poll ()=0
 Let the producer append what it has.
virtual void Rewind ()
 Move both heads back to the start of the buffer.
bool IsEof ()
 Report whether the consumer took every byte and the producer has no more.
bool IsEmpty ()
 Report whether the consumer has taken every byte appended so far.
char * AcquireReadRun (int nMaxBytes, int *pnBytes)
 Take the next run of bytes, after a Poll().
void CommitReadRun (char **ppRun)
 Release the run AcquireReadRun() handed out, Poll(), and clear the caller's pointer.
int EmptySpaceForFilling ()
 Report the room the producer may fill, which keeps mMargin bytes free.
int BytesAvailable (int *pbInputDone)
 Report the bytes the consumer has not taken yet.
int GetSize () const
char * GetBuffer () const
Public Member Functions inherited from RingBuffer
 RingBuffer (unsigned int size)
 Allocate and clear a buffer of size bytes, rounded down to whole words, with both pointers at its start.
virtual ~RingBuffer ()
 Free the buffer.
virtual void Reset ()
 Discard every byte by moving both pointers to the start of the buffer.
bool IsFinished () const
 Report whether the stream has ended and every byte has been read.
unsigned int ContiguousFree () const
 Report the space the writer can fill without wrapping, less the reserve.
bool IsFull () const
 Report whether ContiguousFree() is zero.
bool IsEmpty () const
 Report whether every written byte has been read.
void * Read (unsigned int maxSize, unsigned int *size)
 Notify the writer, then return the next contiguous block of at most maxSize bytes.
void Release (void **block)
 Consume the block Read() returned and notify the writer.
unsigned int FreeSpace () const
 Report the free space, less the reserve.
unsigned int Used (bool *endOfStream) const
 Report the bytes written and not yet read.
void ClearEndOfStream ()
 Clear the end-of-stream flag.
bool EndOfStream () const
 Report the end-of-stream flag.

Static Public Member Functions

static int SendStatus (int value, void *address)
 Write a word to EE memory over SIF DMA.

Static Public Attributes

static constexpr unsigned int kSize = 0xf000
 Buffer size in bytes.

Protected Attributes

int mInputDone
Protected Attributes inherited from RingBuffer
unsigned int mSize
char * mBuffer
char * mRead
char * mWrite
char * mEnd
char * mPendingRead
bool mEndOfStream
unsigned int mReserve

Detailed Description

The ring buffer the EE streams samples into.

Ring buffer of bytes a producer appends and a consumer takes in runs.

After each change it tells the EE how much it may send by writing the free space to an EE address over SIF DMA.

The module was built without RTTI. The name is inferred from the class's routines.

The RTTI includes the class name and records no base. The data members precede the vptr, which sits at +0x20. Every routine reports the state through DebugPrint() whenever the write head has passed the end of the buffer.

Constructor & Destructor Documentation

◆ StreamBuffer() [1/2]

StreamBuffer::StreamBuffer ( unsigned int size)
explicit

Allocate the buffer.

Parameters
sizeRequested size. The binary ignores it and always allocates kSize bytes.
Ghidra address:
NTSC-U/C: 0x00003270
Ghidra address:
PAL: 0x00003270

◆ ~StreamBuffer() [1/2]

StreamBuffer::~StreamBuffer ( )
override

Free the buffer.

Ghidra address:
NTSC-U/C: 0x000033e8
Ghidra address:
PAL: 0x000033e8

◆ StreamBuffer() [2/2]

StreamBuffer::StreamBuffer ( int nSize)
explicit

Allocate a cleared buffer.

Parameters
nSizeThe size of the buffer in bytes.
Ghidra address:
NTSC-U/C: 0x0029f940
Ghidra address:
PAL: 0x002a95f8

◆ ~StreamBuffer() [2/2]

virtual StreamBuffer::~StreamBuffer ( )
virtual

Free the buffer.

Ghidra address:
NTSC-U/C: 0x0029f9c8
Ghidra address:
PAL: 0x002a9680

Member Function Documentation

◆ SendStatus()

int StreamBuffer::SendStatus ( int value,
void * address )
static

Write a word to EE memory over SIF DMA.

Parameters
valueThe word.
addressEE address of a 16-byte destination.
Returns
The transfer identifier.
Ghidra address:
NTSC-U/C: 0x000032b0
Ghidra address:
PAL: 0x000032b0

◆ SetStatusAddress()

void StreamBuffer::SetStatusAddress ( void * address)

Record the EE address that receives the free space, and write 1 there.

Parameters
addressEE address.
Ghidra address:
NTSC-U/C: 0x00003344
Ghidra address:
PAL: 0x00003344

◆ Write()

void StreamBuffer::Write ( const void * data,
unsigned int size,
bool endOfStream )
overridevirtual

Append bytes and schedule a notification.

Parameters
dataBytes to append, or null to record only the flag.
sizeByte count, or zero to record only the flag.
endOfStreamWhether the EE has no more data.
Ghidra address:
NTSC-U/C: 0x00003368
Ghidra address:
PAL: 0x00003368

Reimplemented from RingBuffer.

◆ Notify()

void StreamBuffer::Notify ( )
overridevirtual

Send the free space to the EE when a notification is scheduled and the space is positive.

Ghidra address:
NTSC-U/C: 0x00003394
Ghidra address:
PAL: 0x00003394

Implements RingBuffer.

◆ Add()

virtual void StreamBuffer::Add ( const char * pData,
int nBytes,
int bLast )
virtual

Append bytes behind the write head, wrapping at the end of the buffer.

The caller first checks EmptySpaceForFilling(). The global g_nAddWasEntered is set while the routine runs, and it stays set when there is no byte to append.

Parameters
pDataThe bytes, or null to only record bLast.
nBytesThe number of bytes.
bLastNon-zero when the producer has no more bytes.
Ghidra address:
NTSC-U/C: 0x0029fe68
Ghidra address:
PAL: 0x002a9b20

◆ Poll()

virtual void StreamBuffer::Poll ( )
pure virtual

Let the producer append what it has.

The member is pure in this class.

Implemented in FileStreamBuffer.

◆ Rewind()

virtual void StreamBuffer::Rewind ( )
virtual

Move both heads back to the start of the buffer.

Ghidra address:
NTSC-U/C: 0x002a0120
Ghidra address:
PAL: 0x002a9dd8

Reimplemented in FileStreamBuffer.

◆ IsEof()

bool StreamBuffer::IsEof ( )

Report whether the consumer took every byte and the producer has no more.

A write head past the end of the buffer also counts as the end.

Returns
Whether the stream ended.
Ghidra address:
NTSC-U/C: 0x0029fa28
Ghidra address:
PAL: 0x002a96e0

◆ IsEmpty()

bool StreamBuffer::IsEmpty ( )

Report whether the consumer has taken every byte appended so far.

The name is inferred.

Returns
Whether the read head is at the write head.
Ghidra address:
NTSC-U/C: 0x0029fa88
Ghidra address:
PAL: 0x002a9740

◆ AcquireReadRun()

char * StreamBuffer::AcquireReadRun ( int nMaxBytes,
int * pnBytes )

Take the next run of bytes, after a Poll().

A run ends at the write head or at the end of the buffer.

Parameters
nMaxBytesThe most bytes the caller accepts.
pnBytesReceives the size of the run.
Returns
The run, or null when no byte is ready.
Ghidra address:
NTSC-U/C: 0x0029fae8
Ghidra address:
PAL: 0x002a97a0

◆ CommitReadRun()

void StreamBuffer::CommitReadRun ( char ** ppRun)

Release the run AcquireReadRun() handed out, Poll(), and clear the caller's pointer.

A null run is ignored.

Parameters
ppRunThe caller's pointer to the run.
Ghidra address:
NTSC-U/C: 0x0029fd18
Ghidra address:
PAL: 0x002a99d0

◆ EmptySpaceForFilling()

int StreamBuffer::EmptySpaceForFilling ( )

Report the room the producer may fill, which keeps mMargin bytes free.

Returns
The room in bytes.
Ghidra address:
NTSC-U/C: 0x002a0070
Ghidra address:
PAL: 0x002a9d28

◆ BytesAvailable()

int StreamBuffer::BytesAvailable ( int * pbInputDone)

Report the bytes the consumer has not taken yet.

The name is inferred.

Parameters
pbInputDoneReceives mInputDone.
Returns
The number of bytes.
Ghidra address:
NTSC-U/C: 0x002a00a8
Ghidra address:
PAL: 0x002a9d60

◆ GetSize()

int StreamBuffer::GetSize ( ) const
inline
Returns
The size of the buffer in bytes.

◆ GetBuffer()

char * StreamBuffer::GetBuffer ( ) const
inline
Returns
The buffer.

Member Data Documentation

◆ kSize

unsigned int StreamBuffer::kSize = 0xf000
staticconstexpr

Buffer size in bytes.

◆ mInputDone

int StreamBuffer::mInputDone
protected

1 once the producer has no more bytes.


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