public _AudioConverterEventArgs( uint _NumberDataPackets, AudioBufferList _Data, AudioStreamPacketDescription[] _DataPacketDescription) { NumberDataPackets = _NumberDataPackets; Data = _Data; DataPacketDescription = _DataPacketDescription; }
public static CMSampleBuffer CreateReadyWithPacketDescriptions (CMBlockBuffer dataBuffer, CMFormatDescription formatDescription, int samplesCount, CMTime sampleTimestamp, AudioStreamPacketDescription[] packetDescriptions, out CMSampleBufferError error) { if (dataBuffer == null) throw new ArgumentNullException ("dataBuffer"); if (formatDescription == null) throw new ArgumentNullException ("formatDescription"); if (samplesCount <= 0) throw new ArgumentOutOfRangeException ("samplesCount"); IntPtr buffer; error = CMAudioSampleBufferCreateReadyWithPacketDescriptions (IntPtr.Zero, dataBuffer.handle, formatDescription.handle, samplesCount, sampleTimestamp, packetDescriptions, out buffer); if (error != CMSampleBufferError.None) return null; return new CMSampleBuffer (buffer, true); }
extern static /* OSStatus */ CMSampleBufferError CMAudioSampleBufferCreateReadyWithPacketDescriptions ( /* CFAllocatorRef */ IntPtr allocator, /* CMBlockBufferRef */ IntPtr dataBuffer, /* CMFormatDescriptionRef */ IntPtr formatDescription, /* CMItemCount */ nint numSamples, CMTime sbufPTS, /* AudioStreamPacketDescription* */ AudioStreamPacketDescription[] packetDescriptions, /* CMSampleBufferRef* */ out IntPtr sBufOut);
extern static CMSampleBufferError CMAudioSampleBufferCreateWithPacketDescriptions ( /* CFAllocatorRef */ IntPtr allocator, /* CMBlockBufferRef */ IntPtr dataBuffer, /* Boolean */ bool dataReady, /* CMSampleBufferMakeDataReadyCallback */ IntPtr makeDataReadyCallback, /* void */ IntPtr makeDataReadyRefcon, /* CMFormatDescriptionRef */ IntPtr formatDescription, /* CMItemCount */ nint numSamples, CMTime sbufPTS, /* AudioStreamPacketDescription* */ AudioStreamPacketDescription[] packetDescriptions, /* CMSampleBufferRef* */ out IntPtr sBufOut);
static int complexInputDataProc( IntPtr inAudioConverrter, ref uint ioNumberDataPackets, AudioBufferList ioData, ref AudioStreamPacketDescription[] outDataPacketDescription, //AudioStreamPacketDescription** IntPtr inUserData ) { // getting audiounit instance var handler = GCHandle.FromIntPtr(inUserData); var inst = (_AudioConverter)handler.Target; // evoke event handler with an argument if (inst.EncoderCallback != null) { var args = new _AudioConverterEventArgs( ioNumberDataPackets, ioData, outDataPacketDescription); inst.EncoderCallback(inst, args); } return 0; // noerror }
static extern int AudioConverterFillComplexBuffer( IntPtr inAudioConverter, AudioConverterComplexInputDataProc inInputDataProc, IntPtr inInputDataProcUserData, ref uint ioOutputDataPacketSize, AudioBufferList outOutputData, AudioStreamPacketDescription[] outPacketDescription);
public void FillBuffer(AudioBufferList data, uint numberFrames, AudioStreamPacketDescription[] packetDescs) { uint numPackets = numberFrames; int err = AudioConverterFillComplexBuffer( _audioConverter, complexInputDataProc, GCHandle.ToIntPtr(_handle), ref numPackets, data, packetDescs); if(err != 0 || numPackets == 0) { throw new InvalidOperationException(String.Format("Error code:{0}", err)); } }