Skip to content
Browse files

AudioFile.WritePackets: Add overloads that return the errorcode from …

…the underlying API
  • Loading branch information...
1 parent c7e2250 commit f831e6baf870686eee1b3cf44819d855967257c0 @migueldeicaza migueldeicaza committed
Showing with 36 additions and 0 deletions.
  1. +36 −0 src/AudioToolbox/AudioFile.cs
View
36 src/AudioToolbox/AudioFile.cs
@@ -517,6 +517,42 @@ unsafe public int WritePackets (bool useCache, long startingPacket, AudioStreamP
}
}
+ unsafe public int WritePackets (bool useCache, long inStartingPacket, AudioStreamPacketDescription [] inPacketDescriptions, IntPtr buffer, int count, out int errorCode)
+ {
+ if (inPacketDescriptions == null)
+ throw new ArgumentNullException ("inPacketDescriptions");
+ if (buffer == IntPtr.Zero)
+ throw new ArgumentNullException ("buffer");
+ int nPackets = inPacketDescriptions.Length;
+
+ errorCode = AudioFileWritePackets (handle, useCache, count, inPacketDescriptions, inStartingPacket, ref nPackets, buffer);
+ if (errorCode == 0)
+ return nPackets;
+ return -1;
+ }
+
+ unsafe public int WritePackets (bool useCache, long startingPacket, AudioStreamPacketDescription [] packetDescriptions, byte [] buffer, int offset, int count, out int errorCode)
+ {
+ if (packetDescriptions == null)
+ throw new ArgumentNullException ("inPacketDescriptions");
+ if (buffer == null)
+ throw new ArgumentNullException ("buffer");
+ if (offset < 0)
+ throw new ArgumentOutOfRangeException ("offset", "< 0");
+ if (count < 0)
+ throw new ArgumentOutOfRangeException ("count", "< 0");
+ if (offset > buffer.Length - count)
+ throw new ArgumentException ("Reading would overrun buffer");
+
+ int nPackets = packetDescriptions.Length;
+ fixed (byte *bop = &buffer [offset]){
+ errorCode = AudioFileWritePackets (handle, useCache, count, packetDescriptions, startingPacket, ref nPackets, (IntPtr) bop);
+ if (errorCode == 0)
+ return nPackets;
+ return -1;
+ }
+ }
+
[DllImport (Constants.AudioToolboxLibrary)]
extern static OSStatus AudioFileCountUserData (AudioFileID handle, uint userData, out int count);

0 comments on commit f831e6b

Please sign in to comment.
Something went wrong with that request. Please try again.