~ubuntu-branches/ubuntu/precise/puredata/precise

« back to all changes in this revision

Viewing changes to src/s_audio_paring.h

  • Committer: Bazaar Package Importer
  • Author(s): Paul Brossier
  • Date: 2009-12-22 21:29:31 UTC
  • mfrom: (1.2.6 upstream) (4.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091222212931-nhwkzapjwsmjao1l
Tags: 0.42.5-3
* debian/control:
  - add community site to homepage field
  - improve long description
  - remove Replaces and Conflicts fields
  - add Suggests on pd-csound, pd-pdp, pd-zexy, pd-aubio
* debian/rules: add per-arch configuration flags
* debian/patches/02_kfreebsd.diff:
  - also define pd_tilde_dllextent on FreeBSD
  - fix typo (really closing #414414 this time)
  - also add hurd glue
* debian/patches/04_hurd.diff:
  - add hurd glue and s_midi_dummy.c

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