forked from tkzic/audiograph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTPCircularBuffer.h
executable file
·52 lines (40 loc) · 1.9 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
48
49
50
// original source from Michael Tyson
//
// modified by adding additional functions to produce and consume without checking for buffer underflow
// for delay lines
// tz 11/2011
//
// TPCircularBuffer.h
// Circular buffer implementation
//
// Created by Michael Tyson on 19/03/2011.
// Copyright 2011 A Tasty Pixel. All rights reserved.
//
#include <libkern/OSAtomic.h>
typedef struct {
int32_t head;
int32_t tail;
volatile int32_t fillCount;
int32_t length;
} TPCircularBufferRecord;
void TPCircularBufferInit(TPCircularBufferRecord *record, int length);
void TPCircularBufferClear(TPCircularBufferRecord *record);
int TPCircularBufferFillCount(TPCircularBufferRecord *record);
int TPCircularBufferFillCountContiguous(TPCircularBufferRecord *record);
int TPCircularBufferSpace(TPCircularBufferRecord *record);
int TPCircularBufferSpaceContiguous(TPCircularBufferRecord *record);
// Reading (consuming)
int TPCircularBufferTail(TPCircularBufferRecord *record);
void TPCircularBufferConsume(TPCircularBufferRecord *record, int amount);
void TPCircularBufferConsumeSingleThread(TPCircularBufferRecord *record, int amount);
// Writing (producing)
int TPCircularBufferHead(TPCircularBufferRecord *record);
void TPCircularBufferProduce(TPCircularBufferRecord *record, int amount);
void TPCircularBufferProduceSingleThread(TPCircularBufferRecord *record, int amount);
int TPCircularBufferProduceBytes(TPCircularBufferRecord *record, void* dst, const void* src, int count, int len);
// tz for resetting tail
void TPCircularBufferSetTail(TPCircularBufferRecord *record, int32_t position, int32_t count);
int TPCircularBufferLength(TPCircularBufferRecord *record );
void TPCircularBufferProduceAnywhere(TPCircularBufferRecord *record, int amount);
void TPCircularBufferConsumeAnywhere(TPCircularBufferRecord *record, int amount);
void TPCircularBufferSetTailAnywhere(TPCircularBufferRecord *record, int32_t position );