I'm importing code from Oracle JDK to OpenJDK (Java 8). The only problem left to solve is how to change the volume of Java Clip (java.sound.sampled.Clip) ? Even after hours of searching I couldn't find how to change the volume of Clip.
Using Oracle JDK I did it so:
FloatControl floatControl = (FloatControl) myClip.getControl(FloatControl.Type.MASTER_GAIN);
floatControl.setValue(myVolume);
I also tried FloatControl.Type.VOLUME
but that isn't supported.
I would love just to change the volume of a Clip instead of rewriting my entire audio system using another class/package.
The idea I have is to multiply the incoming audio data with a float
which will either lower or raise the volume. Downside is that it will probably be expensive as I need to change volume while playing the audio instead of doing it once when the program is launched.
EDIT: I guess that it's not that simple with Clip
as there's not a single answer or a comment. What else I could use then aside Clip
that is easy to set up and is lightweight (as I might have up top 30 sounds playing at once) ?
Kubuntu 19.04 on Linux 5.0.0-27
OpenJDK 1.8.0_222