Controling the Volume of an Audio Clip in Java 1.4

痞子三分冷 提交于 2019-12-11 00:39:51

问题


I would have thought that this would be an easy thing to do, but no amount of googling around has turned up any solutions.

I have written an application for a client that runs in full screen and allows the user to page through educational books in order to help teach kids to read. So far so good. Some phrases from the displayed materials are read back to the user and, again, so far so good. Normally, these sounds are read at the system volume. (ie, at whatever volume any other system sound would be played.)

The client, however, now wants the user to be able to adjust the volume in program. I have the UI and processing end of that working, but I'm having a hard time adjusting the volume of the clips being played in a meaningful way. Right now I have a funky setup that involves reading the original gain of the clip and then adjusting that up or down for each clip. While this does adjust the volume, it does not seem to do it relative to the system volume -- all of the sounds are much quieter than the system volume.

So, my question really is: how do you suggest controlling sound volume within a program? All of my research has turned up nothing meaningful, which implies to me that it's kind of hard or even impossible, but that just doesn't seem right.

Oh, details: I'm reading in WAVs as AudioInputStreams and playing them as java.sound.sampled.Clip. I'm controlling the gain using FloatControl.Type.MASTER_GAIN. (FloatControl.Type.VOLUME is not supported.) I'm stuck using Java 1.4.


回答1:


You might also look to see if there is an older version of the Java Media Framework (JMF) that will support Java 1.4... it might provide you with a more rich environment for working with audio.

Other than that, you say you are stuck in 1.4... you might see if there is any way you can get upgraded to Java 5 or 6, though you may want to test either of these first on your local machine to see if they actually help any.

I guess one last suggestion is to find some Java game development sites and post your question there; I would think they would have figured out ways around it... though you could also get a lot of 'upgrade your jvm' responses there too. :-)

Good luck.




回答2:


This is an OS-specific thing to do, and you'll have to use either JNI or J/Invoke or JNIWrapper or jna or...



来源:https://stackoverflow.com/questions/1626751/controling-the-volume-of-an-audio-clip-in-java-1-4

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!