diff --git a/PdCore/pd-core/src/main/java/org/puredata/android/io/PdAudio.java b/PdCore/pd-core/src/main/java/org/puredata/android/io/PdAudio.java index 0b7f8224..5d235c22 100644 --- a/PdCore/pd-core/src/main/java/org/puredata/android/io/PdAudio.java +++ b/PdCore/pd-core/src/main/java/org/puredata/android/io/PdAudio.java @@ -9,6 +9,8 @@ import java.io.IOException; import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; import org.puredata.core.PdBase; @@ -28,6 +30,7 @@ public class PdAudio { private static AudioWrapper audioWrapper = null; private static int inputDeviceId = -1; private static int outputDeviceId = -1; + private static int bufferSizeInFrames = -1; private static final Handler handler = new Handler(Looper.getMainLooper()); private static final Runnable pollRunner = new Runnable() { @Override @@ -58,7 +61,11 @@ public synchronized static void initAudio(int sampleRate, int inChannels, int ou throws IOException { if (isRunning() && !restart) return; stopAudio(); - if (PdBase.openAudio(inChannels, outChannels, sampleRate, null) != 0) { + Map options = new HashMap(); + options.put("inputDeviceId", String.valueOf(inputDeviceId)); + options.put("outputDeviceId", String.valueOf(outputDeviceId)); + options.put("bufferSizeInFrames", String.valueOf(bufferSizeInFrames)); + if (PdBase.openAudio(inChannels, outChannels, sampleRate, options) != 0) { throw new IOException("unable to open Pd audio: " + sampleRate + ", " + inChannels + ", " + outChannels); } if (!PdBase.implementsAudio()) { @@ -80,7 +87,7 @@ protected int process(short[] inBuffer, short[] outBuffer) { } /** - * Set the audio input and output devices Id. Call it before startAudio(). + * Set the audio input and output devices Id. Call it before initAudio(). * * @param inDeviceId id of the audio input device (-1 means the default device) * @param outDeviceId id of the audio output device (-1 means the default device) @@ -90,6 +97,15 @@ public synchronized static void setDevicesId(int inDeviceId, int outDeviceId) { outputDeviceId = outDeviceId; } + /** + * Set the audio buffer size in frames. Call it before initAudio(). + * + * @param frames the buffer size, expressed in frames (-1 means the default buffersize) + */ + public synchronized static void setBufferSizeInFrames(int frames) { + bufferSizeInFrames = frames; + } + /** * Starts the audio components. * @@ -98,8 +114,6 @@ public synchronized static void setDevicesId(int inDeviceId, int outDeviceId) { public synchronized static void startAudio(Context context) { PdBase.computeAudio(true); if (PdBase.implementsAudio()) { - PdBase.setRecordingDeviceId(inputDeviceId); - PdBase.setPlaybackDeviceId(outputDeviceId); handler.post(pollRunner); PdBase.startAudio(); } else { diff --git a/PdCore/pd-core/src/main/jni/libpd b/PdCore/pd-core/src/main/jni/libpd index 3067debb..3fc60ea7 160000 --- a/PdCore/pd-core/src/main/jni/libpd +++ b/PdCore/pd-core/src/main/jni/libpd @@ -1 +1 @@ -Subproject commit 3067debb9dae42c747023bcf99beb4be287da7e6 +Subproject commit 3fc60ea70f5d6f27d0de1c2fa2c8b3a2b5ca82e6