6
#endif /* __cplusplus */
9
* $Id: ringbuffer.h,v 1.4 2006/09/23 18:42:46 llucius Exp $
11
* Ring Buffer utility..
13
* Author: Phil Burk, http://www.softsynth.com
15
* This program is distributed with the PortAudio Portable Audio Library.
16
* For more information see: http://www.portaudio.com
17
* Copyright (c) 1999-2000 Ross Bencina and Phil Burk
19
* Permission is hereby granted, free of charge, to any person obtaining
20
* a copy of this software and associated documentation files
21
* (the "Software"), to deal in the Software without restriction,
22
* including without limitation the rights to use, copy, modify, merge,
23
* publish, distribute, sublicense, and/or sell copies of the Software,
24
* and to permit persons to whom the Software is furnished to do so,
25
* subject to the following conditions:
27
* The above copyright notice and this permission notice shall be
28
* included in all copies or substantial portions of the Software.
30
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
33
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
34
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
35
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40
* The text above constitutes the entire PortAudio license; however,
41
* the PortAudio community also makes the following non-binding requests:
43
* Any person wishing to distribute modifications to the Software is
44
* requested to send the modifications to the original developer so that
45
* they can be incorporated into the canonical version. It is also
46
* requested that these non-binding requests be included along with the
53
#include "ringbuffer.h"
58
long bufferSize; /* Number of bytes in FIFO. Power of 2. Set by RingBuffer_Init. */
59
long writeIndex; /* Index of next writable byte. Set by RingBuffer_AdvanceWriteIndex. */
60
long readIndex; /* Index of next readable byte. Set by RingBuffer_AdvanceReadIndex. */
61
long bigMask; /* Used for wrapping indices with extra bit to distinguish full/empty. */
62
long smallMask; /* Used for fitting indices to buffer. */
67
* Initialize Ring Buffer.
68
* numBytes must be power of 2, returns -1 if not.
70
long RingBuffer_Init( RingBuffer *rbuf, long numBytes, void *dataPtr );
72
/* Clear buffer. Should only be called when buffer is NOT being read. */
73
void RingBuffer_Flush( RingBuffer *rbuf );
75
/* Return number of bytes available for writing. */
76
long RingBuffer_GetWriteAvailable( RingBuffer *rbuf );
77
/* Return number of bytes available for read. */
78
long RingBuffer_GetReadAvailable( RingBuffer *rbuf );
79
/* Return bytes written. */
80
long RingBuffer_Write( RingBuffer *rbuf, void *data, long numBytes );
81
/* Return bytes read. */
82
long RingBuffer_Read( RingBuffer *rbuf, void *data, long numBytes );
84
/* Get address of region(s) to which we can write data.
85
** If the region is contiguous, size2 will be zero.
86
** If non-contiguous, size2 will be the size of second region.
87
** Returns room available to be written or numBytes, whichever is smaller.
89
long RingBuffer_GetWriteRegions( RingBuffer *rbuf, long numBytes,
90
void **dataPtr1, long *sizePtr1,
91
void **dataPtr2, long *sizePtr2 );
92
long RingBuffer_AdvanceWriteIndex( RingBuffer *rbuf, long numBytes );
94
/* Get address of region(s) from which we can read data.
95
** If the region is contiguous, size2 will be zero.
96
** If non-contiguous, size2 will be the size of second region.
97
** Returns room available to be written or numBytes, whichever is smaller.
99
long RingBuffer_GetReadRegions( RingBuffer *rbuf, long numBytes,
100
void **dataPtr1, long *sizePtr1,
101
void **dataPtr2, long *sizePtr2 );
103
long RingBuffer_AdvanceReadIndex( RingBuffer *rbuf, long numBytes );
107
#endif /* __cplusplus */
108
#endif /* _RINGBUFFER_H */