Changeset 1346 for portaudio/branches/v19-devel/src/common/pa_ringbuffer.h
- Timestamp:
- 02/20/08 05:09:20 (10 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
portaudio/branches/v19-devel/src/common/pa_ringbuffer.h
r1151 r1346 9 9 * modified for SMP safety on OS X by Bjorn Roche. 10 10 * also allowed for const where possible. 11 * modified for multiple-byte-sized data elements by Sven Fischer 12 * 11 13 * Note that this is safe only for a single-thread reader 12 14 * and a single-thread writer. … … 58 60 typedef struct PaUtilRingBuffer 59 61 { 60 long bufferSize; /* Number of bytes in FIFO. Power of 2. Set by PaUtil_InitRingBuffer. */ 61 long writeIndex; /* Index of next writable byte. Set by PaUtil_AdvanceRingBufferWriteIndex. */ 62 long readIndex; /* Index of next readable byte. Set by PaUtil_AdvanceRingBufferReadIndex. */ 63 long bigMask; /* Used for wrapping indices with extra bit to distinguish full/empty. */ 64 long smallMask; /* Used for fitting indices to buffer. */ 62 long bufferSize; /* Number of elements in FIFO. Power of 2. Set by PaUtil_InitRingBuffer. */ 63 long writeIndex; /* Index of next writable element. Set by PaUtil_AdvanceRingBufferWriteIndex. */ 64 long readIndex; /* Index of next readable element. Set by PaUtil_AdvanceRingBufferReadIndex. */ 65 long bigMask; /* Used for wrapping indices with extra bit to distinguish full/empty. */ 66 long smallMask; /* Used for fitting indices to buffer. */ 67 long elementSizeBytes; /* Number of bytes per element. */ 65 68 char *buffer; 66 69 }PaUtilRingBuffer; … … 70 73 @param rbuf The ring buffer. 71 74 72 @param numBytes The number of bytes in the buffer and must be power of 2.75 @param elementCount The number of elements in the buffer and must be power of 2. 73 76 74 77 @param dataPtr A pointer to a previously allocated area where the data 75 will be maintained. It must be numBytes long.76 77 @return -1 if numBytesis not a power of 2, otherwise 0.78 */ 79 long PaUtil_InitializeRingBuffer( PaUtilRingBuffer *rbuf, long numBytes, void *dataPtr );78 will be maintained. It must be elementCount*elementSizeBytes long. 79 80 @return -1 if elementCount is not a power of 2, otherwise 0. 81 */ 82 long PaUtil_InitializeRingBuffer( PaUtilRingBuffer *rbuf, long elementSizeBytes, long elementCount, void *dataPtr ); 80 83 81 84 /** Clear buffer. Should only be called when buffer is NOT being read. … … 85 88 void PaUtil_FlushRingBuffer( PaUtilRingBuffer *rbuf ); 86 89 87 /** Retrieve the number of bytes available in the ring buffer for writing.88 89 @param rbuf The ring buffer. 90 91 @return The number of bytes available for writing.90 /** Retrieve the number of elements available in the ring buffer for writing. 91 92 @param rbuf The ring buffer. 93 94 @return The number of elements available for writing. 92 95 */ 93 96 long PaUtil_GetRingBufferWriteAvailable( PaUtilRingBuffer *rbuf ); 94 97 95 /** Retrieve the number of bytes available in the ring buffer for reading.96 97 @param rbuf The ring buffer. 98 99 @return The number of bytes available for reading.98 /** Retrieve the number of elements available in the ring buffer for reading. 99 100 @param rbuf The ring buffer. 101 102 @return The number of elements available for reading. 100 103 */ 101 104 long PaUtil_GetRingBufferReadAvailable( PaUtilRingBuffer *rbuf ); … … 107 110 @param data The address of new data to write to the buffer. 108 111 109 @param numBytes The number of bytes to be written.110 111 @return The number of bytes written.112 */ 113 long PaUtil_WriteRingBuffer( PaUtilRingBuffer *rbuf, const void *data, long numBytes);112 @param elementCount The number of elements to be written. 113 114 @return The number of elements written. 115 */ 116 long PaUtil_WriteRingBuffer( PaUtilRingBuffer *rbuf, const void *data, long elementCount ); 114 117 115 118 /** Read data from the ring buffer. … … 119 122 @param data The address where the data should be stored. 120 123 121 @param numBytes The number of bytes to be read.122 123 @return The number of bytes read.124 */ 125 long PaUtil_ReadRingBuffer( PaUtilRingBuffer *rbuf, void *data, long numBytes);124 @param elementCount The number of elements to be read. 125 126 @return The number of elements read. 127 */ 128 long PaUtil_ReadRingBuffer( PaUtilRingBuffer *rbuf, void *data, long elementCount ); 126 129 127 130 /** Get address of region(s) to which we can write data. … … 129 132 @param rbuf The ring buffer. 130 133 131 @param numBytes The number of bytes desired.134 @param elementCount The number of elements desired. 132 135 133 136 @param dataPtr1 The address where the first (or only) region pointer will be … … 138 141 139 142 @param dataPtr2 The address where the second region pointer will be stored if 140 the first region is too small to satisfy numBytes.143 the first region is too small to satisfy elementCount. 141 144 142 145 @param sizePtr2 The address where the second region length will be stored if 143 the first region is too small to satisfy numBytes.144 145 @return The room available to be written or numBytes, whichever is smaller.146 */ 147 long PaUtil_GetRingBufferWriteRegions( PaUtilRingBuffer *rbuf, long numBytes,146 the first region is too small to satisfy elementCount. 147 148 @return The room available to be written or elementCount, whichever is smaller. 149 */ 150 long PaUtil_GetRingBufferWriteRegions( PaUtilRingBuffer *rbuf, long elementCount, 148 151 void **dataPtr1, long *sizePtr1, 149 152 void **dataPtr2, long *sizePtr2 ); … … 153 156 @param rbuf The ring buffer. 154 157 155 @param numBytes The number of bytes to advance.158 @param elementCount The number of elements to advance. 156 159 157 160 @return The new position. 158 161 */ 159 long PaUtil_AdvanceRingBufferWriteIndex( PaUtilRingBuffer *rbuf, long numBytes);162 long PaUtil_AdvanceRingBufferWriteIndex( PaUtilRingBuffer *rbuf, long elementCount ); 160 163 161 164 /** Get address of region(s) from which we can write data. … … 163 166 @param rbuf The ring buffer. 164 167 165 @param numBytes The number of bytes desired.168 @param elementCount The number of elements desired. 166 169 167 170 @param dataPtr1 The address where the first (or only) region pointer will be … … 172 175 173 176 @param dataPtr2 The address where the second region pointer will be stored if 174 the first region is too small to satisfy numBytes.177 the first region is too small to satisfy elementCount. 175 178 176 179 @param sizePtr2 The address where the second region length will be stored if 177 the first region is too small to satisfy numBytes.178 179 @return The number of bytes available for reading.180 */ 181 long PaUtil_GetRingBufferReadRegions( PaUtilRingBuffer *rbuf, long numBytes,180 the first region is too small to satisfy elementCount. 181 182 @return The number of elements available for reading. 183 */ 184 long PaUtil_GetRingBufferReadRegions( PaUtilRingBuffer *rbuf, long elementCount, 182 185 void **dataPtr1, long *sizePtr1, 183 186 void **dataPtr2, long *sizePtr2 ); … … 187 190 @param rbuf The ring buffer. 188 191 189 @param numBytes The number of bytes to advance.192 @param elementCount The number of elements to advance. 190 193 191 194 @return The new position. 192 195 */ 193 long PaUtil_AdvanceRingBufferReadIndex( PaUtilRingBuffer *rbuf, long numBytes);196 long PaUtil_AdvanceRingBufferReadIndex( PaUtilRingBuffer *rbuf, long elementCount ); 194 197 195 198 #ifdef __cplusplus
