Java 长度无限的音频输入流
我有一堆代码,运行时会产生程序声音。不幸的是,它只持续几秒钟。理想情况下,它会一直运行,直到我告诉它停止为止。我不是在谈论循环,生成它的算法目前提供 2^64 个样本,因此在可预见的将来它不会用完。 AudioInputStream 的构造函数采用第三个输入,理想情况下我可以将其删除。我可以提供一个巨大的数字,但这似乎是错误的方法。
我考虑过使用 SourceDataLine,但理想情况下该算法将按需调用,而不是提前运行并编写路径。想法?
I have a bunch of code that will, when run, produce procedural sound. Unfortunately, it only lasts a few seconds. Ideally it would run until I tell it to stop. I'm not talking about looping, the algorithm to generate it provides 2^64 samples, at the moment, so it isn't going to run out within the foreseeable future. The constructor for AudioInputStream takes a third input, which I could ideally just remove. I could just provide a huge number, but that seems like the wrong way to go about it.
I thought about using SourceDataLine, but the algorithm ideally would be called on-demand, not running ahead and writing the path. Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来我已经回答了我自己的问题。
经过进一步研究,使用
SourceDataLine
是可行的方法,因为当您给它足够的空间来使用时,它会阻塞。对于缺乏适当的 Javadoc 表示歉意。
It seems I've answered my own question.
Upon further research, using the
SourceDataLine
is the way to go, as it'll block when you've given it enough to work with.Apologies for the lack of proper Javadoc.