PortAudio  2.0
pa_ringbuffer.h
Go to the documentation of this file.
1 #ifndef PA_RINGBUFFER_H
2 #define PA_RINGBUFFER_H
3 /*
4  * $Id$
5  * Portable Audio I/O Library
6  * Ring Buffer utility.
7  *
8  * Author: Phil Burk, http://www.softsynth.com
9  * modified for SMP safety on OS X by Bjorn Roche.
10  * also allowed for const where possible.
11  * modified for multiple-byte-sized data elements by Sven Fischer
12  *
13  * Note that this is safe only for a single-thread reader
14  * and a single-thread writer.
15  *
16  * This program is distributed with the PortAudio Portable Audio Library.
17  * For more information see: http://www.portaudio.com
18  * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
19  *
20  * Permission is hereby granted, free of charge, to any person obtaining
21  * a copy of this software and associated documentation files
22  * (the "Software"), to deal in the Software without restriction,
23  * including without limitation the rights to use, copy, modify, merge,
24  * publish, distribute, sublicense, and/or sell copies of the Software,
25  * and to permit persons to whom the Software is furnished to do so,
26  * subject to the following conditions:
27  *
28  * The above copyright notice and this permission notice shall be
29  * included in all copies or substantial portions of the Software.
30  *
31  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
34  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
35  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
36  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38  */
39 
40 /*
41  * The text above constitutes the entire PortAudio license; however,
42  * the PortAudio community also makes the following non-binding requests:
43  *
44  * Any person wishing to distribute modifications to the Software is
45  * requested to send the modifications to the original developer so that
46  * they can be incorporated into the canonical version. It is also
47  * requested that these non-binding requests be included along with the
48  * license above.
49  */
50 
73 #if defined(__APPLE__)
74 #include <sys/types.h>
75 typedef int32_t ring_buffer_size_t;
76 #elif defined( __GNUC__ )
77 typedef long ring_buffer_size_t;
78 #elif (_MSC_VER >= 1400)
79 typedef long ring_buffer_size_t;
80 #elif defined(_MSC_VER) || defined(__BORLANDC__)
81 typedef long ring_buffer_size_t;
82 #else
83 typedef long ring_buffer_size_t;
84 #endif
85 
86 
87 
88 #ifdef __cplusplus
89 extern "C"
90 {
91 #endif /* __cplusplus */
92 
93 typedef struct PaUtilRingBuffer
94 {
101  char *buffer;
103 
117 ring_buffer_size_t PaUtil_InitializeRingBuffer( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementSizeBytes, ring_buffer_size_t elementCount, void *dataPtr );
118 
124 
132 
140 
151 ring_buffer_size_t PaUtil_WriteRingBuffer( PaUtilRingBuffer *rbuf, const void *data, ring_buffer_size_t elementCount );
152 
164 
186  void **dataPtr1, ring_buffer_size_t *sizePtr1,
187  void **dataPtr2, ring_buffer_size_t *sizePtr2 );
188 
198 
220  void **dataPtr1, ring_buffer_size_t *sizePtr1,
221  void **dataPtr2, ring_buffer_size_t *sizePtr2 );
222 
232 
233 #ifdef __cplusplus
234 }
235 #endif /* __cplusplus */
236 #endif /* PA_RINGBUFFER_H */
Definition: pa_ringbuffer.h:93
ring_buffer_size_t smallMask
Definition: pa_ringbuffer.h:99
ring_buffer_size_t PaUtil_WriteRingBuffer(PaUtilRingBuffer *rbuf, const void *data, ring_buffer_size_t elementCount)
Definition: pa_ringbuffer.c:198
ring_buffer_size_t PaUtil_GetRingBufferReadRegions(PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount, void **dataPtr1, ring_buffer_size_t *sizePtr1, void **dataPtr2, ring_buffer_size_t *sizePtr2)
Definition: pa_ringbuffer.c:154
ring_buffer_size_t elementSizeBytes
Definition: pa_ringbuffer.h:100
ring_buffer_size_t PaUtil_InitializeRingBuffer(PaUtilRingBuffer *rbuf, ring_buffer_size_t elementSizeBytes, ring_buffer_size_t elementCount, void *dataPtr)
Definition: pa_ringbuffer.c:66
ring_buffer_size_t PaUtil_ReadRingBuffer(PaUtilRingBuffer *rbuf, void *data, ring_buffer_size_t elementCount)
Definition: pa_ringbuffer.c:220
ring_buffer_size_t PaUtil_GetRingBufferReadAvailable(const PaUtilRingBuffer *rbuf)
Definition: pa_ringbuffer.c:80
ring_buffer_size_t bigMask
Definition: pa_ringbuffer.h:98
long ring_buffer_size_t
Definition: pa_ringbuffer.h:83
ring_buffer_size_t bufferSize
Definition: pa_ringbuffer.h:95
volatile ring_buffer_size_t writeIndex
Definition: pa_ringbuffer.h:96
struct PaUtilRingBuffer PaUtilRingBuffer
volatile ring_buffer_size_t readIndex
Definition: pa_ringbuffer.h:97
void PaUtil_FlushRingBuffer(PaUtilRingBuffer *rbuf)
Definition: pa_ringbuffer.c:93
ring_buffer_size_t PaUtil_GetRingBufferWriteAvailable(const PaUtilRingBuffer *rbuf)
Definition: pa_ringbuffer.c:86
char * buffer
Definition: pa_ringbuffer.h:101
ring_buffer_size_t PaUtil_AdvanceRingBufferWriteIndex(PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount)
Definition: pa_ringbuffer.c:139
ring_buffer_size_t PaUtil_AdvanceRingBufferReadIndex(PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount)
Definition: pa_ringbuffer.c:187
ring_buffer_size_t PaUtil_GetRingBufferWriteRegions(PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount, void **dataPtr1, ring_buffer_size_t *sizePtr1, void **dataPtr2, ring_buffer_size_t *sizePtr2)
Definition: pa_ringbuffer.c:104