forked from leejunkit/MiniMusicalStar-CustomAudioLibraries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTPCircularBuffer.h
executable file
·47 lines (35 loc) · 1.7 KB
/
TPCircularBuffer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//
// TPCircularBuffer.h
// Circular buffer implementation
//
// Created by Michael Tyson on 19/03/2011.
// Copyright 2011 A Tasty Pixel. All rights reserved.
//
typedef struct {
int head;
int tail;
int fillCount;
int length;
} TPCircularBufferRecord;
// Initialise record structure
void TPCircularBufferInit(TPCircularBufferRecord *record, int length);
// Obtain fill count
int TPCircularBufferFillCount(TPCircularBufferRecord *record);
// Obtain fill count for a contiguous area
int TPCircularBufferFillCountContiguous(TPCircularBufferRecord *record);
// Obtain count of available space
int TPCircularBufferSpace(TPCircularBufferRecord *record);
// Obtain count of available space for contiguous area
int TPCircularBufferSpaceContiguous(TPCircularBufferRecord *record);
// Index of the head counter into the corresponding buffer
int TPCircularBufferHead(TPCircularBufferRecord *record);
// Index of the tail counter into the corresponding buffer
int TPCircularBufferTail(TPCircularBufferRecord *record);
// Produce data (by increasing the fill count and moving the head counter forwards)
void TPCircularBufferProduce(TPCircularBufferRecord *record, int amount);
// Consume data (by decreasing the fill count and moving the tail counter forwards)
void TPCircularBufferConsume(TPCircularBufferRecord *record, int amount);
// Clear the whole buffer, resetting fill count to zero and pointing the tail counter to the head
void TPCircularBufferClear(TPCircularBufferRecord *record);
// Produce by copying the data ('count' units of 'len' length) in the buffer at 'src' into the circular buffer 'dst'
int TPCircularBufferCopy(TPCircularBufferRecord *record, void* dst, const void* src, int count, int len);