• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Question about latency on the line-in port
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about latency on the line-in port


  • Subject: Re: Question about latency on the line-in port
  • From: Brian Willoughby <email@hidden>
  • Date: Tue, 9 Jun 2009 03:11:06 -0700


On Jun 9, 2009, at 02:43, Rob Ross wrote:
Can I achieve sub-millisecond latency, say if my buffer is 1024 or 512 bytes, at a sample rate of 44000 - 48000?


Before getting into any CoreAudio-specific details, your example is mathematically impossible. A 1024-byte buffer at 44100 Hz will always have at least 23.22 milliseconds of latency, plus any additional latency from the converter chips. The best case among the ranges you gave would be a 512-byte buffer at 48000 Hz, which is still over 10.7 milliseconds of latency.

So: No, there is no software, operating system, or audio API (not even the famous ASIO) which can use buffers that large with sample rates that low without over ten times the latency you seek. The DMA might be operating with a buffer that large with fancy tricks to get lower latency, but then your audio software would necessarily see smaller buffers than the DMA. The only real way to get low latency is with very small buffers and much higher sampling rates.

To continue the math, at 44.1 kHz, the largest sub-millisecond- latency buffer is 32 bytes, where you get 0.73 milliseconds or more. Even a 64-byte buffer would have a minimum of 1.45 milliseconds. If you increase to 48 kHz, you still have to stay down at 32 bytes. Usually the buffers must be a power of two in size, but even if 48- byte buffers (between 32 bytes and 64 bytes) were possible, they still would be too large for sub-millisecond latency.


I have a general high-level question. Say you want to write a GarageBand type application, where you want to play an instrument like a guitar, and plug it into the line-in jack of the Mac, and read the data samples as you play, and write them immediately to the line-out port; i.e., I want to hear myself play in real time (or as close to real time as possible.)

Is this achievable using CoreAudio? What is the minimum latency in reading a number of samples from the line-in port?

The basic answer depends upon the specific hardware for the line-in port. Audio hardware changes from model to model, and CoreAudio always allows the programmer access to information about the latency of the audio converter hardware and bus transport itself. Apart from external latency in the audio device itself, you must also deal with the CPU speed, which is independent of CoreAudio. It is rather difficult for the average programmer to write software which can process 32-byte buffers without a single glitch. Once you've taken care of those two variables, there may be a minimum latency for CoreAudio in terms of a safety offset, but CoreAudio also lets your program request this information from the system.


i.e. The answer is not the same for every computer.

Brian Willoughby
Sound Consulting

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Question about latency on the line-in port
      • From: Rob Ross <email@hidden>
References: 
 >Question about latency on the line-in port (From: Rob Ross <email@hidden>)

  • Prev by Date: RE: Synchronizing Multiple AUGraph's
  • Next by Date: Audio processing thread realtime priorties
  • Previous by thread: Question about latency on the line-in port
  • Next by thread: Re: Question about latency on the line-in port
  • Index(es):
    • Date
    • Thread