highfidelity/hifi — pull request #3055 by wangyix (2014-06-23 18:32:47+00:00)
Title: Audio jitter buffer resizes depending on max inter-frame time gaps of incoming audio packets

Issue: audio jitter buffer size was fixed at 12ms worth of audio samples, which means it adds about 12ms of delay between incoming audio and audio being mixed and sent back out.

Fix: added class InterframeTimeGapStats which keeps track of the max time gap between incoming audio packets of a particular stream for the past 5000 packets, updated every 500 packets. This max time gap determines the desired size of the jitter buffer for that stream. The current size of the jitter buffer is tracked as follows: whenever the jitter buffer is starved, it's allowed to refill to at least its desired before frames are read from it for mixing. The size that it refills to is the new current jitter buffer size.
When a silent audio packet is received and the current jitter buffer size is larger than the desired size, the silent audio packet is dropped to get the current size closer to the desired size.

Testing: ran audioDeviceExample.js with debugging code to monitor the desired and current jitter buffer sizes update for the AvatarAudioRingBuffer. Ran editVoxels.js and added voxels to monitor InjectedAudioRingBuffer.