简体   繁体   English

通过TargetDataLine流实时音频

[英]Stream Real-Time Audio via TargetDataLine

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). 我的项目代码已经出现在JAVA音频数据流0上 (请原谅,我忘了启动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. 我的问题是理论性更高的,可能会回答诸如“使用低级语言”之类的问题,但是我很好奇是否有办法用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. 在代码synchronously设置的情况下,音频数据的读取/写入之间存在延迟,该延迟随缓冲区大小而变化,我想知道是否存在一种方法来传输音频(最好来自TargetDataLine )延迟最小,因此可以识别地播放歌曲或其他相对高质量的声音。 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! 谢谢!

SourceDataLine is pretty low level. SourceDataLine是相当低的级别。 It relies on native code implementations for each OS that Java accommodates. 它依赖Java可以容纳的每个OS的本机代码实现。

The main way to cut latency is to make your buffer smaller. 减少延迟的主要方法是减小缓冲区。

There are other issues pertaining to Java audio and "real time" guarantees. 还有其他有关Java音频和“实时”保证的问题。 You might find this article of interest: Real-Time Low Latency Audio Processing in Java . 您可能会发现本文感兴趣: Java中的实时低延迟音频处理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM