简体   繁体   English

如何录制javasound应用程序当前正在播放的声音?

[英]How can I record the sound that a javasound application is currently playing?

I have two wav files that I'd like to simulate generating at different points in 3D space, as heard from a rectangular 4 channel mic array. 我有两个wav文件,我想模拟在3D空间中不同点的生成,就像从矩形4通道麦克风阵列听到的那样。 That is, the ideal output will be either a single 4 channel wav file or 4 single channel wav files that are known to be synchronized. 也就是说,理想的输出将是单个4通道wav文件或4个已知已同步的单通道wav文件。

My current approach isn't all that great, but it could in principle work. 我目前的方法并不是很好,但是原则上可以。 I have the two sounds playing from their positions in a jReality simulation (chosen merely because I already had a jReality simulation handy). 我在jReality模拟中从它们的位置播放了这两种声音(之所以选择它们,仅仅是因为我已经有了jReality模拟的方便)。 There are two problems with this: A) jReality only supports a single microphone location and B) it goes directly from jReality to javasound and from there out my speakers. 这样做有两个问题:A)jReality仅支持单个麦克风位置,B)它直接从jReality到javasound,然后从我的扬声器发出。 To solve A, I should be able to position the mic, take a recording, move the mic and repeat. 要解决A,我应该能够放置麦克风,进行录音,移动麦克风并重复。 Unfortunately I don't know how to solve B, I do know that the recording has to be from within my java code because that's the only way to synchronize it. 不幸的是,我不知道如何解决B,我知道录制必须来自我的Java代码中,因为这是同步它的唯一方法。

So the question is twofold, first, is there a better way to simulate the audio mixing and attenuation? 所以问题是双重的,首先,有没有更好的方法来模拟音频混合和衰减? And secondly, is there a way to intercept things that have been sent to javasound and store them to files? 其次,有没有办法拦截已经发送到javasound的东西并将它们存储到文件中?

It is fully possible to read from four sources (AudioInputLines) and work on them at the "per frame" level. 完全有可能从四个源(AudioInputLines)中读取并在“每帧”级别对其进行处理。 Usually coders have a while loop for reading incoming audio data. 通常,编码器有一个while循环,用于读取传入的音频数据。 With each buffer read (for four sources, you would have four buffers) you would decode the incoming bytes into sound data, apply your mixing algorithm, and then reconvert the result back to bytes as per your audio format. 读取每个缓冲区(对于四个源,您将有四个缓冲区),您将解码传入的字节为声音数据,应用混合算法,然后根据音频格式将结果重新转换为字节。

If you wrap the above in a TargetDataLine, it will be possible to record it. 如果将以上内容包装在TargetDataLine中,则可以记录下来。

The Java Sound Tutorials cover this in a sort of "big picture" manner, but if you haven't come across the main concepts before (on using javax.sound.sampled library) it will be worth a look. Java Sound Tutorials以一种“大图”方式涵盖了这一点,但是如果您以前没有遇到过主要概念(使用javax.sound.sampled库),那么值得一看。

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

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