~ubuntu-branches/ubuntu/gutsy/audacity/gutsy-backports

« back to all changes in this revision

Viewing changes to lib-src/portaudio-v19/pablio/ringbuffer.h

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2008-02-18 21:58:19 UTC
  • mfrom: (13.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080218215819-tmbcf1rx238r8gdv
Tags: 1.3.4-1.1ubuntu1~gutsy1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef _RINGBUFFER_H
2
 
#define _RINGBUFFER_H
3
 
#ifdef __cplusplus
4
 
extern "C"
5
 
{
6
 
#endif /* __cplusplus */
7
 
 
8
 
/*
9
 
 * $Id: ringbuffer.h,v 1.4 2006/09/23 18:42:46 llucius Exp $
10
 
 * ringbuffer.h
11
 
 * Ring Buffer utility..
12
 
 *
13
 
 * Author: Phil Burk, http://www.softsynth.com
14
 
 *
15
 
 * This program is distributed with the PortAudio Portable Audio Library.
16
 
 * For more information see: http://www.portaudio.com
17
 
 * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
18
 
 *
19
 
 * Permission is hereby granted, free of charge, to any person obtaining
20
 
 * a copy of this software and associated documentation files
21
 
 * (the "Software"), to deal in the Software without restriction,
22
 
 * including without limitation the rights to use, copy, modify, merge,
23
 
 * publish, distribute, sublicense, and/or sell copies of the Software,
24
 
 * and to permit persons to whom the Software is furnished to do so,
25
 
 * subject to the following conditions:
26
 
 *
27
 
 * The above copyright notice and this permission notice shall be
28
 
 * included in all copies or substantial portions of the Software.
29
 
 *
30
 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31
 
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32
 
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
33
 
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
34
 
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
35
 
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36
 
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37
 
 */
38
 
 
39
 
/*
40
 
 * The text above constitutes the entire PortAudio license; however, 
41
 
 * the PortAudio community also makes the following non-binding requests:
42
 
 *
43
 
 * Any person wishing to distribute modifications to the Software is
44
 
 * requested to send the modifications to the original developer so that
45
 
 * they can be incorporated into the canonical version. It is also 
46
 
 * requested that these non-binding requests be included along with the 
47
 
 * license above.
48
 
 */
49
 
 
50
 
#include <stdio.h>
51
 
#include <stdlib.h>
52
 
#include <math.h>
53
 
#include "ringbuffer.h"
54
 
#include <string.h>
55
 
 
56
 
typedef struct
57
 
{
58
 
    long   bufferSize; /* Number of bytes in FIFO. Power of 2. Set by RingBuffer_Init. */
59
 
    long   writeIndex; /* Index of next writable byte. Set by RingBuffer_AdvanceWriteIndex. */
60
 
    long   readIndex;  /* Index of next readable byte. Set by RingBuffer_AdvanceReadIndex. */
61
 
    long   bigMask;    /* Used for wrapping indices with extra bit to distinguish full/empty. */
62
 
    long   smallMask;  /* Used for fitting indices to buffer. */
63
 
    char *buffer;
64
 
}
65
 
RingBuffer;
66
 
/*
67
 
 * Initialize Ring Buffer.
68
 
 * numBytes must be power of 2, returns -1 if not.
69
 
 */
70
 
long RingBuffer_Init( RingBuffer *rbuf, long numBytes, void *dataPtr );
71
 
 
72
 
/* Clear buffer. Should only be called when buffer is NOT being read. */
73
 
void RingBuffer_Flush( RingBuffer *rbuf );
74
 
 
75
 
/* Return number of bytes available for writing. */
76
 
long RingBuffer_GetWriteAvailable( RingBuffer *rbuf );
77
 
/* Return number of bytes available for read. */
78
 
long RingBuffer_GetReadAvailable( RingBuffer *rbuf );
79
 
/* Return bytes written. */
80
 
long RingBuffer_Write( RingBuffer *rbuf, void *data, long numBytes );
81
 
/* Return bytes read. */
82
 
long RingBuffer_Read( RingBuffer *rbuf, void *data, long numBytes );
83
 
 
84
 
/* Get address of region(s) to which we can write data.
85
 
** If the region is contiguous, size2 will be zero.
86
 
** If non-contiguous, size2 will be the size of second region.
87
 
** Returns room available to be written or numBytes, whichever is smaller.
88
 
*/
89
 
long RingBuffer_GetWriteRegions( RingBuffer *rbuf, long numBytes,
90
 
                                 void **dataPtr1, long *sizePtr1,
91
 
                                 void **dataPtr2, long *sizePtr2 );
92
 
long RingBuffer_AdvanceWriteIndex( RingBuffer *rbuf, long numBytes );
93
 
 
94
 
/* Get address of region(s) from which we can read data.
95
 
** If the region is contiguous, size2 will be zero.
96
 
** If non-contiguous, size2 will be the size of second region.
97
 
** Returns room available to be written or numBytes, whichever is smaller.
98
 
*/
99
 
long RingBuffer_GetReadRegions( RingBuffer *rbuf, long numBytes,
100
 
                                void **dataPtr1, long *sizePtr1,
101
 
                                void **dataPtr2, long *sizePtr2 );
102
 
 
103
 
long RingBuffer_AdvanceReadIndex( RingBuffer *rbuf, long numBytes );
104
 
 
105
 
#ifdef __cplusplus
106
 
}
107
 
#endif /* __cplusplus */
108
 
#endif /* _RINGBUFFER_H */