com_portaudio_PortAudio.c

00001 /*
00002  * Portable Audio I/O Library
00003  * Java Binding for PortAudio
00004  *
00005  * Based on the Open Source API proposed by Ross Bencina
00006  * Copyright (c) 2008 Ross Bencina
00007  *
00008  * Permission is hereby granted, free of charge, to any person obtaining
00009  * a copy of this software and associated documentation files
00010  * (the "Software"), to deal in the Software without restriction,
00011  * including without limitation the rights to use, copy, modify, merge,
00012  * publish, distribute, sublicense, and/or sell copies of the Software,
00013  * and to permit persons to whom the Software is furnished to do so,
00014  * subject to the following conditions:
00015  *
00016  * The above copyright notice and this permission notice shall be
00017  * included in all copies or substantial portions of the Software.
00018  *
00019  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00020  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00021  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00022  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
00023  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00024  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00025  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00026  */
00027 
00028 /*
00029  * The text above constitutes the entire PortAudio license; however, 
00030  * the PortAudio community also makes the following non-binding requests:
00031  *
00032  * Any person wishing to distribute modifications to the Software is
00033  * requested to send the modifications to the original developer so that
00034  * they can be incorporated into the canonical version. It is also 
00035  * requested that these non-binding requests be included along with the 
00036  * license above.
00037  */
00038 
00039 #include "com_portaudio_PortAudio.h"
00040 #include "portaudio.h"
00041 #include "jpa_tools.h"
00042 
00043 /*
00044  * Class:     com_portaudio_PortAudio
00045  * Method:    getVersion
00046  * Signature: ()I
00047  */
00048 JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getVersion
00049   (JNIEnv *env, jclass clazz)
00050 {
00051         return Pa_GetVersion();
00052 }
00053 
00054 /*
00055  * Class:     com_portaudio_PortAudio
00056  * Method:    getVersionText
00057  * Signature: ()Ljava/lang/String;
00058  */
00059 JNIEXPORT jstring JNICALL Java_com_portaudio_PortAudio_getVersionText
00060   (JNIEnv *env, jclass clazz)
00061 {
00062         return (*env)->NewStringUTF(env, Pa_GetVersionText() );
00063 }
00064 
00065 /*
00066  * Class:     com_portaudio_PortAudio
00067  * Method:    initialize
00068  * Signature: ()I
00069  */
00070 JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_initialize
00071   (JNIEnv *env, jclass clazz)
00072 {
00073         PaError err = Pa_Initialize();
00074         jpa_CheckError( env, err );
00075 }
00076 
00077 /*
00078  * Class:     com_portaudio_PortAudio
00079  * Method:    terminate
00080  * Signature: ()I
00081  */
00082 JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_terminate
00083   (JNIEnv *env, jclass clazz)
00084 {
00085         PaError err = Pa_Terminate();
00086         jpa_CheckError( env, err );
00087 }
00088 
00089 /*
00090  * Class:     com_portaudio_PortAudio
00091  * Method:    getDeviceCount
00092  * Signature: ()I
00093  */
00094 JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getDeviceCount
00095   (JNIEnv *env, jclass clazz)
00096 {
00097         jint count = Pa_GetDeviceCount();
00098         return jpa_CheckError( env, count );
00099 }
00100 
00101 /*
00102  * Class:     com_portaudio_PortAudio
00103  * Method:    getDeviceInfo
00104  * Signature: (ILcom/portaudio/DeviceInfo;)I
00105  */
00106 JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_getDeviceInfo
00107   (JNIEnv *env, jclass clazz, jint index, jobject deviceInfo)
00108 {
00109         const PaDeviceInfo *info;
00110              /* Get a reference to obj's class */
00111         jclass cls = (*env)->GetObjectClass(env, deviceInfo);
00112  
00113         info = Pa_GetDeviceInfo( index );
00114         if( info == NULL )
00115         {
00116                 jpa_ThrowError( env, "Pa_GetDeviceInfo returned NULL." );
00117         }
00118         else
00119         {
00120                 jpa_SetStringField( env, cls, deviceInfo, "name", info->name );
00121                 jpa_SetIntField( env, cls, deviceInfo, "maxInputChannels", info->maxInputChannels );
00122                 jpa_SetIntField( env, cls, deviceInfo, "maxOutputChannels", info->maxOutputChannels );
00123                 jpa_SetIntField( env, cls, deviceInfo, "hostApi", info->hostApi );
00124                 jpa_SetDoubleField( env, cls, deviceInfo, "defaultSampleRate", info->defaultSampleRate );
00125                 jpa_SetDoubleField( env, cls, deviceInfo, "defaultLowInputLatency", info->defaultLowInputLatency );
00126                 jpa_SetDoubleField( env, cls, deviceInfo, "defaultLowInputLatency", info->defaultHighInputLatency );
00127                 jpa_SetDoubleField( env, cls, deviceInfo, "defaultLowOutputLatency", info->defaultLowOutputLatency );
00128                 jpa_SetDoubleField( env, cls, deviceInfo, "defaultHighOutputLatency", info->defaultHighOutputLatency );
00129         }
00130 }
00131 
00132 /*
00133  * Class:     com_portaudio_PortAudio
00134  * Method:    geHostApiCount
00135  * Signature: ()I
00136  */
00137 JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getHostApiCount
00138   (JNIEnv *env, jclass clazz)
00139 {
00140         jint count = Pa_GetHostApiCount();
00141         return jpa_CheckError( env, count );
00142 }
00143 
00144 
00145 /*
00146  * Class:     com_portaudio_PortAudio
00147  * Method:    hostApiTypeIdToHostApiIndex
00148  * Signature: (I)I
00149  */
00150 JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_hostApiTypeIdToHostApiIndex
00151   (JNIEnv *env, jclass clazz, jint hostApiType)
00152 {
00153         return Pa_HostApiTypeIdToHostApiIndex( (PaHostApiTypeId) hostApiType );
00154 }
00155 
00156 /*
00157  * Class:     com_portaudio_PortAudio
00158  * Method:    hostApiDeviceIndexToDeviceIndex
00159  * Signature: (II)I
00160  */
00161 JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_hostApiDeviceIndexToDeviceIndex
00162   (JNIEnv *env, jclass clazz, jint hostApiIndex, jint apiDeviceIndex)
00163 {
00164         return Pa_HostApiDeviceIndexToDeviceIndex( hostApiIndex, apiDeviceIndex );
00165 }
00166 
00167 
00168 /*
00169  * Class:     com_portaudio_PortAudio
00170  * Method:    getHostApiInfo
00171  * Signature: (ILcom/portaudio/HostApiInfo;)I
00172  */
00173 JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_getHostApiInfo
00174   (JNIEnv *env, jclass clazz, jint index, jobject hostApiInfo)
00175 {
00176         const PaHostApiInfo *info;
00177              /* Get a reference to obj's class */
00178         jclass cls = (*env)->GetObjectClass(env, hostApiInfo);
00179  
00180         info = Pa_GetHostApiInfo( index );
00181         if( info == NULL )
00182         {
00183                 jpa_ThrowError( env, "Pa_GetHostApiInfo returned NULL." );
00184         }
00185         else
00186         {
00187                 jpa_SetIntField( env, cls, hostApiInfo, "version", info->structVersion );
00188                 jpa_SetIntField( env, cls, hostApiInfo, "type", info->type );
00189                 jpa_SetStringField( env, cls, hostApiInfo, "name", info->name );
00190                 jpa_SetIntField( env, cls, hostApiInfo, "deviceCount", info->deviceCount );
00191                 jpa_SetIntField( env, cls, hostApiInfo, "defaultInputDevice", info->defaultInputDevice );
00192                 jpa_SetIntField( env, cls, hostApiInfo, "defaultOutputDevice", info->defaultOutputDevice );
00193         }
00194 }
00195 
00196 /*
00197  * Class:     com_portaudio_PortAudio
00198  * Method:    getDefaultInputDevice
00199  * Signature: ()I
00200  */
00201 JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getDefaultInputDevice
00202   (JNIEnv *env, jclass clazz)
00203 {
00204         jint deviceId = Pa_GetDefaultInputDevice();
00205         return jpa_CheckError( env, deviceId );
00206 }
00207 
00208 /*
00209  * Class:     com_portaudio_PortAudio
00210  * Method:    getDefaultOutputDevice
00211  * Signature: ()I
00212  */
00213 JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getDefaultOutputDevice
00214   (JNIEnv *env, jclass clazz)
00215 {
00216         jint deviceId = Pa_GetDefaultOutputDevice();
00217         return jpa_CheckError( env, deviceId );
00218 }
00219 
00220 /*
00221  * Class:     com_portaudio_PortAudio
00222  * Method:    getDefaultHostApi
00223  * Signature: ()I
00224  */
00225 JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getDefaultHostApi
00226   (JNIEnv *env, jclass clazz)
00227 {
00228         jint deviceId = Pa_GetDefaultHostApi();
00229         return jpa_CheckError( env, deviceId );
00230 }
00231 
00232 /*
00233  * Class:     com_portaudio_PortAudio
00234  * Method:    isFormatSupported
00235  * Signature: (Lcom/portaudio/StreamParameters;Lcom/portaudio/StreamParameters;I)I
00236  */
00237 JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_isFormatSupported
00238   (JNIEnv *env, jclass clazz, jobject inParams, jobject outParams, jint sampleRate )
00239 {
00240         PaStreamParameters myInParams, *paInParams;
00241         PaStreamParameters myOutParams, *paOutParams;
00242         
00243         paInParams = jpa_FillStreamParameters(  env, inParams, &myInParams );
00244         paOutParams = jpa_FillStreamParameters(  env, outParams, &myOutParams );
00245         
00246         return Pa_IsFormatSupported( paInParams, paOutParams, sampleRate );
00247 
00248 }
00249 
00250 /*
00251  * Class:     com_portaudio_PortAudio
00252  * Method:    openStream
00253  * Signature: (Lcom/portaudio/BlockingStream;Lcom/portaudio/StreamParameters;Lcom/portaudio/StreamParameters;III)I
00254  */
00255 JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_openStream
00256   (JNIEnv *env, jclass clazz, jobject blockingStream,  jobject inParams, jobject outParams, jint sampleRate, jint framesPerBuffer, jint flags )
00257 {
00258         int err;
00259         PaStreamParameters myInParams, *paInParams;
00260         PaStreamParameters myOutParams, *paOutParams;
00261         PaStream *stream;
00262         
00263         paInParams = jpa_FillStreamParameters(  env, inParams, &myInParams );
00264         paOutParams = jpa_FillStreamParameters(  env, outParams, &myOutParams );
00265         err = Pa_OpenStream( &stream, paInParams, paOutParams, sampleRate, framesPerBuffer, flags, NULL, NULL );
00266         if( jpa_CheckError( env, err ) == 0 )
00267         {
00268                 jclass cls = (*env)->GetObjectClass(env, blockingStream);
00269                 jpa_SetLongField( env, cls, blockingStream, "nativeStream", (jlong) stream );
00270                 if( paInParams != NULL )
00271                 {
00272                         jpa_SetIntField( env, cls, blockingStream, "inputFormat", paInParams->sampleFormat );
00273                 }
00274                 if( paOutParams != NULL )
00275                 {
00276                         jpa_SetIntField( env, cls, blockingStream, "outputFormat", paOutParams->sampleFormat );
00277                 }
00278         }
00279 }

Generated on Sat Aug 6 19:33:25 2016 for PortAudio by  doxygen 1.5.6