1 #ifndef PORTAUDIO_PABLIO_H
2 #define PORTAUDIO_PABLIO_H
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif							/* __cplusplus */
7 
8 /*
9  * $Id: pablio.h 1083 2006-08-23 07:30:49Z rossb $
10  * PABLIO.h
11  * Portable Audio Blocking read/write utility.
12  *
13  * Author: Phil Burk, http://www.softsynth.com/portaudio/
14  *
15  * Include file for PABLIO, the Portable Audio Blocking I/O Library.
16  * PABLIO is built on top of PortAudio, the Portable Audio Library.
17  * For more information see: http://www.portaudio.com
18  * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
19  *
20  * Permission is hereby granted, free of charge, to any person obtaining
21  * a copy of this software and associated documentation files
22  * (the "Software"), to deal in the Software without restriction,
23  * including without limitation the rights to use, copy, modify, merge,
24  * publish, distribute, sublicense, and/or sell copies of the Software,
25  * and to permit persons to whom the Software is furnished to do so,
26  * subject to the following conditions:
27  *
28  * The above copyright notice and this permission notice shall be
29  * included in all copies or substantial portions of the Software.
30  *
31  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
34  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
35  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
36  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38  */
39 
40 /*
41  * The text above constitutes the entire PortAudio license; however,
42  * the PortAudio community also makes the following non-binding requests:
43  *
44  * Any person wishing to distribute modifications to the Software is
45  * requested to send the modifications to the original developer so that
46  * they can be incorporated into the canonical version. It is also
47  * requested that these non-binding requests be included along with the
48  * license above.
49  */
50 
51 #include <stdio.h>
52 #include <stdlib.h>
53 #include <math.h>
54 #include <string.h>
55 #include <portaudio.h>
56 #include "pa_ringbuffer.h"
57 
58 /*! Maximum number of channels per stream */
59 #define MAX_IO_CHANNELS 2
60 
61 /*! Maximum numer of milliseconds per packet */
62 #define MAX_IO_MS 100
63 
64 /*! Maximum sampling rate (48Khz) */
65 #define MAX_SAMPLING_RATE  48000
66 
67 /* Maximum size of a read */
68 #define MAX_IO_BUFFER (((MAX_IO_MS * MAX_SAMPLING_RATE)/1000)*sizeof(int16_t))
69 typedef struct {
70 	PaStream *istream;
71 	PaStream *ostream;
72 	PaStream *iostream;
73 	int bytesPerFrame;
74 	int do_dual;
75 	int has_in;
76 	int has_out;
77 	PaUtilRingBuffer inFIFOs[MAX_IO_CHANNELS];
78 	PaUtilRingBuffer outFIFOs[MAX_IO_CHANNELS];
79 	int channelCount;
80 	char iobuff[MAX_IO_BUFFER];
81 } PABLIO_Stream;
82 
83 /* Values for flags for OpenAudioStream(). */
84 #define PABLIO_READ     (1<<0)
85 #define PABLIO_WRITE    (1<<1)
86 #define PABLIO_READ_WRITE    (PABLIO_READ|PABLIO_WRITE)
87 #define PABLIO_MONO     (1<<2)
88 #define PABLIO_STEREO   (1<<3)
89 
90 /************************************************************
91  * Write data to ring buffer.
92  * Will not return until all the data has been written.
93  */
94 long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, int chan, switch_timer_t *timer);
95 
96 /************************************************************
97  * Read data from ring buffer.
98  * Will not return until all the data has been read.
99  */
100 long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, int chan, switch_timer_t *timer);
101 
102 /************************************************************
103  * Return the number of frames that could be written to the stream without
104  * having to wait.
105  */
106 long GetAudioStreamWriteable(PABLIO_Stream * aStream, int chan);
107 
108 /************************************************************
109  * Return the number of frames that are available to be read from the
110  * stream without having to wait.
111  */
112 long GetAudioStreamReadable(PABLIO_Stream * aStream, int chan);
113 
114 /************************************************************
115  * Opens a PortAudio stream with default characteristics.
116  * Allocates PABLIO_Stream structure.
117  *
118  * flags parameter can be an ORed combination of:
119  *    PABLIO_READ, PABLIO_WRITE, or PABLIO_READ_WRITE,
120  *    and either PABLIO_MONO or PABLIO_STEREO
121  */
122 PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
123 			const PaStreamParameters * inputParameters,
124 			const PaStreamParameters * outputParameters,
125 			double sampleRate, PaStreamCallbackFlags statusFlags, long samples_per_packet, int do_dual);
126 
127 PaError CloseAudioStream(PABLIO_Stream * aStream);
128 
129 #ifdef __cplusplus
130 }
131 #endif							/* __cplusplus */
132 #endif							/* _PABLIO_H */
133