Skip to content

Commit

Permalink
AudioQueueBuffer and processing tap fix (fixes #925).
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueRiverInteractive committed Apr 21, 2015
1 parent 321f5a8 commit 641dbe6
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 61 deletions.
11 changes: 10 additions & 1 deletion cocoatouch/src/main/bro-gen/audiotoolbox.yaml
Expand Up @@ -571,7 +571,7 @@ classes:
ParameterEvent: # DONE ParameterEvent: # DONE
name: AUParameterEvent name: AUParameterEvent
parameterID: parameterID:
type: AUParameterID type: AUParameterType
scope: scope:
type: AUScope type: AUScope


Expand Down Expand Up @@ -785,12 +785,21 @@ functions:
name: '#{g[0]}0' name: '#{g[0]}0'
visibility: protected visibility: protected
parameters: parameters:
inBuffer:
type: '@Pointer long'
inPacketDescs: inPacketDescs:
type: AudioStreamPacketDescription.AudioStreamPacketDescriptionPtr type: AudioStreamPacketDescription.AudioStreamPacketDescriptionPtr
inParamValues: inParamValues:
type: AudioQueueParameterEvent.AudioQueueParameterEventPtr type: AudioQueueParameterEvent.AudioQueueParameterEventPtr
outActualStartTime: outActualStartTime:
type: AudioTimeStamp.AudioTimeStampPtr type: AudioTimeStamp.AudioTimeStampPtr
AudioQueue(FreeBuffer):
class: AudioQueue
name: '#{g[0]}0'
visibility: protected
parameters:
inBuffer:
type: '@Pointer long'
AudioQueue(GetCurrentTime): AudioQueue(GetCurrentTime):
class: AudioQueue class: AudioQueue
name: '#{g[0]}0' name: '#{g[0]}0'
Expand Down
Expand Up @@ -19,7 +19,6 @@
import java.io.*; import java.io.*;
import java.nio.*; import java.nio.*;
import java.util.*; import java.util.*;

import org.robovm.objc.*; import org.robovm.objc.*;
import org.robovm.objc.annotation.*; import org.robovm.objc.annotation.*;
import org.robovm.objc.block.*; import org.robovm.objc.block.*;
Expand Down Expand Up @@ -49,7 +48,7 @@
public interface ParseListener { public interface ParseListener {
void onPropertyParsed(AudioFileStream audioFileStream, AudioFileStreamProperty property, AudioFileStreamMutablePropertyFlags flags); void onPropertyParsed(AudioFileStream audioFileStream, AudioFileStreamProperty property, AudioFileStreamMutablePropertyFlags flags);


void onPacketsParsed(int numberBytes, int numberPackets, BytePtr inputData, AudioStreamPacketDescription.AudioStreamPacketDescriptionPtr packetDescriptions); void onPacketsParsed(int numberBytes, long inputData, AudioStreamPacketDescription[] packetDescriptions);
} }


private static java.util.concurrent.atomic.AtomicLong callbackId = new java.util.concurrent.atomic.AtomicLong(); private static java.util.concurrent.atomic.AtomicLong callbackId = new java.util.concurrent.atomic.AtomicLong();
Expand All @@ -61,7 +60,7 @@ public interface ParseListener {
static { static {
try { try {
cbParseProperty = AudioFileStream.class.getDeclaredMethod("cbParseProperty", Long.TYPE, AudioFileStream.class, AudioFileStreamProperty.class, AudioFileStreamMutablePropertyFlags.class); cbParseProperty = AudioFileStream.class.getDeclaredMethod("cbParseProperty", Long.TYPE, AudioFileStream.class, AudioFileStreamProperty.class, AudioFileStreamMutablePropertyFlags.class);
cbParsePackets = AudioFileStream.class.getDeclaredMethod("cbParsePackets", Long.TYPE, Integer.TYPE, Integer.TYPE, BytePtr.class, AudioStreamPacketDescription.AudioStreamPacketDescriptionPtr.class); cbParsePackets = AudioFileStream.class.getDeclaredMethod("cbParsePackets", Long.TYPE, Integer.TYPE, Integer.TYPE, Long.TYPE, AudioStreamPacketDescription.class);
} catch (Throwable e) { } catch (Throwable e) {
throw new Error(e); throw new Error(e);
} }
Expand All @@ -82,9 +81,9 @@ private static void cbParseProperty(@Pointer long clientData, AudioFileStream au
} }
} }
@Callback @Callback
private static void cbParsePackets(@Pointer long clientData, int numberBytes, int numberPackets, BytePtr inputData, AudioStreamPacketDescription.AudioStreamPacketDescriptionPtr packetDescriptions) { private static void cbParsePackets(@Pointer long clientData, int numberBytes, int numberPackets, @Pointer long inputData, AudioStreamPacketDescription packetDescriptions) {
synchronized (parseListeners) { synchronized (parseListeners) {
parseListeners.get(clientData).onPacketsParsed(numberBytes, numberPackets, inputData, packetDescriptions); parseListeners.get(clientData).onPacketsParsed(numberBytes, inputData, packetDescriptions.toArray(numberPackets));
} }
} }


Expand Down
Expand Up @@ -19,7 +19,6 @@
import java.io.*; import java.io.*;
import java.nio.*; import java.nio.*;
import java.util.*; import java.util.*;

import org.robovm.objc.*; import org.robovm.objc.*;
import org.robovm.objc.annotation.*; import org.robovm.objc.annotation.*;
import org.robovm.objc.block.*; import org.robovm.objc.block.*;
Expand Down Expand Up @@ -48,10 +47,10 @@ public interface PropertyListener {
void onChange(AudioQueue queue, AudioQueueProperty id); void onChange(AudioQueue queue, AudioQueueProperty id);
} }
public interface InputCallback { public interface InputCallback {
void onInput(AudioQueue queue, AudioQueueBuffer buffer, AudioTimeStamp startTime, AudioStreamPacketDescription[] packetDescs); void onInput(AudioQueue queue, long buffer, AudioTimeStamp startTime, AudioStreamPacketDescription[] packetDescs);
} }
public interface OutputCallback { public interface OutputCallback {
void onOutput(AudioQueue queue, AudioQueueBuffer buffer); void onOutput(AudioQueue queue, long buffer);
} }


