00001 #ifndef PA_RINGBUFFER_H 00002 #define PA_RINGBUFFER_H 00003 /* 00004 * $Id: pa_ringbuffer.h 1151 2006-11-29 02:11:16Z leland_lucius $ 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 * Note that this is safe only for a single-thread reader 00012 * and a single-thread writer. 00013 * 00014 * This program is distributed with the PortAudio Portable Audio Library. 00015 * For more information see: http://www.portaudio.com 00016 * Copyright (c) 1999-2000 Ross Bencina and Phil Burk 00017 * 00018 * Permission is hereby granted, free of charge, to any person obtaining 00019 * a copy of this software and associated documentation files 00020 * (the "Software"), to deal in the Software without restriction, 00021 * including without limitation the rights to use, copy, modify, merge, 00022 * publish, distribute, sublicense, and/or sell copies of the Software, 00023 * and to permit persons to whom the Software is furnished to do so, 00024 * subject to the following conditions: 00025 * 00026 * The above copyright notice and this permission notice shall be 00027 * included in all copies or substantial portions of the Software. 00028 * 00029 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00030 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00031 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00032 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 00033 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 00034 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00035 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00036 */ 00037 00038 /* 00039 * The text above constitutes the entire PortAudio license; however, 00040 * the PortAudio community also makes the following non-binding requests: 00041 * 00042 * Any person wishing to distribute modifications to the Software is 00043 * requested to send the modifications to the original developer so that 00044 * they can be incorporated into the canonical version. It is also 00045 * requested that these non-binding requests be included along with the 00046 * license above. 00047 */ 00048 00053 #ifdef __cplusplus 00054 extern "C" 00055 { 00056 #endif /* __cplusplus */ 00057 00058 typedef struct PaUtilRingBuffer 00059 { 00060 long bufferSize; /* Number of bytes in FIFO. Power of 2. Set by PaUtil_InitRingBuffer. */ 00061 long writeIndex; /* Index of next writable byte. Set by PaUtil_AdvanceRingBufferWriteIndex. */ 00062 long readIndex; /* Index of next readable byte. Set by PaUtil_AdvanceRingBufferReadIndex. */ 00063 long bigMask; /* Used for wrapping indices with extra bit to distinguish full/empty. */ 00064 long smallMask; /* Used for fitting indices to buffer. */ 00065 char *buffer; 00066 }PaUtilRingBuffer; 00067 00079 long PaUtil_InitializeRingBuffer( PaUtilRingBuffer *rbuf, long numBytes, void *dataPtr ); 00080 00085 void PaUtil_FlushRingBuffer( PaUtilRingBuffer *rbuf ); 00086 00093 long PaUtil_GetRingBufferWriteAvailable( PaUtilRingBuffer *rbuf ); 00094 00101 long PaUtil_GetRingBufferReadAvailable( PaUtilRingBuffer *rbuf ); 00102 00113 long PaUtil_WriteRingBuffer( PaUtilRingBuffer *rbuf, const void *data, long numBytes ); 00114 00125 long PaUtil_ReadRingBuffer( PaUtilRingBuffer *rbuf, void *data, long numBytes ); 00126 00147 long PaUtil_GetRingBufferWriteRegions( PaUtilRingBuffer *rbuf, long numBytes, 00148 void **dataPtr1, long *sizePtr1, 00149 void **dataPtr2, long *sizePtr2 ); 00150 00159 long PaUtil_AdvanceRingBufferWriteIndex( PaUtilRingBuffer *rbuf, long numBytes ); 00160 00181 long PaUtil_GetRingBufferReadRegions( PaUtilRingBuffer *rbuf, long numBytes, 00182 void **dataPtr1, long *sizePtr1, 00183 void **dataPtr2, long *sizePtr2 ); 00184 00193 long PaUtil_AdvanceRingBufferReadIndex( PaUtilRingBuffer *rbuf, long numBytes ); 00194 00195 #ifdef __cplusplus 00196 } 00197 #endif /* __cplusplus */ 00198 #endif /* PA_RINGBUFFER_H */