Strange MIDIPacket Sizes

While vigorously testing out my iOS app with a MIDI controller keyboard, I sometimes generate CoreMIDI input that is clearly garbage. Here is the code I use to iterate over the MIDIPacketList:

Code Block        
let numPackets = packetList.numPackets
os_log(.info, log: log, "processPackets - %d", numPackets)
var packet: MIDIPacket = packetList.packet
for index in 0..<numPackets {
os_log(.info, log: log, "packet %d - %d bytes", index, packet.length)
  // Filter out garbage (zero or really big sizes of 26624)
  if packet.length == 0 || packet.length > 30 {
  os_log(.error, log: log, "suspect packet size %d", packet.length)
    break
  }
  processPacket(packet, controller)
  packet = MIDIPacketNext(&packet).pointee
}

If I pound away on the keys and do a lot of pitch bends and mod wheel spins, I can sometimes get what appears to be garbage, with packets of either 0 or 22624 bytes (which is curiously 0x6800 hex). As above, I currently stop processing the MIDIPacketList when this happens, but that is clearly not a great solution. Anyone else encounter something like this?

Replies

Where is packetList from? Is this your ReadBlock? You get an UnsafePointer pointer there as a param. You can iterate over it via unsafeSequence()
  • Hi Gene. Apologies for the delay --I just saw this. The packeList comes from the argument given to the closure I give to MIDIInputPortCreateWithBlock -- I call packetList.pointee to get a MIDIPacketList which is what I work on in the code above. The issue only manifests when I quickly and repeatedly press down on a lot of keys, generating a lot of MIDI traffic.

Add a Comment
I'm seeing a similar thing, but with MIDI data coming from RTP-MIDI network connections inbound. Anything that generates a reasonably significant amount of traffic will do it, and it seems fairly random. It appears to be a recent problem, as I've run the exact same code in the same situations a thousand times before but since one of the latest updates I've been seeing this... possibly a bug in CoreMIDI?

I should note, the odd sizes I'm seeing are exactly 0x7000 in length...
  • Thanks for the reply. Good to know I'm not alone. Curious too that our packets are quite close in size.

Add a Comment