EasyOGG library - volume regulation problem

Hello, this is my first post, nice to be here!

Since I haven’t been able to find a solution to my problem I decided to ask: I recently added some sound the game i’m creating - I used the EasyOgg library, because a friend of mine recommended using ogg files. Unfortunately, I plan to add some kind of a volume regulator for the sounds produced by my game. Is there any way of controlling the volume of an OggClip?

Have a nice evening!

EasyOgg gives you a setGain(float vol) method, where vol should be a float between 0 and 1. EasyOgg then attempts to make use of the MASTER_GAIN Control for the SourceDataLine, but there are many setups where this Control will not be available.

You might also check TinySound (see the project at GitHub). It supports Ogg, and the line is played through a “mixer”. I think that TinySound offers a way to vary the volumes of the sounds as they go through the audio mixer.

Looking at the source code for EasyOgg, I think it could very well be possible to add a volume control that works at the “per sample” level rather than trying to use a Control that may or may not exist. Are you willing to tinker with the source? In the method “playStream()” (in OggClip source), notice there is an inner loop near the end where values are being multiplied by 32767. The ‘val’ variable can also be multiplied by a float that ranges from 0 to 1 at that point or on the next line as a separate command. (Do this BEFORE ‘val’ is compared to 32767!) The float variable you create and use as a volume factor should be a volatile instance variable with a public setter.

But I’m not absolutely sure that the playback runs through this ‘playStream()’ method. I’d have to spend more time examining the code.

There are further refinements, to make the range from 0 to 1 better map our sense of loudness, and to prevent clicks that can arise if you jump volume values “too much.” But first things first and maybe the above is “good enough.”