Question

So, I've been working on a pet project for some time, and I finally got it all working... Mostly. My project code has already come up at JAVA audio data streaming 0s (please, excuse that I forgot to start my TargetDataLine xp). My question is more theoretical, and may be subject to answers such as "use a lower level language", but I'm curious as to if there is a way to do it in Java. With my code set up synchronously the way it is, there is a delay between the reading/writing of my audio data that varies with the buffer size, and I was wondering if there is a way to stream the audio (preferably from a TargetDataLine) with minimal latency so that a song or other relatively high quality sound could be played recognizably. My logic goes:

while (Stream.RENDERING_BUFFER.isOpen()) {
    int readLength = Stream.PROCESSING_BUFFER.read(Stream.READ_BUFFER, 0, Stream.BUFFER_SIZE);
    Stream.RENDERING_BUFFER.write(Stream.READ_BUFFER, 0, readLength);
}

Thanks!

Was it helpful?

Solution

SourceDataLine is pretty low level. It relies on native code implementations for each OS that Java accommodates.

The main way to cut latency is to make your buffer smaller.

There are other issues pertaining to Java audio and "real time" guarantees. You might find this article of interest: Real-Time Low Latency Audio Processing in Java.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top