I am looking for a solution to the following issue:
- There are multiple bundles within my java run-time which might produce audio output.
- The user should be able开发者_StackOverflow社区 to control the volume of all bundles by only one slider (until this point, I could use
AudioSystem.getMixer()
to obtain the windows main volume control) - There is one bundle that creates important audio output that should not be affected by the slider above.
As mentioned, target environment is windows (XP or later).
Unfortunately, all audio output bundles share the same process id as they're part of the same java run-time. For this reason windows will only create one application specific mixer. Do you have any ideas?
Are you playing via Clips? SourceDataLines? Very likely, each exposes a Control that can be used to change volume. With a basic sort of Producer/Consumer Design Pattern you can select which sounds are affected by the JSlider or not.
In other words, you can do things at the Clip/SDL level rather than at the mixer level.
And if a Control for volume doesn't work, it is not that difficult to create a float "volume" variable that you can "subscribe" or expose to the JSlider, that holds values between 0 and 1.0f and multiply that to each frame value in the inner buffer loop prior to SourceDataLine playback. It might require putting bytes together (for 16-bit sound), doing the multiplication, then taking them back apart again. There are other threads here that show the coding for little-endian or big-endian sound data treatment.
I took one look at the OSGi link provided and ran away. I'm mostly just doing javax.sound.sampled directly.
I would be quite surprised if the "bundle" provided by a third party for sound didn't expose a volume control. It seems like such a basic thing!
精彩评论