6
#endif /* __cplusplus */
10
* Ring Buffer utility..
12
* Author: Phil Burk, http://www.softsynth.com
14
* This program is distributed with the PortAudio Portable Audio Library.
15
* For more information see: http://www.audiomulch.com/portaudio/
16
* Copyright (c) 1999-2000 Ross Bencina and Phil Burk
18
* Permission is hereby granted, free of charge, to any person obtaining
19
* a copy of this software and associated documentation files
20
* (the "Software"), to deal in the Software without restriction,
21
* including without limitation the rights to use, copy, modify, merge,
22
* publish, distribute, sublicense, and/or sell copies of the Software,
23
* and to permit persons to whom the Software is furnished to do so,
24
* subject to the following conditions:
26
* The above copyright notice and this permission notice shall be
27
* included in all copies or substantial portions of the Software.
29
* Any person wishing to distribute modifications to the Software is
30
* requested to send the modifications to the original developer so that
31
* they can be incorporated into the canonical version.
33
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
34
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
35
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
36
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
37
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
38
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
39
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
45
#include "s_audio_paring.h"
50
long bufferSize; /* Number of bytes in FIFO. Power of 2. Set by sys_ringbuf_Init. */
51
/* These are declared volatile because they are written by a different thread than the reader. */
52
volatile long writeIndex; /* Index of next writable byte. Set by sys_ringbuf_AdvanceWriteIndex. */
53
volatile long readIndex; /* Index of next readable byte. Set by sys_ringbuf_AdvanceReadIndex. */
54
long bigMask; /* Used for wrapping indices with extra bit to distinguish full/empty. */
55
long smallMask; /* Used for fitting indices to buffer. */
60
* Initialize Ring Buffer.
61
* numBytes must be power of 2, returns -1 if not.
63
long sys_ringbuf_Init( sys_ringbuf *rbuf, long numBytes, void *dataPtr );
65
/* Clear buffer. Should only be called when buffer is NOT being read. */
66
void sys_ringbuf_Flush( sys_ringbuf *rbuf );
68
/* Return number of bytes available for writing. */
69
long sys_ringbuf_GetWriteAvailable( sys_ringbuf *rbuf );
70
/* Return number of bytes available for read. */
71
long sys_ringbuf_GetReadAvailable( sys_ringbuf *rbuf );
72
/* Return bytes written. */
73
long sys_ringbuf_Write( sys_ringbuf *rbuf, const void *data, long numBytes );
74
/* Return bytes read. */
75
long sys_ringbuf_Read( sys_ringbuf *rbuf, void *data, long numBytes );
77
/* Get address of region(s) to which we can write data.
78
** If the region is contiguous, size2 will be zero.
79
** If non-contiguous, size2 will be the size of second region.
80
** Returns room available to be written or numBytes, whichever is smaller.
82
long sys_ringbuf_GetWriteRegions( sys_ringbuf *rbuf, long numBytes,
83
void **dataPtr1, long *sizePtr1,
84
void **dataPtr2, long *sizePtr2 );
85
long sys_ringbuf_AdvanceWriteIndex( sys_ringbuf *rbuf, long numBytes );
87
/* Get address of region(s) from which we can read data.
88
** If the region is contiguous, size2 will be zero.
89
** If non-contiguous, size2 will be the size of second region.
90
** Returns room available to be read or numBytes, whichever is smaller.
92
long sys_ringbuf_GetReadRegions( sys_ringbuf *rbuf, long numBytes,
93
void **dataPtr1, long *sizePtr1,
94
void **dataPtr2, long *sizePtr2 );
96
long sys_ringbuf_AdvanceReadIndex( sys_ringbuf *rbuf, long numBytes );
100
#endif /* __cplusplus */
101
#endif /* _RINGBUFFER_H */