![]() |
Mixxx
|
00001 #ifndef PA_RINGBUFFER_H 00002 #define PA_RINGBUFFER_H 00003 /* 00004 * $Id: pa_ringbuffer.h 1734 2011-08-18 11:19:36Z rossb $ 00005 * Portable Audio I/O Library 00006 * Ring Buffer utility. 00007 * 00008 * Author: Phil Burk, http://www.softsynth.com 00009 * modified for SMP safety on OS X by Bjorn Roche. 00010 * also allowed for const where possible. 00011 * modified for multiple-byte-sized data elements by Sven Fischer 00012 * 00013 * Note that this is safe only for a single-thread reader 00014 * and a single-thread writer. 00015 * 00016 * This program is distributed with the PortAudio Portable Audio Library. 00017 * For more information see: http://www.portaudio.com 00018 * Copyright (c) 1999-2000 Ross Bencina and Phil Burk 00019 * 00020 * Permission is hereby granted, free of charge, to any person obtaining 00021 * a copy of this software and associated documentation files 00022 * (the "Software"), to deal in the Software without restriction, 00023 * including without limitation the rights to use, copy, modify, merge, 00024 * publish, distribute, sublicense, and/or sell copies of the Software, 00025 * and to permit persons to whom the Software is furnished to do so, 00026 * subject to the following conditions: 00027 * 00028 * The above copyright notice and this permission notice shall be 00029 * included in all copies or substantial portions of the Software. 00030 * 00031 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00032 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00033 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00034 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 00035 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 00036 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00037 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00038 */ 00039 00040 /* 00041 * The text above constitutes the entire PortAudio license; however, 00042 * the PortAudio community also makes the following non-binding requests: 00043 * 00044 * Any person wishing to distribute modifications to the Software is 00045 * requested to send the modifications to the original developer so that 00046 * they can be incorporated into the canonical version. It is also 00047 * requested that these non-binding requests be included along with the 00048 * license above. 00049 */ 00050 00070 #if defined(__APPLE__) 00071 #include <sys/types.h> 00072 typedef int32_t ring_buffer_size_t; 00073 #elif defined( __GNUC__ ) 00074 typedef long ring_buffer_size_t; 00075 #elif (_MSC_VER >= 1400) 00076 typedef long ring_buffer_size_t; 00077 #elif defined(_MSC_VER) || defined(__BORLANDC__) 00078 typedef long ring_buffer_size_t; 00079 #else 00080 typedef long ring_buffer_size_t; 00081 #endif 00082 00083 00084 00085 #ifdef __cplusplus 00086 extern "C" 00087 { 00088 #endif /* __cplusplus */ 00089 00090 typedef struct PaUtilRingBuffer 00091 { 00092 ring_buffer_size_t bufferSize; 00093 volatile ring_buffer_size_t writeIndex; 00094 volatile ring_buffer_size_t readIndex; 00095 ring_buffer_size_t bigMask; 00096 ring_buffer_size_t smallMask; 00097 ring_buffer_size_t elementSizeBytes; 00098 char *buffer; 00099 }PaUtilRingBuffer; 00100 00114 ring_buffer_size_t PaUtil_InitializeRingBuffer( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementSizeBytes, ring_buffer_size_t elementCount, void *dataPtr ); 00115 00120 void PaUtil_FlushRingBuffer( PaUtilRingBuffer *rbuf ); 00121 00128 ring_buffer_size_t PaUtil_GetRingBufferWriteAvailable( const PaUtilRingBuffer *rbuf ); 00129 00136 ring_buffer_size_t PaUtil_GetRingBufferReadAvailable( const PaUtilRingBuffer *rbuf ); 00137 00148 ring_buffer_size_t PaUtil_WriteRingBuffer( PaUtilRingBuffer *rbuf, const void *data, ring_buffer_size_t elementCount ); 00149 00160 ring_buffer_size_t PaUtil_ReadRingBuffer( PaUtilRingBuffer *rbuf, void *data, ring_buffer_size_t elementCount ); 00161 00182 ring_buffer_size_t PaUtil_GetRingBufferWriteRegions( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount, 00183 void **dataPtr1, ring_buffer_size_t *sizePtr1, 00184 void **dataPtr2, ring_buffer_size_t *sizePtr2 ); 00185 00194 ring_buffer_size_t PaUtil_AdvanceRingBufferWriteIndex( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount ); 00195 00216 ring_buffer_size_t PaUtil_GetRingBufferReadRegions( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount, 00217 void **dataPtr1, ring_buffer_size_t *sizePtr1, 00218 void **dataPtr2, ring_buffer_size_t *sizePtr2 ); 00219 00228 ring_buffer_size_t PaUtil_AdvanceRingBufferReadIndex( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount ); 00229 00230 #ifdef __cplusplus 00231 } 00232 #endif /* __cplusplus */ 00233 #endif /* PA_RINGBUFFER_H */