Java Sound API: Recording Sound from the Target Port

I am writing a simple piece of software that transmits audio over a local area network. I have all the implemented network components, but what I come across is the use of the Java Sound API. I have successfully captured microphone audio and line-in, but I cannot capture from any target ports, such as speakers. My question is: can I capture from the main target port? Here is a piece of code that works when initializing a string.

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; } } 

Running code like this will just use a microphone as my line. Here is information about my sound system. The most important is probably the fact that I am running Linux.

Thanks in advance for any help you can give me.

+4
source share
3 answers

One of the problems with network audio is that computers at each end may have slightly different sampling frequencies due to differences between the clocks on the sound card. Computer clocks vary. If the sending computer is slower than the receiving computer, then even if you have a buffer, your buffer will be slowly empty. If it works faster, you will gradually get excess data. This man tried only what you did and saw the dropout. Please note that buying more expensive sound cards will reduce his problem, but will not completely fix it unless he does something like blocking them for a GPS time signal. Your regular casual user will not do this.

Perhaps for short gears you can handle it. For example, if you make a voice and you stop transmitting when the speaker is quiet, then you can synchronize your buffers when you restart. Interestingly, this will be with latency. The โ€œrightโ€ solution requires re-sampling the sound on the receiving side in order to cope with a small difference in sampling frequency.

With such a small change in frequency, you could leave with your closest neighbor - effectively pass or duplicate samples so often. The digital amateur radio software I've heard about uses linear interpolation between samples. You need to maintain and control the scaling factor to make sure you clear your buffer so that new data arrives, but has a control loop that won't be too frustrated by network vagaries and won't try to make sudden big changes.

I donโ€™t know if you took it into account or not. I saw people torture this, who do not. I, besides people, are currently using the former audio conferencing library to take care of this. If you're curious about how to do this, the digital ham community is a good place to watch.

+1
source

Here is the path (not software).

Jump to: Control Panel \ Hardware and Sound \ click on the sound icon. Now go to the recording, right-click-> select both options - turn on, turn off the device. You will find the Stereomix icon. Make it as the default device.

Now try to record the sound. The problem is resolved.

+1
source
Speakers

is a SourceDataLine, not a TargetDataLine. I donโ€™t understand how you can โ€œcaptureโ€ from the speaker?

0
source

Source: https://habr.com/ru/post/1310302/


All Articles