简体   繁体   中英

Java Sound using specific Ports and DataLines

This feels like the 100th Java Sound related question I've asked on this site but I cant find the answer any where in the Java Sound API or at jsresources.org. I'm making a multitrack recorder and so far its working great, well better than expected, what I'm having problems with currently is allowing a user to select an input for each track at runtime. Right now my program just takes an available TargetDataLine from the Mixer and I'm able to control the volume during recording as well as the balance. If I list the Ports and allow a user to select a specific Port , for example the internal microphone in laptop, how do I get a TargetDataLine for that specific Port to use for recording? Is it a matter of closing all unused Ports ?

I also just noticed when listing the Ports source refers to input and target output, I just got used to DataLines being the other way around if someone could clarify that I'd appreciate it.

And something that may help me solve my current problem is understanding the relationship between Ports and DataLines , I know what the two are but I don't understand why you cant get a DataLine from a Port just like you would a mixer, so what is the relationship between the two?

You are getting ahead of what I have tried to do, but perhaps I can still help a bit!

Did you see this summary of the differences between a Port and a DataLine? http://docs.oracle.com/javase/7/docs/api/javax/sound/sampled/package-summary.html

It seems to me a given Port will work with only ONE of either a SourceDataLine or a TargetDataLine depending upon whether it is an input or output port.

Did you also try the examples from here? http://docs.oracle.com/javase/tutorial/sound/capturing.html

It seems to me that since a Port extends Line, the example code for reading audio should work if you substitute your Port for their Line (assuming it is an input Port). Does the example code work for you?

I'm guessing that if you are mixing sound from more than one Port, it would require unpacking the sound data, doing your own addition of the sound values and repacking them as PCM samples (ie, doing your own audio mixing) for a single output line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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