I'm currently facing the difficult task of achieving low-latency throughput on a class of USB chipset from C-Media (CM108/109/119) whose sample timings CoreAudio apparently cannot consistently track.
Problem: Over time (about 5 minutes), frames grabbed from the input stream become increasingly delayed, often by up to 250 ms. I'm guessing the HAL's IO engine is underestimating the actual sample rate of the device, leaving behind some number of frames during each IO cycle. Likewise, audio is sometimes garbled, perhaps from overestimating the sample rate and under-running the driver's buffer (?), though this is less common.
I can observe the effect using a simple HAL IOProc input callback or with any application that does software playthrough (e.g., CAPlayThrough, HALLab's Input window, etc...). On 10.5 and 10.6 I can reset this latency only by either unplugging the device or setting the stream format on any section. On 10.4 stopping the HAL engine for the app seems necessary.
This chipset is common in USB headsets (especially those for education) and has some desirable qualities (e.g., hardware-playthrough control), so I'm motivated to adapt my application (which involves very-low-latency audio conferencing) to work with it as well as possible. If knowledgeable CoreAudio people could tell me which of these work-arounds might set me on the right track or provide better suggestions, I would be extremely obliged:
a) Avoid AudioDeviceAddIOProc() and instead call AudioDeviceRead() from a real-time thread with jitter-buffer semantics, dropping a few frames every now and then b) Create a user-space HAL driver to manipulate whatever underlying ring buffer is feeding the HAL IO engine c) Create an AppleUSBAudio plug-in kext to do the same d) Set the stream format every few minutes to trigger a reset (extremely disruptive when playing or recording) e) Send commands directly to the chipset with IOKitLib to trigger a reset, aiming for fewer side-effects
Thanks very much in advance,
Zach
--------------------------------------- Zachary Schneirov Northwestern University |