Initial check-in for an experimental Java binding for PortAudio called JPortAudio.
This commit is contained in:
parent
468c6bceb7
commit
e58d315241
24 changed files with 2782 additions and 4 deletions
8
bindings/java/jportaudio/.classpath
Normal file
8
bindings/java/jportaudio/.classpath
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="jtests"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
17
bindings/java/jportaudio/.project
Normal file
17
bindings/java/jportaudio/.project
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>JPortAudio</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
523
bindings/java/jportaudio/jtests/com/portaudio/TestBasic.java
Normal file
523
bindings/java/jportaudio/jtests/com/portaudio/TestBasic.java
Normal file
|
|
@ -0,0 +1,523 @@
|
|||
/*
|
||||
* Portable Audio I/O Library
|
||||
* Java Binding for PortAudio
|
||||
*
|
||||
* Based on the Open Source API proposed by Ross Bencina
|
||||
* Copyright (c) 2008 Ross Bencina
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
||||
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* the PortAudio community also makes the following non-binding requests:
|
||||
*
|
||||
* Any person wishing to distribute modifications to the Software is
|
||||
* requested to send the modifications to the original developer so that
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* license above.
|
||||
*/
|
||||
|
||||
package com.portaudio;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Test the Java bindings for PortAudio.
|
||||
*
|
||||
* @author Phil Burk
|
||||
*
|
||||
*/
|
||||
public class TestBasic extends TestCase
|
||||
{
|
||||
|
||||
public void testDeviceCount()
|
||||
{
|
||||
PortAudio.initialize();
|
||||
assertTrue( "version invalid", (PortAudio.getVersion() > 0) );
|
||||
System.out.println( "getVersion = " + PortAudio.getVersion() );
|
||||
System.out.println( "getVersionText = " + PortAudio.getVersionText() );
|
||||
System.out.println( "getDeviceCount = " + PortAudio.getDeviceCount() );
|
||||
assertTrue( "getDeviceCount", (PortAudio.getDeviceCount() > 0) );
|
||||
PortAudio.terminate();
|
||||
}
|
||||
|
||||
public void testListDevices()
|
||||
{
|
||||
PortAudio.initialize();
|
||||
int count = PortAudio.getDeviceCount();
|
||||
assertTrue( "getDeviceCount", (count > 0) );
|
||||
for( int i = 0; i < count; i++ )
|
||||
{
|
||||
DeviceInfo info = PortAudio.getDeviceInfo( i );
|
||||
System.out.println( "------------------ #" + i );
|
||||
System.out.println( " name = " + info.name );
|
||||
System.out.println( " hostApi = " + info.hostApi );
|
||||
System.out.println( " maxOutputChannels = "
|
||||
+ info.maxOutputChannels );
|
||||
System.out.println( " maxInputChannels = "
|
||||
+ info.maxInputChannels );
|
||||
System.out.println( " defaultSampleRate = "
|
||||
+ info.defaultSampleRate );
|
||||
System.out.printf( " defaultLowInputLatency = %3d msec\n",
|
||||
((int) (info.defaultLowInputLatency * 1000)) );
|
||||
System.out.printf( " defaultHighInputLatency = %3d msec\n",
|
||||
((int) (info.defaultHighInputLatency * 1000)) );
|
||||
System.out.printf( " defaultLowOutputLatency = %3d msec\n",
|
||||
((int) (info.defaultLowOutputLatency * 1000)) );
|
||||
System.out.printf( " defaultHighOutputLatency = %3d msec\n",
|
||||
((int) (info.defaultHighOutputLatency * 1000)) );
|
||||
|
||||
assertTrue( "some channels",
|
||||
(info.maxOutputChannels + info.maxInputChannels) > 0 );
|
||||
assertTrue( "not too many channels", (info.maxInputChannels < 64) );
|
||||
assertTrue( "not too many channels", (info.maxOutputChannels < 64) );
|
||||
}
|
||||
|
||||
System.out.println( "defaultInput = "
|
||||
+ PortAudio.getDefaultInputDevice() );
|
||||
System.out.println( "defaultOutput = "
|
||||
+ PortAudio.getDefaultOutputDevice() );
|
||||
|
||||
PortAudio.terminate();
|
||||
}
|
||||
|
||||
public void testHostApis()
|
||||
{
|
||||
PortAudio.initialize();
|
||||
int validApiCount = 0;
|
||||
for( int hostApiType = 0; hostApiType < PortAudio.HOST_API_TYPE_COUNT; hostApiType++ )
|
||||
{
|
||||
int hostApiIndex = PortAudio
|
||||
.hostApiTypeIdToHostApiIndex( hostApiType );
|
||||
if( hostApiIndex >= 0 )
|
||||
{
|
||||
HostApiInfo info = PortAudio.getHostApiInfo( hostApiIndex );
|
||||
System.out.println( "Checking Host API: " + info.name );
|
||||
for( int apiDeviceIndex = 0; apiDeviceIndex < info.deviceCount; apiDeviceIndex++ )
|
||||
{
|
||||
int deviceIndex = PortAudio
|
||||
.hostApiDeviceIndexToDeviceIndex( hostApiIndex,
|
||||
apiDeviceIndex );
|
||||
DeviceInfo deviceInfo = PortAudio
|
||||
.getDeviceInfo( deviceIndex );
|
||||
assertEquals( "host api must match up", hostApiIndex,
|
||||
deviceInfo.hostApi );
|
||||
}
|
||||
validApiCount++;
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals( "host api counts", PortAudio.getHostApiCount(),
|
||||
validApiCount );
|
||||
}
|
||||
|
||||
public void testListHostApis()
|
||||
{
|
||||
PortAudio.initialize();
|
||||
int count = PortAudio.getHostApiCount();
|
||||
assertTrue( "getHostApiCount", (count > 0) );
|
||||
for( int i = 0; i < count; i++ )
|
||||
{
|
||||
HostApiInfo info = PortAudio.getHostApiInfo( i );
|
||||
System.out.println( "------------------ #" + i );
|
||||
System.out.println( " version = " + info.version );
|
||||
System.out.println( " name = " + info.name );
|
||||
System.out.println( " type = " + info.type );
|
||||
System.out.println( " deviceCount = " + info.deviceCount );
|
||||
System.out.println( " defaultInputDevice = "
|
||||
+ info.defaultInputDevice );
|
||||
System.out.println( " defaultOutputDevice = "
|
||||
+ info.defaultOutputDevice );
|
||||
assertTrue( "some devices", info.deviceCount > 0 );
|
||||
}
|
||||
|
||||
System.out.println( "------\ndefaultHostApi = "
|
||||
+ PortAudio.getDefaultHostApi() );
|
||||
PortAudio.terminate();
|
||||
}
|
||||
|
||||
public void testCheckFormat()
|
||||
{
|
||||
PortAudio.initialize();
|
||||
StreamParameters streamParameters = new StreamParameters();
|
||||
streamParameters.device = PortAudio.getDefaultOutputDevice();
|
||||
int result = PortAudio
|
||||
.isFormatSupported( null, streamParameters, 44100 );
|
||||
System.out.println( "isFormatSupported returns " + result );
|
||||
assertEquals( "default output format", 0, result );
|
||||
// Try crazy channelCount
|
||||
streamParameters.channelCount = 8765;
|
||||
result = PortAudio.isFormatSupported( null, streamParameters, 44100 );
|
||||
System.out.println( "crazy isFormatSupported returns " + result );
|
||||
assertTrue( "default output format", (result < 0) );
|
||||
PortAudio.terminate();
|
||||
}
|
||||
|
||||
static class SineOscillator
|
||||
{
|
||||
double phase = 0.0;
|
||||
double phaseIncrement = 0.01;
|
||||
|
||||
SineOscillator(double freq, int sampleRate)
|
||||
{
|
||||
phaseIncrement = freq * Math.PI * 2.0 / sampleRate;
|
||||
}
|
||||
|
||||
double next()
|
||||
{
|
||||
double value = Math.sin( phase );
|
||||
phase += phaseIncrement;
|
||||
if( phase > Math.PI )
|
||||
{
|
||||
phase -= Math.PI * 2.0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public void testStreamError()
|
||||
{
|
||||
PortAudio.initialize();
|
||||
StreamParameters streamParameters = new StreamParameters();
|
||||
streamParameters.sampleFormat = PortAudio.FORMAT_FLOAT_32;
|
||||
streamParameters.channelCount = 2;
|
||||
streamParameters.device = PortAudio.getDefaultOutputDevice();
|
||||
int framesPerBuffer = 256;
|
||||
int flags = 0;
|
||||
BlockingStream stream = PortAudio.openStream( null, streamParameters,
|
||||
44100, framesPerBuffer, flags );
|
||||
|
||||
// Try to write data to a stopped stream.
|
||||
Throwable caught = null;
|
||||
try
|
||||
{
|
||||
float[] buffer = new float[framesPerBuffer
|
||||
* streamParameters.channelCount];
|
||||
stream.write( buffer, framesPerBuffer );
|
||||
} catch( Throwable e )
|
||||
{
|
||||
caught = e;
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
assertTrue( "caught no expection", (caught != null) );
|
||||
assertTrue( "exception should say stream is stopped", caught
|
||||
.getMessage().contains( "stopped" ) );
|
||||
|
||||
// Try to write null data.
|
||||
caught = null;
|
||||
try
|
||||
{
|
||||
stream.write( (float[]) null, framesPerBuffer );
|
||||
} catch( Throwable e )
|
||||
{
|
||||
caught = e;
|
||||
e.printStackTrace();
|
||||
}
|
||||
assertTrue( "caught no expection", (caught != null) );
|
||||
assertTrue( "exception should say stream is stopped", caught
|
||||
.getMessage().contains( "null" ) );
|
||||
|
||||
// Try to write short data to a float stream.
|
||||
stream.start();
|
||||
caught = null;
|
||||
try
|
||||
{
|
||||
short[] buffer = new short[framesPerBuffer
|
||||
* streamParameters.channelCount];
|
||||
stream.write( buffer, framesPerBuffer );
|
||||
} catch( Throwable e )
|
||||
{
|
||||
caught = e;
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
assertTrue( "caught no expection", (caught != null) );
|
||||
assertTrue( "exception should say tried to", caught.getMessage()
|
||||
.contains( "Tried to write short" ) );
|
||||
|
||||
stream.close();
|
||||
|
||||
PortAudio.terminate();
|
||||
}
|
||||
|
||||
public void checkBlockingWriteFloat( int deviceId, double sampleRate )
|
||||
{
|
||||
StreamParameters streamParameters = new StreamParameters();
|
||||
streamParameters.channelCount = 2;
|
||||
streamParameters.device = deviceId;
|
||||
streamParameters.suggestedLatency = PortAudio
|
||||
.getDeviceInfo( streamParameters.device ).defaultLowOutputLatency;
|
||||
System.out.println( "suggestedLatency = "
|
||||
+ streamParameters.suggestedLatency );
|
||||
|
||||
int framesPerBuffer = 256;
|
||||
int flags = 0;
|
||||
BlockingStream stream = PortAudio.openStream( null, streamParameters,
|
||||
(int) sampleRate, framesPerBuffer, flags );
|
||||
assertTrue( "got default stream", stream != null );
|
||||
|
||||
assertEquals( "stream isStopped", true, stream.isStopped() );
|
||||
assertEquals( "stream isActive", false, stream.isActive() );
|
||||
|
||||
int numFrames = 80000;
|
||||
double expected = ((double)numFrames) / sampleRate;
|
||||
stream.start();
|
||||
long startTime = System.currentTimeMillis();
|
||||
double startStreamTime = stream.getTime();
|
||||
assertEquals( "stream isStopped", false, stream.isStopped() );
|
||||
assertEquals( "stream isActive", true, stream.isActive() );
|
||||
|
||||
writeSineData( stream, framesPerBuffer, numFrames, (int) sampleRate );
|
||||
|
||||
StreamInfo streamInfo = stream.getInfo();
|
||||
System.out.println( "inputLatency of a stream = "+ streamInfo.inputLatency );
|
||||
System.out.println( "outputLatency of a stream = "+streamInfo.outputLatency );
|
||||
System.out.println( "sampleRate of a stream = "+ streamInfo.sampleRate );
|
||||
|
||||
assertEquals( "inputLatency of a stream ", 0.0, streamInfo.inputLatency, 0.000001 );
|
||||
assertTrue( "outputLatency of a stream ",(streamInfo.outputLatency > 0) );
|
||||
assertEquals( "sampleRate of a stream ", sampleRate, streamInfo.sampleRate, 3 );
|
||||
|
||||
double endStreamTime = stream.getTime();
|
||||
stream.stop();
|
||||
long stopTime = System.currentTimeMillis();
|
||||
|
||||
System.out.println( "startStreamTime = " + startStreamTime );
|
||||
System.out.println( "endStreamTime = " + endStreamTime );
|
||||
double elapsedStreamTime = endStreamTime - startStreamTime;
|
||||
System.out.println( "elapsedStreamTime = " + elapsedStreamTime );
|
||||
assertTrue( "elapsedStreamTime: " + elapsedStreamTime,
|
||||
(elapsedStreamTime > 0.0) );
|
||||
assertEquals( "elapsedStreamTime: ", expected, elapsedStreamTime, 0.10 );
|
||||
|
||||
assertEquals( "stream isStopped", true, stream.isStopped() );
|
||||
assertEquals( "stream isActive", false, stream.isActive() );
|
||||
stream.close();
|
||||
|
||||
double elapsed = (stopTime - startTime) / 1000.0;
|
||||
assertEquals( "elapsed time to play", expected, elapsed, 0.20 );
|
||||
}
|
||||
|
||||
public void testBlockingWriteFloat()
|
||||
{
|
||||
PortAudio.initialize();
|
||||
checkBlockingWriteFloat( PortAudio.getDefaultOutputDevice(), 44100 );
|
||||
PortAudio.terminate();
|
||||
}
|
||||
|
||||
public void ZtestWriteEachHostAPI()
|
||||
{
|
||||
PortAudio.initialize();
|
||||
for( int hostApiIndex = 0; hostApiIndex < PortAudio.getHostApiCount(); hostApiIndex++ )
|
||||
{
|
||||
HostApiInfo hostInfo = PortAudio.getHostApiInfo( hostApiIndex );
|
||||
System.out.println( "-------------\nWriting using Host API: " + hostInfo.name );
|
||||
int deviceId = hostInfo.defaultOutputDevice;
|
||||
System.out.println( " Device ID =" + deviceId );
|
||||
DeviceInfo deviceInfo = PortAudio.getDeviceInfo( deviceId );
|
||||
System.out.println( " sampleRate =" + deviceInfo.defaultSampleRate );
|
||||
checkBlockingWriteFloat( deviceId,
|
||||
(int) deviceInfo.defaultSampleRate );
|
||||
System.out.println( "Finished with " + hostInfo.name );
|
||||
}
|
||||
PortAudio.terminate();
|
||||
}
|
||||
|
||||
private void writeSineData( BlockingStream stream, int framesPerBuffer,
|
||||
int numFrames, int sampleRate )
|
||||
{
|
||||
float[] buffer = new float[framesPerBuffer * 2];
|
||||
SineOscillator osc1 = new SineOscillator( 200.0, sampleRate );
|
||||
SineOscillator osc2 = new SineOscillator( 300.0, sampleRate );
|
||||
int framesLeft = numFrames;
|
||||
while( framesLeft > 0 )
|
||||
{
|
||||
int index = 0;
|
||||
int framesToWrite = (framesLeft > framesPerBuffer) ? framesPerBuffer
|
||||
: framesLeft;
|
||||
for( int j = 0; j < framesToWrite; j++ )
|
||||
{
|
||||
buffer[index++] = (float) osc1.next();
|
||||
buffer[index++] = (float) osc2.next();
|
||||
}
|
||||
stream.write( buffer, framesToWrite );
|
||||
framesLeft -= framesToWrite;
|
||||
}
|
||||
}
|
||||
|
||||
private void writeSineDataShort( BlockingStream stream,
|
||||
int framesPerBuffer, int numFrames )
|
||||
{
|
||||
short[] buffer = new short[framesPerBuffer * 2];
|
||||
SineOscillator osc1 = new SineOscillator( 200.0, 44100 );
|
||||
SineOscillator osc2 = new SineOscillator( 300.0, 44100 );
|
||||
int framesLeft = numFrames;
|
||||
while( framesLeft > 0 )
|
||||
{
|
||||
int index = 0;
|
||||
int framesToWrite = (framesLeft > framesPerBuffer) ? framesPerBuffer
|
||||
: framesLeft;
|
||||
for( int j = 0; j < framesToWrite; j++ )
|
||||
{
|
||||
buffer[index++] = (short) (osc1.next() * 32767);
|
||||
buffer[index++] = (short) (osc2.next() * 32767);
|
||||
}
|
||||
stream.write( buffer, framesToWrite );
|
||||
framesLeft -= framesToWrite;
|
||||
}
|
||||
}
|
||||
|
||||
public void testBlockingWriteShort()
|
||||
{
|
||||
PortAudio.initialize();
|
||||
|
||||
StreamParameters streamParameters = new StreamParameters();
|
||||
streamParameters.sampleFormat = PortAudio.FORMAT_INT_16;
|
||||
streamParameters.channelCount = 2;
|
||||
streamParameters.device = PortAudio.getDefaultOutputDevice();
|
||||
streamParameters.suggestedLatency = PortAudio
|
||||
.getDeviceInfo( streamParameters.device ).defaultLowOutputLatency;
|
||||
System.out.println( "suggestedLatency = "
|
||||
+ streamParameters.suggestedLatency );
|
||||
|
||||
int framesPerBuffer = 256;
|
||||
int flags = 0;
|
||||
BlockingStream stream = PortAudio.openStream( null, streamParameters,
|
||||
44100, framesPerBuffer, flags );
|
||||
assertTrue( "got default stream", stream != null );
|
||||
|
||||
int numFrames = 80000;
|
||||
stream.start();
|
||||
long startTime = System.currentTimeMillis();
|
||||
writeSineDataShort( stream, framesPerBuffer, numFrames );
|
||||
stream.stop();
|
||||
long stopTime = System.currentTimeMillis();
|
||||
stream.close();
|
||||
|
||||
double elapsed = (stopTime - startTime) / 1000.0;
|
||||
double expected = numFrames / 44100.0;
|
||||
assertEquals( "elapsed time to play", expected, elapsed, 0.20 );
|
||||
PortAudio.terminate();
|
||||
}
|
||||
|
||||
public void testRecordPlayFloat() throws InterruptedException
|
||||
{
|
||||
checkRecordPlay( PortAudio.FORMAT_FLOAT_32 );
|
||||
}
|
||||
|
||||
public void testRecordPlayShort() throws InterruptedException
|
||||
{
|
||||
checkRecordPlay( PortAudio.FORMAT_INT_16 );
|
||||
}
|
||||
|
||||
public void checkRecordPlay( int sampleFormat ) throws InterruptedException
|
||||
{
|
||||
int framesPerBuffer = 256;
|
||||
int flags = 0;
|
||||
int sampleRate = 44100;
|
||||
int numFrames = sampleRate * 3;
|
||||
float[] floatBuffer = null;
|
||||
short[] shortBuffer = null;
|
||||
|
||||
PortAudio.initialize();
|
||||
StreamParameters inParameters = new StreamParameters();
|
||||
inParameters.sampleFormat = sampleFormat;
|
||||
inParameters.device = PortAudio.getDefaultInputDevice();
|
||||
|
||||
DeviceInfo info = PortAudio.getDeviceInfo( inParameters.device );
|
||||
inParameters.channelCount = (info.maxInputChannels > 2) ? 2
|
||||
: info.maxInputChannels;
|
||||
System.out.println( "channelCount = " + inParameters.channelCount );
|
||||
inParameters.suggestedLatency = PortAudio
|
||||
.getDeviceInfo( inParameters.device ).defaultLowInputLatency;
|
||||
|
||||
if( sampleFormat == PortAudio.FORMAT_FLOAT_32 )
|
||||
{
|
||||
floatBuffer = new float[numFrames * inParameters.channelCount];
|
||||
}
|
||||
else if( sampleFormat == PortAudio.FORMAT_INT_16 )
|
||||
{
|
||||
shortBuffer = new short[numFrames * inParameters.channelCount];
|
||||
}
|
||||
// Record a few seconds of audio.
|
||||
BlockingStream inStream = PortAudio.openStream( inParameters, null,
|
||||
sampleRate, framesPerBuffer, flags );
|
||||
|
||||
System.out.println( "RECORDING - say something like testing 1,2,3..." );
|
||||
inStream.start();
|
||||
|
||||
if( sampleFormat == PortAudio.FORMAT_FLOAT_32 )
|
||||
{
|
||||
inStream.read( floatBuffer, numFrames );
|
||||
}
|
||||
else if( sampleFormat == PortAudio.FORMAT_INT_16 )
|
||||
{
|
||||
inStream.read( shortBuffer, numFrames );
|
||||
}
|
||||
Thread.sleep( 100 );
|
||||
int availableToRead = inStream.getReadAvailable();
|
||||
System.out.println( "availableToRead = " + availableToRead );
|
||||
assertTrue( "getReadAvailable ", availableToRead > 0 );
|
||||
|
||||
inStream.stop();
|
||||
inStream.close();
|
||||
System.out.println( "Finished recording. Begin Playback." );
|
||||
|
||||
// Play back what we recorded.
|
||||
StreamParameters outParameters = new StreamParameters();
|
||||
outParameters.sampleFormat = sampleFormat;
|
||||
outParameters.channelCount = inParameters.channelCount;
|
||||
outParameters.device = PortAudio.getDefaultOutputDevice();
|
||||
outParameters.suggestedLatency = PortAudio
|
||||
.getDeviceInfo( outParameters.device ).defaultLowOutputLatency;
|
||||
|
||||
BlockingStream outStream = PortAudio.openStream( null, outParameters,
|
||||
sampleRate, framesPerBuffer, flags );
|
||||
assertTrue( "got default stream", outStream != null );
|
||||
|
||||
assertEquals( "inStream isActive", false, inStream.isActive() );
|
||||
|
||||
outStream.start();
|
||||
Thread.sleep( 100 );
|
||||
int availableToWrite = outStream.getWriteAvailable();
|
||||
System.out.println( "availableToWrite = " + availableToWrite );
|
||||
assertTrue( "getWriteAvailable ", availableToWrite > 0 );
|
||||
|
||||
System.out.println( "inStream = " + inStream );
|
||||
System.out.println( "outStream = " + outStream );
|
||||
assertEquals( "inStream isActive", false, inStream.isActive() );
|
||||
assertEquals( "outStream isActive", true, outStream.isActive() );
|
||||
if( sampleFormat == PortAudio.FORMAT_FLOAT_32 )
|
||||
{
|
||||
outStream.write( floatBuffer, numFrames );
|
||||
}
|
||||
else if( sampleFormat == PortAudio.FORMAT_INT_16 )
|
||||
{
|
||||
outStream.write( shortBuffer, numFrames );
|
||||
}
|
||||
outStream.stop();
|
||||
|
||||
outStream.close();
|
||||
PortAudio.terminate();
|
||||
}
|
||||
}
|
||||
197
bindings/java/jportaudio/src/com/portaudio/BlockingStream.java
Normal file
197
bindings/java/jportaudio/src/com/portaudio/BlockingStream.java
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
/*
|
||||
* Portable Audio I/O Library
|
||||
* Java Binding for PortAudio
|
||||
*
|
||||
* Based on the Open Source API proposed by Ross Bencina
|
||||
* Copyright (c) 2008 Ross Bencina
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
||||
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* the PortAudio community also makes the following non-binding requests:
|
||||
*
|
||||
* Any person wishing to distribute modifications to the Software is
|
||||
* requested to send the modifications to the original developer so that
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* license above.
|
||||
*/
|
||||
|
||||
package com.portaudio;
|
||||
|
||||
/**
|
||||
* Represents a stream for blocking read/write I/O.
|
||||
*
|
||||
* This Java object contains the pointer to a PortAudio stream stored as a long.
|
||||
* It is passed to PortAudio when calling stream related functions.
|
||||
*
|
||||
* To create one of these, call PortAudio.openStream().
|
||||
*
|
||||
* @author Phil Burk
|
||||
*
|
||||
*/
|
||||
public class BlockingStream
|
||||
{
|
||||
// nativeStream is only accessed by the native code. It contains a pointer
|
||||
// to a PaStream.
|
||||
private long nativeStream;
|
||||
private int inputFormat = -1;
|
||||
private int outputFormat = -1;
|
||||
|
||||
protected BlockingStream()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return number of frames that can be read without blocking.
|
||||
*/
|
||||
public native int getReadAvailable();
|
||||
|
||||
/**
|
||||
* @return number of frames that can be written without blocking.
|
||||
*/
|
||||
public native int getWriteAvailable();
|
||||
|
||||
private native void readFloats( float[] buffer, int numFrames );
|
||||
|
||||
private native void writeFloats( float[] buffer, int numFrames );
|
||||
|
||||
/**
|
||||
* Read 32-bit floating point data from the stream into the array.
|
||||
*
|
||||
* @param buffer
|
||||
* @param numFrames
|
||||
* number of frames to read
|
||||
*/
|
||||
public void read( float[] buffer, int numFrames )
|
||||
{
|
||||
if( inputFormat != PortAudio.FORMAT_FLOAT_32 )
|
||||
{
|
||||
throw new RuntimeException(
|
||||
"Tried to read float samples from a non float stream." );
|
||||
}
|
||||
readFloats( buffer, numFrames );
|
||||
}
|
||||
|
||||
/**
|
||||
* Write 32-bit floating point data to the stream from the array. The data
|
||||
* should be in the range -1.0 to +1.0.
|
||||
*
|
||||
* @param buffer
|
||||
* @param numFrames
|
||||
* number of frames to write
|
||||
*/
|
||||
public void write( float[] buffer, int numFrames )
|
||||
{
|
||||
if( outputFormat != PortAudio.FORMAT_FLOAT_32 )
|
||||
{
|
||||
throw new RuntimeException(
|
||||
"Tried to write float samples to a non float stream." );
|
||||
}
|
||||
writeFloats( buffer, numFrames );
|
||||
}
|
||||
|
||||
private native void readShorts( short[] buffer, int numFrames );
|
||||
|
||||
private native void writeShorts( short[] buffer, int numFrames );
|
||||
|
||||
/**
|
||||
* Read 16-bit integer data to the stream from the array.
|
||||
*
|
||||
* @param buffer
|
||||
* @param numFrames
|
||||
* number of frames to write
|
||||
*/
|
||||
public void read( short[] buffer, int numFrames )
|
||||
{
|
||||
if( inputFormat != PortAudio.FORMAT_INT_16 )
|
||||
{
|
||||
throw new RuntimeException(
|
||||
"Tried to read short samples from a non short stream." );
|
||||
}
|
||||
readShorts( buffer, numFrames );
|
||||
}
|
||||
|
||||
/**
|
||||
* Write 16-bit integer data to the stream from the array.
|
||||
*
|
||||
* @param buffer
|
||||
* @param numFrames
|
||||
* number of frames to write
|
||||
*/
|
||||
public void write( short[] buffer, int numFrames )
|
||||
{
|
||||
if( outputFormat != PortAudio.FORMAT_INT_16 )
|
||||
{
|
||||
throw new RuntimeException(
|
||||
"Tried to write short samples from a non short stream." );
|
||||
}
|
||||
writeShorts( buffer, numFrames );
|
||||
}
|
||||
|
||||
/**
|
||||
* Atart audio I/O.
|
||||
*/
|
||||
public native void start();
|
||||
|
||||
/**
|
||||
* Wait for the stream to play all of the data that has been written then
|
||||
* stop.
|
||||
*/
|
||||
public native void stop();
|
||||
|
||||
/**
|
||||
* Stop immediately and lose any data that was written but not played.
|
||||
*/
|
||||
public native void abort();
|
||||
|
||||
/**
|
||||
* Close the stream and zero out the pointer. Do not reference the stream
|
||||
* after this.
|
||||
*/
|
||||
public native void close();
|
||||
|
||||
public native boolean isStopped();
|
||||
|
||||
public native boolean isActive();
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "BlockingStream: streamPtr = " + Long.toHexString( nativeStream )
|
||||
+ ", inFormat = " + inputFormat + ", outFormat = "
|
||||
+ outputFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get audio time related to this stream. Note that it may not start at 0.0.
|
||||
*/
|
||||
public native double getTime();
|
||||
|
||||
private native void getInfo( StreamInfo streamInfo );
|
||||
|
||||
public StreamInfo getInfo()
|
||||
{
|
||||
StreamInfo streamInfo = new StreamInfo();
|
||||
getInfo( streamInfo );
|
||||
return streamInfo;
|
||||
}
|
||||
}
|
||||
58
bindings/java/jportaudio/src/com/portaudio/DeviceInfo.java
Normal file
58
bindings/java/jportaudio/src/com/portaudio/DeviceInfo.java
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Portable Audio I/O Library
|
||||
* Java Binding for PortAudio
|
||||
*
|
||||
* Based on the Open Source API proposed by Ross Bencina
|
||||
* Copyright (c) 2008 Ross Bencina
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
||||
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* the PortAudio community also makes the following non-binding requests:
|
||||
*
|
||||
* Any person wishing to distribute modifications to the Software is
|
||||
* requested to send the modifications to the original developer so that
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* license above.
|
||||
*/
|
||||
|
||||
package com.portaudio;
|
||||
|
||||
/**
|
||||
* Equivalent to PaDeviceInfo
|
||||
* @author Phil Burk
|
||||
*
|
||||
*/
|
||||
public class DeviceInfo
|
||||
{
|
||||
public int version;
|
||||
public String name;
|
||||
public int hostApi;
|
||||
public int maxInputChannels;
|
||||
public int maxOutputChannels;
|
||||
public double defaultLowInputLatency;
|
||||
public double defaultHighInputLatency;
|
||||
public double defaultLowOutputLatency;
|
||||
public double defaultHighOutputLatency;
|
||||
public double defaultSampleRate;
|
||||
}
|
||||
54
bindings/java/jportaudio/src/com/portaudio/HostApiInfo.java
Normal file
54
bindings/java/jportaudio/src/com/portaudio/HostApiInfo.java
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Portable Audio I/O Library
|
||||
* Java Binding for PortAudio
|
||||
*
|
||||
* Based on the Open Source API proposed by Ross Bencina
|
||||
* Copyright (c) 2008 Ross Bencina
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
||||
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* the PortAudio community also makes the following non-binding requests:
|
||||
*
|
||||
* Any person wishing to distribute modifications to the Software is
|
||||
* requested to send the modifications to the original developer so that
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* license above.
|
||||
*/
|
||||
|
||||
package com.portaudio;
|
||||
|
||||
/**
|
||||
* Equivalent to PaHostApiInfo
|
||||
* @author Phil Burk
|
||||
*
|
||||
*/
|
||||
public class HostApiInfo
|
||||
{
|
||||
public int version;
|
||||
public int type;
|
||||
public String name;
|
||||
public int deviceCount;
|
||||
public int defaultInputDevice;
|
||||
public int defaultOutputDevice;
|
||||
}
|
||||
212
bindings/java/jportaudio/src/com/portaudio/PortAudio.java
Normal file
212
bindings/java/jportaudio/src/com/portaudio/PortAudio.java
Normal file
|
|
@ -0,0 +1,212 @@
|
|||
/*
|
||||
* Portable Audio I/O Library
|
||||
* Java Binding for PortAudio
|
||||
*
|
||||
* Based on the Open Source API proposed by Ross Bencina
|
||||
* Copyright (c) 2008 Ross Bencina
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
||||
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* the PortAudio community also makes the following non-binding requests:
|
||||
*
|
||||
* Any person wishing to distribute modifications to the Software is
|
||||
* requested to send the modifications to the original developer so that
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* license above.
|
||||
*/
|
||||
|
||||
package com.portaudio;
|
||||
|
||||
/**
|
||||
* Java methods that call PortAudio via JNI.
|
||||
* This is a portable audio I/O library that can be used as an alternative to JavaSound.
|
||||
*
|
||||
* Please see the PortAudio documentation for a full explanation.
|
||||
*
|
||||
* http://portaudio.com/docs/
|
||||
* http://portaudio.com/docs/v19-doxydocs/portaudio_8h.html
|
||||
*
|
||||
* This Java binding does not support audio callbacks because an audio callback should never block.
|
||||
* Calling into a Java virtual machine might block for garbage collection or synchronization.
|
||||
* So only the blocking read/write mode is supported.
|
||||
*
|
||||
* @author Phil Burk
|
||||
*
|
||||
*/
|
||||
public class PortAudio
|
||||
{
|
||||
public final static int FLAG_CLIP_OFF = (1 << 0);
|
||||
public final static int FLAG_DITHER_OFF = (1 << 1);
|
||||
|
||||
/** Sample Formats */
|
||||
public final static int FORMAT_FLOAT_32 = (1 << 0);
|
||||
public final static int FORMAT_INT_32 = (1 << 1); // not supported
|
||||
public final static int FORMAT_INT_24 = (1 << 2); // not supported
|
||||
public final static int FORMAT_INT_16 = (1 << 3);
|
||||
public final static int FORMAT_INT_8 = (1 << 4); // not supported
|
||||
public final static int FORMAT_UINT_8 = (1 << 5); // not supported
|
||||
|
||||
/** These HOST_API_TYPES will not change in the future. */
|
||||
public final static int HOST_API_TYPE_DEV = 0;
|
||||
public final static int HOST_API_TYPE_DIRECTSOUND = 1;
|
||||
public final static int HOST_API_TYPE_MME = 2;
|
||||
public final static int HOST_API_TYPE_ASIO = 3;
|
||||
/** Apple Sound Manager. Obsolete. */
|
||||
public final static int HOST_API_TYPE_SOUNDMANAGER = 4;
|
||||
public final static int HOST_API_TYPE_COREAUDIO = 5;
|
||||
public final static int HOST_API_TYPE_OSS = 7;
|
||||
public final static int HOST_API_TYPE_ALSA = 8;
|
||||
public final static int HOST_API_TYPE_AL = 9;
|
||||
public final static int HOST_API_TYPE_BEOS = 10;
|
||||
public final static int HOST_API_TYPE_WDMKS = 11;
|
||||
public final static int HOST_API_TYPE_JACK = 12;
|
||||
public final static int HOST_API_TYPE_WASAPI = 13;
|
||||
public final static int HOST_API_TYPE_AUDIOSCIENCE = 14;
|
||||
public final static int HOST_API_TYPE_COUNT = 15;
|
||||
|
||||
static
|
||||
{
|
||||
if( System.getProperty( "os.arch" ).contains( "64" ) )
|
||||
{
|
||||
System.loadLibrary( "jportaudio_x64" );
|
||||
}
|
||||
else
|
||||
{
|
||||
System.loadLibrary( "jportaudio_x86" );
|
||||
}
|
||||
System.out.println("---- JPortAudio version " + getVersion() + ", " + getVersionText());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the release number of the currently running PortAudio build, eg 1900.
|
||||
*/
|
||||
public native static int getVersion();
|
||||
|
||||
/**
|
||||
* @return a textual description of the current PortAudio build, eg "PortAudio V19-devel 13 October 2002".
|
||||
*/
|
||||
public native static String getVersionText();
|
||||
|
||||
|
||||
/**
|
||||
* Library initialization function - call this before using PortAudio. This function initializes internal data structures and prepares underlying host APIs for use. With the exception of getVersion(), getVersionText(), and getErrorText(), this function MUST be called before using any other PortAudio API functions.
|
||||
*/
|
||||
public native static void initialize();
|
||||
/**
|
||||
* Library termination function - call this when finished using PortAudio. This function deallocates all resources allocated by PortAudio since it was initialized by a call to initialize(). In cases where Pa_Initialise() has been called multiple times, each call must be matched with a corresponding call to terminate(). The final matching call to terminate() will automatically close any PortAudio streams that are still open.
|
||||
*/
|
||||
public native static void terminate();
|
||||
|
||||
/**
|
||||
* @return the number of available devices. The number of available devices may be zero.
|
||||
*/
|
||||
public native static int getDeviceCount();
|
||||
|
||||
private native static void getDeviceInfo( int index, DeviceInfo deviceInfo );
|
||||
|
||||
/**
|
||||
* @param index A valid device index in the range 0 to (getDeviceCount()-1)
|
||||
* @return An DeviceInfo structure.
|
||||
* @throws RuntimeException if the device parameter is out of range.
|
||||
*/
|
||||
public static DeviceInfo getDeviceInfo( int index )
|
||||
{
|
||||
DeviceInfo deviceInfo = new DeviceInfo();
|
||||
getDeviceInfo( index, deviceInfo );
|
||||
return deviceInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of available host APIs.
|
||||
*/
|
||||
public native static int getHostApiCount();
|
||||
|
||||
private native static void getHostApiInfo( int index, HostApiInfo hostApiInfo );
|
||||
|
||||
/**
|
||||
* @param index
|
||||
* @return information about the Host API
|
||||
*/
|
||||
public static HostApiInfo getHostApiInfo( int index )
|
||||
{
|
||||
HostApiInfo hostApiInfo = new HostApiInfo();
|
||||
getHostApiInfo( index, hostApiInfo );
|
||||
return hostApiInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param hostApiType A unique host API identifier, for example HOST_API_TYPE_COREAUDIO.
|
||||
* @return a runtime host API index
|
||||
*/
|
||||
public native static int hostApiTypeIdToHostApiIndex( int hostApiType );
|
||||
|
||||
/**
|
||||
* @param hostApiIndex A valid host API index ranging from 0 to (getHostApiCount()-1)
|
||||
* @param apiDeviceIndex A valid per-host device index in the range 0 to (getHostApiInfo(hostApi).deviceCount-1)
|
||||
* @return standard PortAudio device index
|
||||
*/
|
||||
public native static int hostApiDeviceIndexToDeviceIndex( int hostApiIndex,
|
||||
int apiDeviceIndex );
|
||||
|
||||
public native static int getDefaultInputDevice();
|
||||
public native static int getDefaultOutputDevice();
|
||||
public native static int getDefaultHostApi();
|
||||
|
||||
/**
|
||||
* @param inputStreamParameters input description, may be null
|
||||
* @param outputStreamParameters output description, may be null
|
||||
* @param sampleRate typically 44100 or 48000, or maybe 22050, 16000, 8000, 96000
|
||||
* @return 0 if supported or a negative error
|
||||
*/
|
||||
public native static int isFormatSupported(
|
||||
StreamParameters inputStreamParameters,
|
||||
StreamParameters outputStreamParameters, int sampleRate );
|
||||
|
||||
private native static void openStream( BlockingStream blockingStream,
|
||||
StreamParameters inputStreamParameters,
|
||||
StreamParameters outputStreamParameters, int sampleRate,
|
||||
int framesPerBuffer, int flags );
|
||||
/**
|
||||
*
|
||||
* @param inputStreamParameters input description, may be null
|
||||
* @param outputStreamParameters output description, may be null
|
||||
* @param sampleRate typically 44100 or 48000, or maybe 22050, 16000, 8000, 96000
|
||||
* @param framesPerBuffer
|
||||
* @param flags
|
||||
* @return
|
||||
*/
|
||||
public static BlockingStream openStream(
|
||||
StreamParameters inputStreamParameters,
|
||||
StreamParameters outputStreamParameters, int sampleRate, int framesPerBuffer,
|
||||
int flags )
|
||||
{
|
||||
BlockingStream blockingStream = new BlockingStream();
|
||||
openStream( blockingStream, inputStreamParameters,
|
||||
outputStreamParameters, sampleRate, framesPerBuffer,
|
||||
flags);
|
||||
return blockingStream;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
52
bindings/java/jportaudio/src/com/portaudio/StreamInfo.java
Normal file
52
bindings/java/jportaudio/src/com/portaudio/StreamInfo.java
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Portable Audio I/O Library
|
||||
* Java Binding for PortAudio
|
||||
*
|
||||
* Based on the Open Source API proposed by Ross Bencina
|
||||
* Copyright (c) 2008 Ross Bencina
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
||||
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* the PortAudio community also makes the following non-binding requests:
|
||||
*
|
||||
* Any person wishing to distribute modifications to the Software is
|
||||
* requested to send the modifications to the original developer so that
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* license above.
|
||||
*/
|
||||
|
||||
package com.portaudio;
|
||||
|
||||
/**
|
||||
* Equivalent to PaStreamInfo
|
||||
* @author Phil Burk
|
||||
*
|
||||
*/
|
||||
public class StreamInfo
|
||||
{
|
||||
public int structVersion;
|
||||
public double outputLatency;
|
||||
public double inputLatency;
|
||||
public double sampleRate;
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Portable Audio I/O Library
|
||||
* Java Binding for PortAudio
|
||||
*
|
||||
* Based on the Open Source API proposed by Ross Bencina
|
||||
* Copyright (c) 2008 Ross Bencina
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
||||
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* the PortAudio community also makes the following non-binding requests:
|
||||
*
|
||||
* Any person wishing to distribute modifications to the Software is
|
||||
* requested to send the modifications to the original developer so that
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* license above.
|
||||
*/
|
||||
|
||||
package com.portaudio;
|
||||
/**
|
||||
* Equivalent to PaStreamParameters
|
||||
* @author Phil Burk
|
||||
*
|
||||
*/
|
||||
public class StreamParameters
|
||||
{
|
||||
public int device = 0;
|
||||
public int channelCount = 2;
|
||||
public int sampleFormat = PortAudio.FORMAT_FLOAT_32;
|
||||
public double suggestedLatency = 0.050;
|
||||
}
|
||||
Loading…
Reference in a new issue