Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert AudioBuffer to data?

Tags:

ios

swift

i want to convert unsafemutablepointer to data, here is my sample code

let u8ptr: UnsafeMutablePointer<UInt8> = buffer.mData!.assumingMemoryBound(to: UInt8.self)

I am trying to convert AudioBuffer to NSData or Data. Any help is appreciated.

like image 929
BXV Avatar asked Nov 24 '25 18:11

BXV


1 Answers

When working with AudioBuffer, the byte size of the data is given int the property mDataByteSize. And when creating a Data, you have no need to convert the pointer type using assumingMemoryBound.

let data = Data(bytes: buffer.mData!, count: Int(buffer.mDataByteSize))
like image 70
OOPer Avatar answered Nov 26 '25 09:11

OOPer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!