Sunday, December 15, 2013

Maximum Midi

In the human or natural world, people or creatures communicate with each other sounds, gestures & motions, symbols & writing, and even smells.

The electronic world, devices communicate with each other through electricity. 

Analog Communication

 In the analog domain, raw voltages carry "meaning", and can sway in relatively massive swings.  Old telephones, for example, convert the voice to electricity, send that electricity over wires, then to a speaker, which renders the electricity as sound.

Digital Communication

In the digital domain, electric current is split into discrete units of measurement: sequences of blips ("on") and bleeps ("off") carry meaning.  A raw voltage might be sampled and converted from a massive, continuous signal, and chunked up into streams of bits.  How a digital device works is highly dependent on the digital design, so what follows is only true at a very high level.

Typically, there are two signals--two wires--a clock wire and a data wire.  Electricity on each wire can be a "high" voltage, and a "low' voltage.  No voltage--well, that could be high, or low, or...just means everything is turned off. Really depends! 
  • In general, the clock signal ticks and tocks, flipping from high voltage to low voltage at regular intervals.  
  • A data signal will be high or low (on or off) in sync with the clock signal
  • A transmitter will "send" on the "tick" portion of a clock (when clock signal falls from high to low) either a high voltage (on) or a low voltage (off).
  • A receiver will "listen" on the tock portion of a clock (when clock signal rises from low to high) for either a high voltage (on) or a low voltage (off).
  • Or...some other design all together (beyond the scope of this posting).

Definition: Bits

On or Off has meaning, so we call this measurement data--the data is one "bit", and is true or false.  A bit forms the basis of binary numbers and all digital processing.

Definition: Serial vs Parallel

Bits can be sent digitally, typically, in one of two methods: in serial, one bit after the other, and in parallel, a whole bunch at a time.   Both have their pros and cons that are far beyond the scope of this blog.  

Definition: Baud Rate

The key is in serial devices, there can only be ONE bit sent--and received--at a time.   Thus, serial devices have what is known as a baud rate--essentially, the clock rate of the digital signal.  A higher baud rate means the clock is running faster, implying that there can be more data sent.  Not always true!

Definition: Protocol

How and when bits are sent, and what a package of bits means--all make up a given protocol.  A protocol is really, how two digital devices "speak" to each other, breaking collection of bits into various packets, and -- in general -- defining strict, repeatable rules that can generate and process the same data the same way over and over again.

Maximum MIDI: One note every 960 microseconds

MIDI (or Musical Instrument Digital Interface) is an asynchronous serial protocol that multiple pieces of musical hardware can use to talk to each other.  The MIDI protocol specifies a maximum baud rate of 31250; a given MIDI packet is 10 bits long: 8 bits of data, and 2 bits of transport overhead.  MIDI also specifies 5 pins (wires), though only 3 are used: pin 1 is ground. Pins 4 and 5 are clock and data.

This means that in a second, MIDI can support a theoretical maximum of 31250 baud rate / 10 bits = 3125 packets of MIDI data. 

A given MIDI note on event is three packets of MIDI data: "note on" "note" "velocity".  That means MIDI can support, at best, 3125/3 = 1041 midi note on events in a given second.

Keep in mind, MIDI is serial, and  this means bits are sent one of after the other.  In MIDI, there is no true simultaneous communication for a given MIDI port.

Since MIDI is serial, when we hit a chord, we aren't sending three note on events a the same time, instead we are sending one note on events three times: one each 1/1041 = 0.00096 seconds (or 960 microseconds).

todo --  above is incorrect, running status

Can the ear hear 960 microseconds of delay? Probably.

In comparison, the human ear should be able to distinguish between .06 microseconds and 1667 microseconds of delay, although technically we're not quite sure.  1667 microseconds represents the the amount of time a single hair could respond, since a given neuron only operates at 600Hz, neurons can't respond any faster then that (sadly inefficient creatures we are).   However, we may have as many as 30k neurons!

The limits of human hearing, courtesy of Yamaha, are as follows:
Yamaha Audio Studies


Will our brain fix 960 microseconds of delay? probably.

Our brain is an incredible processing environment.  It will go through great lengths to keep our natural, analog world in sync with what it thinks should be proper timing.  Whereas neurons may feed information that tell our brain "hey these sounds are getting generate every 960 microseconds", our brain will auto correct those sounds so that they appear to all be starting at the same time.  Delays up to 20 milliseconds are automatically 'corrected' but can be felt...certainly 960 microseconds of delay are not going to be noticed. 

http://edge.org/conversation/brain-time

Can MIDI modules respond within 960 microseconds?

This is a good question. I am not sure yet if synthesizers and romplers have an internal parts per quarter (PPQ) that they use to "batch" chords up...or if they can handle it.