| 1 | #ifndef _PABLIO_H |
| 2 | #define _PABLIO_H |
| 3 | |
| 4 | #ifdef __cplusplus |
| 5 | extern "C" |
| 6 | { |
| 7 | #endif /* __cplusplus */ |
| 8 | |
| 9 | /* |
| 10 | * $Id: pablio.h,v 1.3 2006/06/10 21:30:55 dmazzoni Exp $ |
| 11 | * PABLIO.h |
| 12 | * Portable Audio Blocking read/write utility. |
| 13 | * |
| 14 | * Author: Phil Burk, http://www.softsynth.com/portaudio/ |
| 15 | * |
| 16 | * Include file for PABLIO, the Portable Audio Blocking I/O Library. |
| 17 | * PABLIO is built on top of PortAudio, the Portable Audio Library. |
| 18 | * For more information see: http://www.audiomulch.com/portaudio/ |
| 19 | * Copyright (c) 1999-2000 Ross Bencina and Phil Burk |
| 20 | * |
| 21 | * Permission is hereby granted, free of charge, to any person obtaining |
| 22 | * a copy of this software and associated documentation files |
| 23 | * (the "Software"), to deal in the Software without restriction, |
| 24 | * including without limitation the rights to use, copy, modify, merge, |
| 25 | * publish, distribute, sublicense, and/or sell copies of the Software, |
| 26 | * and to permit persons to whom the Software is furnished to do so, |
| 27 | * subject to the following conditions: |
| 28 | * |
| 29 | * The above copyright notice and this permission notice shall be |
| 30 | * included in all copies or substantial portions of the Software. |
| 31 | * |
| 32 | * Any person wishing to distribute modifications to the Software is |
| 33 | * requested to send the modifications to the original developer so that |
| 34 | * they can be incorporated into the canonical version. |
| 35 | * |
| 36 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 37 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 38 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 39 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR |
| 40 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 41 | * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 42 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 43 | * |
| 44 | */ |
| 45 | #include <stdio.h> |
| 46 | #include <stdlib.h> |
| 47 | #include <math.h> |
| 48 | #include "portaudio.h" |
| 49 | #include "ringbuffer.h" |
| 50 | #include <string.h> |
| 51 | |
| 52 | typedef struct |
| 53 | { |
| 54 | RingBuffer inFIFO; |
| 55 | RingBuffer outFIFO; |
| 56 | PaStream *stream; |
| 57 | int bytesPerFrame; |
| 58 | int samplesPerFrame; |
| 59 | } |
| 60 | PABLIO_Stream; |
| 61 | |
| 62 | /* Values for flags for OpenAudioStream(). */ |
| 63 | #define PABLIO_READ (1<<0) |
| 64 | #define PABLIO_WRITE (1<<1) |
| 65 | #define PABLIO_READ_WRITE (PABLIO_READ|PABLIO_WRITE) |
| 66 | #define PABLIO_MONO (1<<2) |
| 67 | #define PABLIO_STEREO (1<<3) |
| 68 | |
| 69 | /************************************************************ |
| 70 | * Write data to ring buffer. |
| 71 | * Will not return until all the data has been written. |
| 72 | */ |
| 73 | long WriteAudioStream( PABLIO_Stream *aStream, void *data, long numFrames ); |
| 74 | |
| 75 | /************************************************************ |
| 76 | * Read data from ring buffer. |
| 77 | * Will not return until all the data has been read. |
| 78 | */ |
| 79 | long ReadAudioStream( PABLIO_Stream *aStream, void *data, long numFrames ); |
| 80 | |
| 81 | /************************************************************ |
| 82 | * Return the number of frames that could be written to the stream without |
| 83 | * having to wait. |
| 84 | */ |
| 85 | long GetAudioStreamWriteable( PABLIO_Stream *aStream ); |
| 86 | |
| 87 | /************************************************************ |
| 88 | * Return the number of frames that are available to be read from the |
| 89 | * stream without having to wait. |
| 90 | */ |
| 91 | long GetAudioStreamReadable( PABLIO_Stream *aStream ); |
| 92 | |
| 93 | /************************************************************ |
| 94 | * Opens a PortAudio stream with default characteristics. |
| 95 | * Allocates PABLIO_Stream structure. |
| 96 | * |
| 97 | * flags parameter can be an ORed combination of: |
| 98 | * PABLIO_READ, PABLIO_WRITE, or PABLIO_READ_WRITE, |
| 99 | * and either PABLIO_MONO or PABLIO_STEREO |
| 100 | */ |
| 101 | PaError OpenAudioStream( PABLIO_Stream **aStreamPtr, double sampleRate, |
| 102 | PaSampleFormat format, long flags ); |
| 103 | |
| 104 | PaError CloseAudioStream( PABLIO_Stream *aStream ); |
| 105 | |
| 106 | #ifdef __cplusplus |
| 107 | } |
| 108 | #endif /* __cplusplus */ |
| 109 | #endif /* _PABLIO_H */ |