Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to implement getLevel() (DataLine Interface)

843802Mar 26 2010 — edited Sep 14 2010
Hello everybody,

the other day I had to realise that DataLine.getLevel() will always return -1 regardless from the object being a TargetDataLine or a SourceDataLine. I found this FAQ saying that getLevel() was not implemented in JDK 1.4.1. I really have to wonder why this has not been achieved yet since I'm using JDK 6 for developing and of course JRE 6 for running. The documentation does not give any further information about the method being implemented but this:
Returns: the current amplitude of the signal in this line, or AudioSystem.NOT_SPECIFIED sample code for javax.sound.sampled.AudioSystem.NOT_SPECIFIED
So I searched on to figure out how to implement this method on my own and found this [right here|http://forums.sun.com/thread.jspa?forumID=541&threadID=5395673]. Sorry but I still don't get it. All I can get from a line (that might have to do with the explanation) is the AudioFormat and from that the SampleRate and the SampleSizeInBits. How can this help me to calculate the current level?
I also stumbled upon other approaches telling me to calculate the root mean square of some buffered bytes I Just read from the line. I can understand what an RMS is in means of mathematics but I still don't comprehend how to apply this calculation on a byte array.

Please, can someone explain how to do it the right way?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 12 2010
Added on Mar 26 2010
17 comments
4,035 views