PortAudio 2.0
|
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 00044 package com.portaudio; 00045 00069 public class PortAudio 00070 { 00071 public final static int FLAG_CLIP_OFF = (1 << 0); 00072 public final static int FLAG_DITHER_OFF = (1 << 1); 00073 00075 public final static int FORMAT_FLOAT_32 = (1 << 0); 00076 public final static int FORMAT_INT_32 = (1 << 1); // not supported 00077 public final static int FORMAT_INT_24 = (1 << 2); // not supported 00078 public final static int FORMAT_INT_16 = (1 << 3); 00079 public final static int FORMAT_INT_8 = (1 << 4); // not supported 00080 public final static int FORMAT_UINT_8 = (1 << 5); // not supported 00081 00083 public final static int HOST_API_TYPE_DEV = 0; 00084 public final static int HOST_API_TYPE_DIRECTSOUND = 1; 00085 public final static int HOST_API_TYPE_MME = 2; 00086 public final static int HOST_API_TYPE_ASIO = 3; 00088 public final static int HOST_API_TYPE_SOUNDMANAGER = 4; 00089 public final static int HOST_API_TYPE_COREAUDIO = 5; 00090 public final static int HOST_API_TYPE_OSS = 7; 00091 public final static int HOST_API_TYPE_ALSA = 8; 00092 public final static int HOST_API_TYPE_AL = 9; 00093 public final static int HOST_API_TYPE_BEOS = 10; 00094 public final static int HOST_API_TYPE_WDMKS = 11; 00095 public final static int HOST_API_TYPE_JACK = 12; 00096 public final static int HOST_API_TYPE_WASAPI = 13; 00097 public final static int HOST_API_TYPE_AUDIOSCIENCE = 14; 00098 public final static int HOST_API_TYPE_COUNT = 15; 00099 00100 static 00101 { 00102 String os = System.getProperty( "os.name" ).toLowerCase(); 00103 // On Windows we have separate libraries for 32 and 64-bit JVMs. 00104 if( os.indexOf( "win" ) >= 0 ) 00105 { 00106 if( System.getProperty( "os.arch" ).contains( "64" ) ) 00107 { 00108 System.loadLibrary( "jportaudio_x64" ); 00109 } 00110 else 00111 { 00112 System.loadLibrary( "jportaudio_x86" ); 00113 } 00114 } 00115 else 00116 { 00117 System.loadLibrary( "jportaudio" ); 00118 } 00119 System.out.println( "---- JPortAudio version " + getVersion() + ", " 00120 + getVersionText() ); 00121 } 00122 00127 public native static int getVersion(); 00128 00133 public native static String getVersionText(); 00134 00142 public native static void initialize(); 00143 00152 public native static void terminate(); 00153 00158 public native static int getDeviceCount(); 00159 00160 private native static void getDeviceInfo( int index, DeviceInfo deviceInfo ); 00161 00169 public static DeviceInfo getDeviceInfo( int index ) 00170 { 00171 DeviceInfo deviceInfo = new DeviceInfo(); 00172 getDeviceInfo( index, deviceInfo ); 00173 return deviceInfo; 00174 } 00175 00179 public native static int getHostApiCount(); 00180 00181 private native static void getHostApiInfo( int index, 00182 HostApiInfo hostApiInfo ); 00183 00188 public static HostApiInfo getHostApiInfo( int index ) 00189 { 00190 HostApiInfo hostApiInfo = new HostApiInfo(); 00191 getHostApiInfo( index, hostApiInfo ); 00192 return hostApiInfo; 00193 } 00194 00201 public native static int hostApiTypeIdToHostApiIndex( int hostApiType ); 00202 00211 public native static int hostApiDeviceIndexToDeviceIndex( int hostApiIndex, 00212 int apiDeviceIndex ); 00213 00214 public native static int getDefaultInputDevice(); 00215 00216 public native static int getDefaultOutputDevice(); 00217 00218 public native static int getDefaultHostApi(); 00219 00229 public native static int isFormatSupported( 00230 StreamParameters inputStreamParameters, 00231 StreamParameters outputStreamParameters, int sampleRate ); 00232 00233 private native static void openStream( BlockingStream blockingStream, 00234 StreamParameters inputStreamParameters, 00235 StreamParameters outputStreamParameters, int sampleRate, 00236 int framesPerBuffer, int flags ); 00237 00250 public static BlockingStream openStream( 00251 StreamParameters inputStreamParameters, 00252 StreamParameters outputStreamParameters, int sampleRate, 00253 int framesPerBuffer, int flags ) 00254 { 00255 BlockingStream blockingStream = new BlockingStream(); 00256 openStream( blockingStream, inputStreamParameters, 00257 outputStreamParameters, sampleRate, framesPerBuffer, flags ); 00258 return blockingStream; 00259 } 00260 00261 }