pa_host.h

00001 #ifndef PA_HOST_H
00002 #define PA_HOST_H
00003 
00004 /*
00005  * $Id: pa_host.h 94 2003-05-13 10:54:17Z rene-cvs $
00006  * Host dependant internal API for PortAudio
00007  *
00008  * Author: Phil Burk  <philburk@softsynth.com>
00009  *
00010  * PortAudio Portable Real-Time Audio Library
00011  * Latest Version at: http://www.softsynth.com/portaudio/
00012  * DirectSound and Macintosh Implementation
00013  * Copyright (c) 1999-2000 Phil Burk
00014  *
00015  * Permission is hereby granted, free of charge, to any person obtaining
00016  * a copy of this software and associated documentation files
00017  * (the "Software"), to deal in the Software without restriction,
00018  * including without limitation the rights to use, copy, modify, merge,
00019  * publish, distribute, sublicense, and/or sell copies of the Software,
00020  * and to permit persons to whom the Software is furnished to do so,
00021  * subject to the following conditions:
00022  *
00023  * The above copyright notice and this permission notice shall be
00024  * included in all copies or substantial portions of the Software.
00025  *
00026  * Any person wishing to distribute modifications to the Software is
00027  * requested to send the modifications to the original developer so that
00028  * they can be incorporated into the canonical version.
00029  *
00030  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00033  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
00034  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00035  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00037  *
00038  */
00039  
00040 #include "portaudio.h"
00041 
00042 #ifdef __cplusplus
00043 extern "C"
00044 {
00045 #endif /* __cplusplus */
00046 
00047 #ifndef SUPPORT_AUDIO_CAPTURE
00048 #define SUPPORT_AUDIO_CAPTURE  (1)
00049 #endif
00050 
00051 #ifndef int32
00052     typedef long int32;
00053 #endif
00054 #ifndef uint32
00055     typedef unsigned long uint32;
00056 #endif
00057 #ifndef int16
00058     typedef short int16;
00059 #endif
00060 #ifndef uint16
00061     typedef unsigned short uint16;
00062 #endif
00063 
00064 /* Used to convert between various sample formats. */
00065 typedef void (PortAudioConverter)(
00066     void *inputBuffer, int inputStride,
00067     void *outputBuffer, int outputStride,
00068     int numSamples );
00069 
00070 #define PA_MAGIC    (0x18273645)
00071 
00072 /************************************************************************************/
00073 /****************** Structures ******************************************************/
00074 /************************************************************************************/
00075 
00076 typedef struct internalPortAudioStream
00077 {
00078     uint32                    past_Magic;  /* ID for struct to catch bugs. */
00079     /* User specified information. */
00080     uint32                    past_FramesPerUserBuffer;
00081     uint32                    past_NumUserBuffers;
00082     double                    past_SampleRate;     /* Closest supported sample rate. */
00083     int                       past_NumInputChannels;
00084     int                       past_NumOutputChannels;
00085     PaDeviceID                past_InputDeviceID;
00086     PaDeviceID                past_OutputDeviceID;
00087     PaSampleFormat            past_NativeInputSampleFormat;
00088     PaSampleFormat            past_InputSampleFormat;
00089     PaSampleFormat            past_NativeOutputSampleFormat;
00090     PaSampleFormat            past_OutputSampleFormat;
00091     void                     *past_DeviceData;
00092     PortAudioCallback        *past_Callback;
00093     void                     *past_UserData;
00094     uint32                    past_Flags;
00095     /* Flags for communicating between foreground and background. */
00096     volatile int              past_IsActive;      /* Background is still playing. */
00097     volatile int              past_StopSoon;      /* Background should keep playing when buffers empty. */
00098     volatile int              past_StopNow;       /* Background should stop playing now. */
00099     /* These buffers are used when the native format does not match the user format. */
00100     void                     *past_InputBuffer;
00101     uint32                    past_InputBufferSize;
00102     void                     *past_OutputBuffer;
00103     uint32                    past_OutputBufferSize;
00104     /* Measurements */
00105     uint32                    past_NumCallbacks;
00106     PaTimestamp               past_FrameCount;    /* Frames output to buffer. */
00107     /* For measuring CPU utilization. */
00108     double                    past_AverageInsideCount;
00109     double                    past_AverageTotalCount;
00110     double                    past_Usage;
00111     int                       past_IfLastExitValid;
00112     /* Format Conversion */
00113     /* These are setup by PaConversion_Setup() */
00114     PortAudioConverter       *past_InputConversionProc;
00115     int                       past_InputConversionSourceStride;
00116     int                       past_InputConversionTargetStride;
00117     PortAudioConverter       *past_OutputConversionProc;
00118     int                       past_OutputConversionSourceStride;
00119     int                       past_OutputConversionTargetStride;
00120 }
00121 internalPortAudioStream;
00122 
00123 /************************************************************************************/
00124 /******** These functions must be provided by a platform implementation. ************/
00125 /************************************************************************************/
00126 
00127 PaError PaHost_Init( void );
00128 PaError PaHost_Term( void );
00129 
00130 PaError PaHost_OpenStream( internalPortAudioStream   *past );
00131 PaError PaHost_CloseStream( internalPortAudioStream   *past );
00132 
00133 PaError PaHost_StartOutput( internalPortAudioStream   *past );
00134 PaError PaHost_StopOutput( internalPortAudioStream   *past, int abort );
00135 PaError PaHost_StartInput( internalPortAudioStream   *past );
00136 PaError PaHost_StopInput( internalPortAudioStream   *past, int abort );
00137 PaError PaHost_StartEngine( internalPortAudioStream   *past );
00138 PaError PaHost_StopEngine( internalPortAudioStream *past, int abort );
00139 PaError PaHost_StreamActive( internalPortAudioStream   *past );
00140 
00141 void   *PaHost_AllocateFastMemory( long numBytes );
00142 void    PaHost_FreeFastMemory( void *addr, long numBytes );
00143 
00144 /* This only called if PA_VALIDATE_RATE IS CALLED. */
00145 PaError PaHost_ValidateSampleRate( PaDeviceID id, double requestedFrameRate,
00146                                    double *closestFrameRatePtr );
00147 
00148 /**********************************************************************/
00149 /************ Common Utility Routines provided by PA ******************/
00150 /**********************************************************************/
00151 
00152 /* PaHost_IsInitialized() returns non-zero if PA is initialized, 0 otherwise */
00153 int PaHost_IsInitialized( void );
00154 
00155 internalPortAudioStream* PaHost_GetStreamRepresentation( PortAudioStream *stream );
00156 
00157 int PaHost_FindClosestTableEntry( double allowableError,  const double *rateTable,
00158                                   int numRates, double frameRate );
00159 
00160 long Pa_CallConvertInt16( internalPortAudioStream   *past,
00161                           short *nativeInputBuffer,
00162                           short *nativeOutputBuffer );
00163                           
00164 /* Calculate 2 LSB dither signal with a triangular distribution.
00165 ** Ranged properly for adding to a 32 bit 1.31 fixed point value prior to >>15.
00166 ** Range of output is +/- 65535
00167 ** Multiply by PA_DITHER_SCALE to get a float between -2.0 and 2.0. */
00168 #define PA_DITHER_BITS   (15)
00169 #define PA_DITHER_SCALE  (1.0f / ((1<<PA_DITHER_BITS)-1))
00170 long PaConvert_TriangularDither( void );
00171 
00172 PaError PaConvert_SetupInput( internalPortAudioStream   *past,
00173     PaSampleFormat   nativeInputSampleFormat );
00174 
00175 PaError PaConvert_SetupOutput( internalPortAudioStream   *past,
00176     PaSampleFormat   nativeOutputSampleFormat );
00177 
00178 long PaConvert_Process( internalPortAudioStream   *past,
00179             void *nativeInputBuffer,
00180             void *nativeOutputBuffer );
00181 
00182 #ifdef __cplusplus
00183 }
00184 #endif /* __cplusplus */
00185 #endif /* PA_HOST_H */

Generated on Mon Jun 5 10:20:43 2006 for Intelligence.kdevelop by  doxygen 1.4.6