User Tools

Site Tools


opus:fall2012:dgirard3:hpc1part2

Data Buffer

Definition

Data buffer is a place in physical memory that holds data temporarily while it is being moved from one place to another. So say you have music from one place you want to move to another, well when you make this transfer that sound will be held in a buffer during the process of moving. A buffer will be very useful in the project of creating my drum machine. When i get access to the sound drivers and transfer the sound over that i want, im going to need many buffers to hold all this data while it is being moved from input, to process, to output. here is some example code:

typedef struct {
    void             *buffer;
    int32_t           length;
    int32_t           tail;
    int32_t           head;
    volatile int32_t  fillCount;
} TPCircularBuffer;
 
bool  TPCircularBufferInit(TPCircularBuffer *buffer, int32_t length);
void  TPCircularBufferCleanup(TPCircularBuffer *buffer);
void  TPCircularBufferClear(TPCircularBuffer *buffer);
 
// Reading (consuming)
void* TPCircularBufferTail(TPCircularBuffer *buffer, int32_t* availableBytes);
void  TPCircularBufferConsume(TPCircularBuffer *buffer, int32_t amount);
 
// Writing (producing)
void* TPCircularBufferHead(TPCircularBuffer *buffer, int32_t* availableBytes);
void  TPCircularBufferProduce(TPCircularBuffer *buffer, int32_t amount);
int   TPCircularBufferProduceBytes(TPCircularBuffer *buffer, const void* src, int32_t len);

References

Data Buffer Phase 2

Definition

Data buffer is a place in physical memory that holds data temporarily while it is being moved from one place to another. So say you have music from one place you want to move to another, well when you make this transfer that sound will be held in a buffer during the process of moving. A buffer will be very useful in the project of creating my drum machine. When i get access to the sound drivers and transfer the sound over that i want, im going to need many buffers to hold all this data while it is being moved from input, to process, to output. here is some example code:

typedef struct {
    void             *buffer;
    int32_t           length;
    int32_t           tail;
    int32_t           head;
    volatile int32_t  fillCount;
} TPCircularBuffer;
 
bool  TPCircularBufferInit(TPCircularBuffer *buffer, int32_t length);
void  TPCircularBufferCleanup(TPCircularBuffer *buffer);
void  TPCircularBufferClear(TPCircularBuffer *buffer);
 
// Reading (consuming)
void* TPCircularBufferTail(TPCircularBuffer *buffer, int32_t* availableBytes);
void  TPCircularBufferConsume(TPCircularBuffer *buffer, int32_t amount);
 
// Writing (producing)
void* TPCircularBufferHead(TPCircularBuffer *buffer, int32_t* availableBytes);
void  TPCircularBufferProduce(TPCircularBuffer *buffer, int32_t amount);
int   TPCircularBufferProduceBytes(TPCircularBuffer *buffer, const void* src, int32_t len);

References

Demonstration

here is an example of a simple buffer:

typedef struct BufferBlockHeader_st BufferBlockHeader;
 
struct BufferBlockHeader_st {
   BufferBlockHeader * pNextBlock;
};
 
struct Buffer_st {
   long  int             totalLength;
   BufferBlockHeader *   pFirstBlock;
   short int             startPoint;
   BufferBlockHeader *   pLastBlock;
   short int             endPoint;
};
 
typedef struct Buffer_st Buffer;

Its only the buffer so this is not a full program or anything, its just showing how it would be created and used. Its being thrown in with a linked list while the buffer are holding data that will eventually be placed within the list itself. That is what a buffer will do!

opus/fall2012/dgirard3/hpc1part2.txt · Last modified: 2012/11/01 02:57 by dgirard3