PortAudio  2.0
com_portaudio_PortAudio.c
1 /*
2  * Portable Audio I/O Library
3  * Java Binding for PortAudio
4  *
5  * Based on the Open Source API proposed by Ross Bencina
6  * Copyright (c) 2008 Ross Bencina
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files
10  * (the "Software"), to deal in the Software without restriction,
11  * including without limitation the rights to use, copy, modify, merge,
12  * publish, distribute, sublicense, and/or sell copies of the Software,
13  * and to permit persons to whom the Software is furnished to do so,
14  * subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
23  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
24  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27 
28 /*
29  * The text above constitutes the entire PortAudio license; however,
30  * the PortAudio community also makes the following non-binding requests:
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. It is also
35  * requested that these non-binding requests be included along with the
36  * license above.
37  */
38 
39 #include "com_portaudio_PortAudio.h"
40 #include "portaudio.h"
41 #include "jpa_tools.h"
42 
43 /*
44  * Class: com_portaudio_PortAudio
45  * Method: getVersion
46  * Signature: ()I
47  */
48 JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getVersion
49  (JNIEnv *env, jclass clazz)
50 {
51  return Pa_GetVersion();
52 }
53 
54 /*
55  * Class: com_portaudio_PortAudio
56  * Method: getVersionText
57  * Signature: ()Ljava/lang/String;
58  */
59 JNIEXPORT jstring JNICALL Java_com_portaudio_PortAudio_getVersionText
60  (JNIEnv *env, jclass clazz)
61 {
62  return (*env)->NewStringUTF(env, Pa_GetVersionText() );
63 }
64 
65 /*
66  * Class: com_portaudio_PortAudio
67  * Method: initialize
68  * Signature: ()I
69  */
70 JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_initialize
71  (JNIEnv *env, jclass clazz)
72 {
73  PaError err = Pa_Initialize();
74  jpa_CheckError( env, err );
75 }
76 
77 /*
78  * Class: com_portaudio_PortAudio
79  * Method: terminate
80  * Signature: ()I
81  */
82 JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_terminate
83  (JNIEnv *env, jclass clazz)
84 {
85  PaError err = Pa_Terminate();
86  jpa_CheckError( env, err );
87 }
88 
89 /*
90  * Class: com_portaudio_PortAudio
91  * Method: getDeviceCount
92  * Signature: ()I
93  */
94 JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getDeviceCount
95  (JNIEnv *env, jclass clazz)
96 {
97  jint count = Pa_GetDeviceCount();
98  return jpa_CheckError( env, count );
99 }
100 
101 /*
102  * Class: com_portaudio_PortAudio
103  * Method: getDeviceInfo
104  * Signature: (ILcom/portaudio/DeviceInfo;)I
105  */
106 JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_getDeviceInfo
107  (JNIEnv *env, jclass clazz, jint index, jobject deviceInfo)
108 {
109  const PaDeviceInfo *info;
110  /* Get a reference to obj's class */
111  jclass cls = (*env)->GetObjectClass(env, deviceInfo);
112 
113  info = Pa_GetDeviceInfo( index );
114  if( info == NULL )
115  {
116  jpa_ThrowError( env, "Pa_GetDeviceInfo returned NULL." );
117  }
118  else
119  {
120  jpa_SetStringField( env, cls, deviceInfo, "name", info->name );
121  jpa_SetIntField( env, cls, deviceInfo, "maxInputChannels", info->maxInputChannels );
122  jpa_SetIntField( env, cls, deviceInfo, "maxOutputChannels", info->maxOutputChannels );
123  jpa_SetIntField( env, cls, deviceInfo, "hostApi", info->hostApi );
124  jpa_SetDoubleField( env, cls, deviceInfo, "defaultSampleRate", info->defaultSampleRate );
125  jpa_SetDoubleField( env, cls, deviceInfo, "defaultLowInputLatency", info->defaultLowInputLatency );
126  jpa_SetDoubleField( env, cls, deviceInfo, "defaultLowInputLatency", info->defaultHighInputLatency );
127  jpa_SetDoubleField( env, cls, deviceInfo, "defaultLowOutputLatency", info->defaultLowOutputLatency );
128  jpa_SetDoubleField( env, cls, deviceInfo, "defaultHighOutputLatency", info->defaultHighOutputLatency );
129  }
130 }
131 
132 /*
133  * Class: com_portaudio_PortAudio
134  * Method: geHostApiCount
135  * Signature: ()I
136  */
137 JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getHostApiCount
138  (JNIEnv *env, jclass clazz)
139 {
140  jint count = Pa_GetHostApiCount();
141  return jpa_CheckError( env, count );
142 }
143 
144 
145 /*
146  * Class: com_portaudio_PortAudio
147  * Method: hostApiTypeIdToHostApiIndex
148  * Signature: (I)I
149  */
150 JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_hostApiTypeIdToHostApiIndex
151  (JNIEnv *env, jclass clazz, jint hostApiType)
152 {
153  return Pa_HostApiTypeIdToHostApiIndex( (PaHostApiTypeId) hostApiType );
154 }
155 
156 /*
157  * Class: com_portaudio_PortAudio
158  * Method: hostApiDeviceIndexToDeviceIndex
159  * Signature: (II)I
160  */
161 JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_hostApiDeviceIndexToDeviceIndex
162  (JNIEnv *env, jclass clazz, jint hostApiIndex, jint apiDeviceIndex)
163 {
164  return Pa_HostApiDeviceIndexToDeviceIndex( hostApiIndex, apiDeviceIndex );
165 }
166 
167 
168 /*
169  * Class: com_portaudio_PortAudio
170  * Method: getHostApiInfo
171  * Signature: (ILcom/portaudio/HostApiInfo;)I
172  */
173 JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_getHostApiInfo
174  (JNIEnv *env, jclass clazz, jint index, jobject hostApiInfo)
175 {
176  const PaHostApiInfo *info;
177  /* Get a reference to obj's class */
178  jclass cls = (*env)->GetObjectClass(env, hostApiInfo);
179 
180  info = Pa_GetHostApiInfo( index );
181  if( info == NULL )
182  {
183  jpa_ThrowError( env, "Pa_GetHostApiInfo returned NULL." );
184  }
185  else
186  {
187  jpa_SetIntField( env, cls, hostApiInfo, "version", info->structVersion );
188  jpa_SetIntField( env, cls, hostApiInfo, "type", info->type );
189  jpa_SetStringField( env, cls, hostApiInfo, "name", info->name );
190  jpa_SetIntField( env, cls, hostApiInfo, "deviceCount", info->deviceCount );
191  jpa_SetIntField( env, cls, hostApiInfo, "defaultInputDevice", info->defaultInputDevice );
192  jpa_SetIntField( env, cls, hostApiInfo, "defaultOutputDevice", info->defaultOutputDevice );
193  }
194 }
195 
196 /*
197  * Class: com_portaudio_PortAudio
198  * Method: getDefaultInputDevice
199  * Signature: ()I
200  */
201 JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getDefaultInputDevice
202  (JNIEnv *env, jclass clazz)
203 {
204  jint deviceId = Pa_GetDefaultInputDevice();
205  return jpa_CheckError( env, deviceId );
206 }
207 
208 /*
209  * Class: com_portaudio_PortAudio
210  * Method: getDefaultOutputDevice
211  * Signature: ()I
212  */
213 JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getDefaultOutputDevice
214  (JNIEnv *env, jclass clazz)
215 {
216  jint deviceId = Pa_GetDefaultOutputDevice();
217  return jpa_CheckError( env, deviceId );
218 }
219 
220 /*
221  * Class: com_portaudio_PortAudio
222  * Method: getDefaultHostApi
223  * Signature: ()I
224  */
225 JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getDefaultHostApi
226  (JNIEnv *env, jclass clazz)
227 {
228  jint deviceId = Pa_GetDefaultHostApi();
229  return jpa_CheckError( env, deviceId );
230 }
231 
232 /*
233  * Class: com_portaudio_PortAudio
234  * Method: isFormatSupported
235  * Signature: (Lcom/portaudio/StreamParameters;Lcom/portaudio/StreamParameters;I)I
236  */
237 JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_isFormatSupported
238  (JNIEnv *env, jclass clazz, jobject inParams, jobject outParams, jint sampleRate )
239 {
240  PaStreamParameters myInParams, *paInParams;
241  PaStreamParameters myOutParams, *paOutParams;
242 
243  paInParams = jpa_FillStreamParameters( env, inParams, &myInParams );
244  paOutParams = jpa_FillStreamParameters( env, outParams, &myOutParams );
245 
246  return Pa_IsFormatSupported( paInParams, paOutParams, sampleRate );
247 
248 }
249 
250 /*
251  * Class: com_portaudio_PortAudio
252  * Method: openStream
253  * Signature: (Lcom/portaudio/BlockingStream;Lcom/portaudio/StreamParameters;Lcom/portaudio/StreamParameters;III)I
254  */
255 JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_openStream
256  (JNIEnv *env, jclass clazz, jobject blockingStream, jobject inParams, jobject outParams, jint sampleRate, jint framesPerBuffer, jint flags )
257 {
258  int err;
259  PaStreamParameters myInParams, *paInParams;
260  PaStreamParameters myOutParams, *paOutParams;
261  PaStream *stream;
262 
263  paInParams = jpa_FillStreamParameters( env, inParams, &myInParams );
264  paOutParams = jpa_FillStreamParameters( env, outParams, &myOutParams );
265  err = Pa_OpenStream( &stream, paInParams, paOutParams, sampleRate, framesPerBuffer, flags, NULL, NULL );
266  if( jpa_CheckError( env, err ) == 0 )
267  {
268  jclass cls = (*env)->GetObjectClass(env, blockingStream);
269  jpa_SetLongField( env, cls, blockingStream, "nativeStream", (jlong) stream );
270  if( paInParams != NULL )
271  {
272  jpa_SetIntField( env, cls, blockingStream, "inputFormat", paInParams->sampleFormat );
273  }
274  if( paOutParams != NULL )
275  {
276  jpa_SetIntField( env, cls, blockingStream, "outputFormat", paOutParams->sampleFormat );
277  }
278  }
279 }

Generated for PortAudio by  doxygen1.8.3.1