/*<ptr>*/public static class AudioQueuePtr extends Ptr<AudioQueue, AudioQueuePtr> {}/*</ptr>*/ /*<ptr>*/public static class AudioQueuePtr extends Ptr<AudioQueue, AudioQueuePtr> {}/*</ptr>*/
Expand All @@ -68,8 +67,8 @@ public interface OutputCallback {
static { static {
try { try {
cbPropertyChanged = AudioQueue.class.getDeclaredMethod("cbPropertyChanged", Long.TYPE, AudioQueue.class, AudioQueueProperty.class); cbPropertyChanged = AudioQueue.class.getDeclaredMethod("cbPropertyChanged", Long.TYPE, AudioQueue.class, AudioQueueProperty.class);
cbInput = AudioQueue.class.getDeclaredMethod("cbInput", Long.TYPE, AudioQueue.class, AudioQueueBuffer.class, AudioTimeStamp.class, Integer.TYPE, AudioStreamPacketDescription.class); cbInput = AudioQueue.class.getDeclaredMethod("cbInput", Long.TYPE, AudioQueue.class, Long.TYPE, AudioTimeStamp.class, Integer.TYPE, AudioStreamPacketDescription.class);
cbOutput = AudioQueue.class.getDeclaredMethod("cbOutput", Long.TYPE, AudioQueue.class, AudioQueueBuffer.class); cbOutput = AudioQueue.class.getDeclaredMethod("cbOutput", Long.TYPE, AudioQueue.class, Long.TYPE);
} catch (Throwable e) { } catch (Throwable e) {
throw new Error(e); throw new Error(e);
} }
Expand All @@ -88,13 +87,13 @@ private static void cbPropertyChanged(@Pointer long userData, AudioQueue queue,
} }
} }
@Callback @Callback
private static void cbInput(@Pointer long userData, AudioQueue queue, AudioQueueBuffer buffer, AudioTimeStamp startTime, int numberPacketDescs, AudioStreamPacketDescription packetDescs) { private static void cbInput(@Pointer long userData, AudioQueue queue, @Pointer long buffer, AudioTimeStamp startTime, int numberPacketDescs, AudioStreamPacketDescription packetDescs) {
synchronized (inputCallbacks) { synchronized (inputCallbacks) {
inputCallbacks.get(userData).onInput(queue, buffer, startTime, packetDescs.toArray(numberPacketDescs)); inputCallbacks.get(userData).onInput(queue, buffer, startTime, packetDescs.toArray(numberPacketDescs));
} }
} }
@Callback @Callback
private static void cbOutput(@Pointer long userData, AudioQueue queue, AudioQueueBuffer buffer) { private static void cbOutput(@Pointer long userData, AudioQueue queue, @Pointer long buffer) {
synchronized (outputCallbacks) { synchronized (outputCallbacks) {
outputCallbacks.get(userData).onOutput(queue, buffer); outputCallbacks.get(userData).onOutput(queue, buffer);
} }
Expand Down Expand Up @@ -201,6 +200,13 @@ public AudioQueueBuffer allocateBuffer(int bufferByteSize, int numberPacketDescr
* @since Available in iOS 2.0 and later. * @since Available in iOS 2.0 and later.
*/ */
public void freeBuffer(AudioQueueBuffer buffer) throws OSStatusException { public void freeBuffer(AudioQueueBuffer buffer) throws OSStatusException {
freeBuffer(buffer.getHandle());
}
/**
* @throws OSStatusException
* @since Available in iOS 2.0 and later.
*/
public void freeBuffer(long buffer) throws OSStatusException {
OSStatus status = freeBuffer0(buffer); OSStatus status = freeBuffer0(buffer);
OSStatusException.throwIfNecessary(status); OSStatusException.throwIfNecessary(status);
} }
Expand All @@ -209,6 +215,13 @@ public void freeBuffer(AudioQueueBuffer buffer) throws OSStatusException {
* @since Available in iOS 2.0 and later. * @since Available in iOS 2.0 and later.
*/ */
public void enqueueBuffer(AudioQueueBuffer buffer, AudioStreamPacketDescription[] packetDescs) throws OSStatusException { public void enqueueBuffer(AudioQueueBuffer buffer, AudioStreamPacketDescription[] packetDescs) throws OSStatusException {
enqueueBuffer(buffer.getHandle(), packetDescs);
}
/**
* @throws OSStatusException
* @since Available in iOS 2.0 and later.
*/
public void enqueueBuffer(long buffer, AudioStreamPacketDescription[] packetDescs) throws OSStatusException {
AudioStreamPacketDescription.AudioStreamPacketDescriptionPtr ptr = new AudioStreamPacketDescription.AudioStreamPacketDescriptionPtr(); AudioStreamPacketDescription.AudioStreamPacketDescriptionPtr ptr = new AudioStreamPacketDescription.AudioStreamPacketDescriptionPtr();
ptr.set(packetDescs); ptr.set(packetDescs);
OSStatus status = enqueueBuffer0(buffer, packetDescs.length, ptr); OSStatus status = enqueueBuffer0(buffer, packetDescs.length, ptr);
Expand All @@ -219,6 +232,13 @@ public void enqueueBuffer(AudioQueueBuffer buffer, AudioStreamPacketDescription[
* @since Available in iOS 2.0 and later. * @since Available in iOS 2.0 and later.
*/ */
public AudioTimeStamp enqueueBuffer(AudioQueueBuffer buffer, AudioStreamPacketDescription[] packetDescs, int trimFramesAtStart, int trimFramesAtEnd, AudioQueueParameterEvent[] paramValues, AudioTimeStamp startTime) throws OSStatusException { public AudioTimeStamp enqueueBuffer(AudioQueueBuffer buffer, AudioStreamPacketDescription[] packetDescs, int trimFramesAtStart, int trimFramesAtEnd, AudioQueueParameterEvent[] paramValues, AudioTimeStamp startTime) throws OSStatusException {
return enqueueBuffer(buffer.getHandle(), packetDescs, trimFramesAtStart, trimFramesAtEnd, paramValues, startTime);
}
/**
* @throws OSStatusException
* @since Available in iOS 2.0 and later.
*/
public AudioTimeStamp enqueueBuffer(long buffer, AudioStreamPacketDescription[] packetDescs, int trimFramesAtStart, int trimFramesAtEnd, AudioQueueParameterEvent[] paramValues, AudioTimeStamp startTime) throws OSStatusException {
AudioTimeStamp.AudioTimeStampPtr ptr = new AudioTimeStamp.AudioTimeStampPtr(); AudioTimeStamp.AudioTimeStampPtr ptr = new AudioTimeStamp.AudioTimeStampPtr();


AudioStreamPacketDescription.AudioStreamPacketDescriptionPtr packetDescsPtr = new AudioStreamPacketDescription.AudioStreamPacketDescriptionPtr(); AudioStreamPacketDescription.AudioStreamPacketDescriptionPtr packetDescsPtr = new AudioStreamPacketDescription.AudioStreamPacketDescriptionPtr();
Expand Down Expand Up @@ -511,17 +531,17 @@ public AudioQueueProcessingTap createProcessingTap(AudioQueueProcessingTap.Proce
* @since Available in iOS 2.0 and later. * @since Available in iOS 2.0 and later.
*/ */
@Bridge(symbol="AudioQueueFreeBuffer", optional=true) @Bridge(symbol="AudioQueueFreeBuffer", optional=true)
protected native OSStatus freeBuffer0(AudioQueueBuffer inBuffer); protected native OSStatus freeBuffer0(@Pointer long inBuffer);
/** /**
* @since Available in iOS 2.0 and later. * @since Available in iOS 2.0 and later.
*/ */
@Bridge(symbol="AudioQueueEnqueueBuffer", optional=true) @Bridge(symbol="AudioQueueEnqueueBuffer", optional=true)
protected native OSStatus enqueueBuffer0(AudioQueueBuffer inBuffer, int inNumPacketDescs, AudioStreamPacketDescription.AudioStreamPacketDescriptionPtr inPacketDescs); protected native OSStatus enqueueBuffer0(@Pointer long inBuffer, int inNumPacketDescs, AudioStreamPacketDescription.AudioStreamPacketDescriptionPtr inPacketDescs);
/** /**
* @since Available in iOS 2.0 and later. * @since Available in iOS 2.0 and later.
*/ */
@Bridge(symbol="AudioQueueEnqueueBufferWithParameters", optional=true) @Bridge(symbol="AudioQueueEnqueueBufferWithParameters", optional=true)
protected native OSStatus enqueueBuffer0(AudioQueueBuffer inBuffer, int inNumPacketDescs, AudioStreamPacketDescription.AudioStreamPacketDescriptionPtr inPacketDescs, int inTrimFramesAtStart, int inTrimFramesAtEnd, int inNumParamValues, AudioQueueParameterEvent.AudioQueueParameterEventPtr inParamValues, AudioTimeStamp inStartTime, AudioTimeStamp.AudioTimeStampPtr outActualStartTime); protected native OSStatus enqueueBuffer0(@Pointer long inBuffer, int inNumPacketDescs, AudioStreamPacketDescription.AudioStreamPacketDescriptionPtr inPacketDescs, int inTrimFramesAtStart, int inTrimFramesAtEnd, int inNumParamValues, AudioQueueParameterEvent.AudioQueueParameterEventPtr inParamValues, AudioTimeStamp inStartTime, AudioTimeStamp.AudioTimeStampPtr outActualStartTime);
/** /**
* @since Available in iOS 2.0 and later. * @since Available in iOS 2.0 and later.
*/ */
Expand Down
Expand Up @@ -19,6 +19,7 @@
import java.io.*; import java.io.*;
import java.nio.*; import java.nio.*;
import java.util.*; import java.util.*;

import org.robovm.objc.*; import org.robovm.objc.*;
import org.robovm.objc.annotation.*; import org.robovm.objc.annotation.*;
import org.robovm.objc.block.*; import org.robovm.objc.block.*;
Expand Down Expand Up @@ -52,35 +53,32 @@
public AudioQueueBuffer() {} public AudioQueueBuffer() {}


/*</constructors>*/ /*</constructors>*/
public AudioQueueBuffer(long handle) {
super(handle);
}

/*<properties>*//*</properties>*/ /*<properties>*//*</properties>*/
public AudioQueueBuffer setAudioData(byte[] data) { public AudioQueueBuffer setAudioData(long dataPointer, int length) {
setArrayAudioData(data, data.length); setData0(dataPointer);
setAudioDataByteSize(length);
return this; return this;
} }
public AudioQueueBuffer setAudioData(short[] data) { public AudioQueueBuffer setAudioData(byte[] data) {
setArrayAudioData(data, data.length); setArrayAudioData(data, data.length);
return this; return this;
} }
public AudioQueueBuffer setAudioData(char[] data) { public AudioQueueBuffer setAudioData(short[] data) {
setArrayAudioData(data, data.length); setArrayAudioData(data, data.length);
return this; return this;
} }
public AudioQueueBuffer setAudioData(int[] data) { public AudioQueueBuffer setAudioData(int[] data) {
setArrayAudioData(data, data.length); setArrayAudioData(data, data.length);
return this; return this;
} }
public AudioQueueBuffer setAudioData(long[] data) {
setArrayAudioData(data, data.length);
return this;
}
public AudioQueueBuffer setAudioData(float[] data) { public AudioQueueBuffer setAudioData(float[] data) {
setArrayAudioData(data, data.length); setArrayAudioData(data, data.length);
return this; return this;
} }
public AudioQueueBuffer setAudioData(double[] data) {
setArrayAudioData(data, data.length);
return this;
}
public AudioQueueBuffer setAudioData(Buffer data) { public AudioQueueBuffer setAudioData(Buffer data) {
setAudioDataByteSize(data.capacity()); setAudioDataByteSize(data.capacity());
setData0(BufferMarshalers.BufferMarshaler.toNative(data, 0)); setData0(BufferMarshalers.BufferMarshaler.toNative(data, 0));
Expand All @@ -94,53 +92,43 @@ private AudioQueueBuffer setArrayAudioData(Object array, int length) {


@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T extends Buffer> T getAudioDataAsBuffer(Class<T> bufferType) { public <T extends Buffer> T getAudioDataAsBuffer(Class<T> bufferType) {
VoidPtr ptr = getDataPointer(); long dataPointer = getDataPointer();
if (bufferType == ByteBuffer.class) { if (bufferType == ByteBuffer.class) {
return (T) ptr.as(BytePtr.class).asByteBuffer(getAudioDataByteSize()); return (T) VM.newDirectByteBuffer(dataPointer, getAudioDataByteSize());
} else if (bufferType == CharBuffer.class) {
return (T) ptr.as(CharPtr.class).asCharBuffer(getAudioDataByteSize());
} else if (bufferType == ShortBuffer.class) { } else if (bufferType == ShortBuffer.class) {
return (T) ptr.as(ShortPtr.class).asShortBuffer(getAudioDataByteSize()); return (T) VM.newDirectByteBuffer(dataPointer, getAudioDataByteSize() << 1).order(ByteOrder.nativeOrder()).asShortBuffer();
} else if (bufferType == IntBuffer.class) { } else if (bufferType == IntBuffer.class) {
return (T) ptr.as(IntPtr.class).asIntBuffer(getAudioDataByteSize()); return (T) VM.newDirectByteBuffer(dataPointer, getAudioDataByteSize() << 2).order(ByteOrder.nativeOrder()).asIntBuffer();
} else if (bufferType == LongBuffer.class) {
return (T) ptr.as(LongPtr.class).asLongBuffer(getAudioDataByteSize());
} else if (bufferType == FloatBuffer.class) { } else if (bufferType == FloatBuffer.class) {
return (T) ptr.as(FloatPtr.class).asFloatBuffer(getAudioDataByteSize()); return (T) VM.newDirectByteBuffer(dataPointer, getAudioDataByteSize() << 2).order(ByteOrder.nativeOrder()).asFloatBuffer();
} else if (bufferType == DoubleBuffer.class) {
return (T) ptr.as(DoublePtr.class).asDoubleBuffer(getAudioDataByteSize());
} else { } else {
throw new UnsupportedOperationException("Buffer type not supported: " + bufferType); throw new UnsupportedOperationException("Buffer type not supported: " + bufferType);
} }
} }


public byte[] getAudioDataAsByteArray() { public byte[] getAudioDataAsByteArray() {
BytePtr ptr = getDataPointer().as(BytePtr.class); int length = getAudioDataByteSize();
return ptr.toByteArray(getAudioDataByteSize()); byte[] data = new byte[length];
getAudioDataAsBuffer(ByteBuffer.class).get(data, 0, length);
return data;
} }
public short[] getAudioDataAsShortArray() { public short[] getAudioDataAsShortArray() {
ShortPtr ptr = getDataPointer().as(ShortPtr.class); int length = getAudioDataByteSize();
return ptr.toShortArray(getAudioDataByteSize()); short[] data = new short[length];
} getAudioDataAsBuffer(ShortBuffer.class).get(data, 0, length);
public char[] getAudioDataAsCharArray() { return data;
CharPtr ptr = getDataPointer().as(CharPtr.class);
return ptr.toCharArray(getAudioDataByteSize());
} }
public int[] getAudioDataAsIntArray() { public int[] getAudioDataAsIntArray() {
IntPtr ptr = getDataPointer().as(IntPtr.class); int length = getAudioDataByteSize();
return ptr.toIntArray(getAudioDataByteSize()); int[] data = new int[length];
} getAudioDataAsBuffer(IntBuffer.class).get(data, 0, length);
public long[] getAudioDataAsLongArray() { return data;
LongPtr ptr = getDataPointer().as(LongPtr.class);
return ptr.toLongArray(getAudioDataByteSize());
} }
public float[] getAudioDataAsFloatArray() { public float[] getAudioDataAsFloatArray() {
FloatPtr ptr = getDataPointer().as(FloatPtr.class); int length = getAudioDataByteSize();
return ptr.toFloatArray(getAudioDataByteSize()); float[] data = new float[length];
} getAudioDataAsBuffer(FloatBuffer.class).get(data, 0, length);
public double[] getAudioDataAsDoubleArray() { return data;
DoublePtr ptr = getDataPointer().as(DoublePtr.class);
return ptr.toDoubleArray(getAudioDataByteSize());
} }


public int getPacketDescriptionCount() { public int getPacketDescriptionCount() {
Expand Down Expand Up @@ -186,7 +174,7 @@ public AudioQueueBuffer setPacketDescriptions(AudioStreamPacketDescription[] reg
@StructMember(0) public native int getAudioDataBytesCapacity(); @StructMember(0) public native int getAudioDataBytesCapacity();
@StructMember(4) public native int getPacketDescriptionCapacity(); @StructMember(4) public native int getPacketDescriptionCapacity();


@StructMember(1) protected native VoidPtr getDataPointer(); @StructMember(1) public native @Pointer long getDataPointer();
@StructMember(1) protected native AudioQueueBuffer setData0(@Pointer long audioData); @StructMember(1) protected native AudioQueueBuffer setData0(@Pointer long audioData);
/*<methods>*//*</methods>*/ /*<methods>*//*</methods>*/
} }
Expand Up @@ -56,7 +56,7 @@ public interface ProcessingTapCallback {


static { static {
try { try {
cbProcess = AudioQueueProcessingTap.class.getDeclaredMethod("cbProcess", Long.TYPE, AudioQueueProcessingTap.class, Integer.class, AudioTimeStamp.class, cbProcess = AudioQueueProcessingTap.class.getDeclaredMethod("cbProcess", Long.TYPE, AudioQueueProcessingTap.class, Integer.TYPE, AudioTimeStamp.class,
AudioQueueProcessingTapFlags.class, IntPtr.class, AudioBufferList.class); AudioQueueProcessingTapFlags.class, IntPtr.class, AudioBufferList.class);
} catch (Throwable e) { } catch (Throwable e) {
throw new Error(e); throw new Error(e);
Expand Down

0 comments on commit 641dbe6

Please sign in to comment.