BlockingStream.java
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00044 package com.portaudio;
00045
00059 public class BlockingStream
00060 {
00061
00062
00063 private long nativeStream;
00064 private int inputFormat = -1;
00065 private int outputFormat = -1;
00066
00067 protected BlockingStream()
00068 {
00069 }
00070
00074 public native int getReadAvailable();
00075
00079 public native int getWriteAvailable();
00080
00081 private native boolean readFloats( float[] buffer, int numFrames );
00082
00083 private native boolean writeFloats( float[] buffer, int numFrames );
00084
00093 public boolean read( float[] buffer, int numFrames )
00094 {
00095 if( inputFormat != PortAudio.FORMAT_FLOAT_32 )
00096 {
00097 throw new RuntimeException(
00098 "Tried to read float samples from a non float stream." );
00099 }
00100 return readFloats( buffer, numFrames );
00101 }
00102
00112 public boolean write( float[] buffer, int numFrames )
00113 {
00114 if( outputFormat != PortAudio.FORMAT_FLOAT_32 )
00115 {
00116 throw new RuntimeException(
00117 "Tried to write float samples to a non float stream." );
00118 }
00119 return writeFloats( buffer, numFrames );
00120 }
00121
00122 private native boolean readShorts( short[] buffer, int numFrames );
00123
00124 private native boolean writeShorts( short[] buffer, int numFrames );
00125
00134 public boolean read( short[] buffer, int numFrames )
00135 {
00136 if( inputFormat != PortAudio.FORMAT_INT_16 )
00137 {
00138 throw new RuntimeException(
00139 "Tried to read short samples from a non short stream." );
00140 }
00141 return readShorts( buffer, numFrames );
00142 }
00143
00152 public boolean write( short[] buffer, int numFrames )
00153 {
00154 if( outputFormat != PortAudio.FORMAT_INT_16 )
00155 {
00156 throw new RuntimeException(
00157 "Tried to write short samples from a non short stream." );
00158 }
00159 return writeShorts( buffer, numFrames );
00160 }
00161
00165 public native void start();
00166
00171 public native void stop();
00172
00176 public native void abort();
00177
00182 public native void close();
00183
00184 public native boolean isStopped();
00185
00186 public native boolean isActive();
00187
00188 public String toString()
00189 {
00190 return "BlockingStream: streamPtr = " + Long.toHexString( nativeStream )
00191 + ", inFormat = " + inputFormat + ", outFormat = "
00192 + outputFormat;
00193 }
00194
00198 public native double getTime();
00199
00200 private native void getInfo( StreamInfo streamInfo );
00201
00202 public StreamInfo getInfo()
00203 {
00204 StreamInfo streamInfo = new StreamInfo();
00205 getInfo( streamInfo );
00206 return streamInfo;
00207 }
00208 }