Int16
この変更可能なポインターを変換UInt8
して、OutputStream に書き込むようにしようとしています。関数を使用しようとしました.withMemoryRebound
が、正しく行う方法がわかりません。この関数を使ってやりたいのですが、一度試しましたが成功しませんでした。以下のコードで何かを動作させることができますが、それが正しいとは思いません。
unwrappedOutputStream.open()
let buffer: UnsafeMutablePointer<Int16> = avAudioPCMBuffer.int16ChannelData![0]
let size = MemoryLayout<UInt8>.size
let bound: UnsafeMutablePointer<UInt16> = UnsafeMutablePointer.allocate(capacity: 1)
bound.pointee = UInt16(bitPattern: buffer.pointee)
let bytePointer: UnsafeMutablePointer<UInt8> = UnsafeMutablePointer.allocate(capacity: 1)
bytePointer.pointee = UInt8(bound.pointee >> 0x8)
unwrappedOutputStream.write(bytePointer, maxLength: size)
bytePointer.pointee = UInt8(bound.pointee & 0xff)
unwrappedOutputStream.write(bytePointer, maxLength: size)
bound.deallocate(capacity: 1)
bytePointer.deallocate(capacity: 1)
unwrappedOutputStream.close()
現在 Swift 4 を使用していますが、何かできることはありますか? ありがとうございます。ご理解とご協力をお願いいたします。