• 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: Realtime synthesis and low latency with Java
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Realtime synthesis and low latency with Java


  • Subject: Re: Realtime synthesis and low latency with Java
  • From: Bob Lang <email@hidden>
  • Date: Wed, 23 Nov 2005 17:25:55 +0000

Hi Peter

Java Sound mixers appear to have an "inherent" or "minimum" latency which is seems to be independent of the buffer size specified when the Source Data Line is opened. When you write your first buffer of data, the time before it appears in the speaker is given by the inherent latency, plus the buffer latency.

This inherent latency was particularly bad on XP for Java 1.4 but was much improved for Java 5, when the "Direct Sound" mixer was introduced. By comparison, the Apple mixer appears to be unchanged from 1.4 to 5.0 and this has a noticeable inherent latency of (I guess) the order of some hundreds of milliseconds. Reducing the buffer size cannot change this and there's no simple workaround. (see below for difficult workarounds).

Looking at your code, it appears to me over-designed (but who I am to criticise?). Writes sent to a Source Data Line should block once the SDL's buffer is full. If you set this buffer size to the same size of your outBuffer, then the SDL should block on *every* loop pass and your processing is reduced to this:

lineOut.open (audioFormat, outBuffer.length);

while (isRunning) {
   computeAudioHere ();
   lineOut.write (outBuffer, 0, outBuffer.length);
}

The blocking behaviour of write () stops the loop from running ahead of time and also allows other threads to execute. It's also much simpler. I feel sure that the designers of Java Sound had this in mind when they specified what write () should do.

Difficult workarounds to the latency issue are:
a) Ask Apple to put more development into the Java 5.0 Output Mixer
b) Develop your own Mixer via the SPI
c) Convert your application to use Core Audio via the Java JNI interface

The difficulty of (b) and (c) is compounded because Apple has stopped development of the Core Audio JNI interface. This means that before you can do either of these things, you need to update it to the latest version of Core Audio. (The old version is open source and so can be used as a basis for a new version - but it's another hassle)

I'm not sure any of this has actually helped you with your problem.

Good luck with your project.

Bob
--
On 23 Nov 2005, at 09:39, Peter Salomonsen wrote:

Hi,

I'm developing a software music studio in Java, with realtime sound synthesis
and low latency.


Reliable low latency and realtime sound synthesis is my main headache when it
comes to Java sound. I've made a lot of tries and the result is fairly good
on Linux and Windows platforms. But I still struggle with the Mac OSX
implementation. It just won't keep up on the low latencies...


I've written down some thoughts around the methods I use, and you can read it
here:


http://www.petersalomonsen.com/ShowFolder.asp?id=6142

An implementation of the method described in the article is the latest version
of Frinika (Version 0.1.6): http://www.frinika.com


Best regards,
Peter Salomonsen
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40blueyonder.co.uk


This email sent to email@hidden


_______________________________________________ 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: Realtime synthesis and low latency with Java
      • From: Peter Salomonsen <email@hidden>
References: 
 >Realtime synthesis and low latency with Java (From: Peter Salomonsen <email@hidden>)

  • Prev by Date: Re: Side-chain detection
  • Next by Date: Re: Side-chain detection
  • Previous by thread: Realtime synthesis and low latency with Java
  • Next by thread: Re: Realtime synthesis and low latency with Java
  • Index(es):
    • Date
    • Thread