Java的API的声音:从目标端口捕获声音输出 [英] Java Sound API: Capturing sound output from a Target Port

查看:145
本文介绍了Java的API的声音:从目标端口捕获声音输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个简单的软件,通过局域网流音频。我都实现了网络部分,但是我绊上使用Java API的声音。我已经成功抓获从麦克风和线路输入录音,但我似乎无法从任何目标端口捕获,就像扬声器。我的问题是,是否有可能从主目标端口捕捉?这里是一块code上初始化行工作的。

I'm writing a simple piece of software that streams audio over LAN. I have all of the network parts implemented, but what I'm stumbling on is using the Java Sound API. I have successfully captured audio from the microphone, and line-in, but I can't seem to capture from any target ports, like the speakers. My question is, is it possible to capture from the Master target port? Here is the piece of code that works on initializing the line.

private boolean startCapture(){
    try{
        DataLine.Info info = new DataLine.Info( TargetDataLine.class, format);
        line = (TargetDataLine)AudioSystem.getLine(info);
        audioBuffer = new byte[bufferSize];
        line.open(format);
        line.start();
        return true;
    }catch(Exception e){
        System.out.println("Exception thrown when capturing audio:\n" + e);
        return false;
    }
}

运行code这样将只使用麦克风为我行。 这里是我的音响系统的信息。最重要的是可能是我在运行Linux的事实。

Running the code like this will just use the microphone as my line. Here is info about my sound system. Most important is probably the fact that I'm running Linux.

先感谢您的任何和所有帮助你可以给我。

Thanks in advance for any and all help you can give me.

推荐答案

与网络健全的一个问题是,在每一端的计算机可能有由于声卡时钟之间的差异略有不同的采样率。计算机时钟而变化。如果发送计算机运行的是比接收计算机慢的话,即使你有一个缓冲区,您的缓冲区会慢慢空。如果正在运行的速度,然后你会慢慢得到过量的数据。 此人试过,你在做什么以及看到辍学。请注意,购买更昂贵的声卡会减少他的问题,但不能完全解决它,除非他确实像他们锁定到GPS时间信号。典型的一般用户不会那么做的。

One issue with network sound is that the computers at each end may have slightly different sample rates due to differences between the sound card clocks. Computer clocks vary. If the sending computer is running slower than the receiving computer then, even if you do have a buffer, your buffer will slowly empty. If it is running faster then you'll slowly gain an excess of data. This person tried just what you were doing and saw dropouts. Note that buying more expensive sound cards will reduce his problem but not completely solve it, unless he does something like lock them to the GPS time signal. Your typical casual user won't do that.

也许短期传输你可以逃脱它。如果你正在做,例如语音和你停止发送当扬声器静音然后当你再次启动同步您的缓冲区。我不知道它会做等待时间。 正确的解决方案要求在接收端重新采样的音频处理的采样率的轻微差异。

Maybe for short transmissions you can get away with it. If you're doing voice for example and you stop transmitting when the speaker is quiet then you can synchronise your buffers when you start again. I wonder what it would do to latency. The "proper" solution requires re-sampling the audio at the receiving end to deal with the slight difference of sample rate.

有关频率这么小的变化你可能逃脱采取近邻 - 有效地跳跃或每隔一段时间重复样本。数字业余无线电软件,我听说过采样之间使用线性插值。你需要保持缩放因子,并控制它,以确保您在新的数据来源中企清空你的缓冲区,但有一个控制环,将不会受到网络变化莫测的太难过,而不是试图让突然发生较大变化

For such small variation in frequency you could possibly get away with taking the nearest neighbour - effectively skipping or duplicating samples every so often. Digital Amateur radio software I've heard of uses linear interpolation between samples. You need to maintain a scaling factor and control it in order to ensure that you empty your buffer at the rate that new data comes in, but have a control loop that will not be too upset by network vagaries and not try to make sudden large changes.

我不知道你是否已经考虑到这一点或没有。我见过人们尝试这个谁没有。我现在除了人会使用一种现成的,现成的音频会议库,采取这种事情的照顾。如果你有兴趣在如何做到这一点,数字业余无线电界是一个很好的地方去寻找。

I don't know whether you've taken this into account or not. I've seen people attempt this who have not. I except nowadays people would use an off-the-shelf audio conferencing library which takes care of this kind of thing. If you're interested in how to do it, the digital amateur radio community is a good place to look.

这篇关于Java的API的声音:从目标端口捕获声音输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