//export Go_callback func Go_callback(playerInfo unsafe.Pointer, queue C.AudioQueueRef, buffer C.AudioQueueBufferRef) { audioData := ((*[1 << 30]byte)(unsafe.Pointer((*buffer).mAudioData)))[:buffer.mAudioDataBytesCapacity] pktDescs := (*[1 << 30]C.AudioStreamPacketDescription)(unsafe.Pointer(buffer.mPacketDescriptions)) npackets := 0 upto := audioData if peeked != nil { copy(upto, peeked) pktDescs[npackets].mStartOffset = C.SInt64(int64(len(audioData) - len(upto))) pktDescs[npackets].mDataByteSize = C.UInt32(int32(len(peeked))) upto = upto[len(peeked):] npackets++ } peeked = <-packetsin for len(peeked) <= len(upto) { copy(upto, peeked) pktDescs[npackets].mStartOffset = C.SInt64(int64(len(audioData) - len(upto))) pktDescs[npackets].mDataByteSize = C.UInt32(int32(len(peeked))) pktDescs[npackets].mVariableFramesInPacket = C.UInt32(int32(0)) upto = upto[len(peeked):] npackets++ peeked = <-packetsin } buffer.mAudioDataByteSize = C.UInt32(len(audioData) - len(upto)) buffer.mPacketDescriptionCount = C.UInt32(npackets) C.AudioQueueEnqueueBuffer(queue, buffer, 0, (*C.AudioStreamPacketDescription)(nil)) }
// there is no uint64 CFNumber type, so we have to use the SInt64 one func convertUInt32ToCFNumber(u uint32) C.CFNumberRef { sint := C.SInt64(u) return C.CFNumberCreate(nil, C.kCFNumberSInt64Type, unsafe.Pointer(&sint)) }
// ===== CFNumber ===== // for simplicity's sake, only include the largest of any given numeric datatype func convertInt64ToCFNumber(i int64) C.CFNumberRef { sint := C.SInt64(i) return C.CFNumberCreate(nil, C.kCFNumberSInt64Type, unsafe.Pointer(&sint)) }
//export go_audiofile_getsizeproc func go_audiofile_getsizeproc(data unsafe.Pointer) C.SInt64 { af := (*AudioFile)(data) return C.SInt64(af.fileSize) }