This site requires JavaScript, please enable it in your browser!
Greenfoot back
darkmist255
darkmist255 wrote ...

2012/2/11

I know nothing of logarithms, quick question.

darkmist255 darkmist255

2012/2/11

#
I hear that setVolume(0-100) is based on logarithms, of which I have yet to learn about. I will do some research, but for now, does anyone know how I could achieve 33% volume and 66% volume? If not, can anyone link a site explaining it?
danpost danpost

2012/2/12

#
You know, I could not say for sure. But my best guesstimate is 50 for 33% and 80 for 66%.
darkmist255 darkmist255

2012/2/12

#
Thanks :D. I'll give them a shot. Any idea how I could try to figure it out myself?
danpost danpost

2012/2/12

#
You would probably have to get the specs on GreenfootSound.setVolume. Just saying it is logarithmic is not really enough information to determine exact numbers. The range is from 0 to 100 for the volume, but the graph of the log is infinite in both directions (left and right), and we do not know where along that scale they place 0 or 100!
darkmist255 darkmist255

2012/2/12

#
Neither do I, I heard in the past that it was logarithmic, but couldn't get any more information. The only information giver is "Set the current volume of the sound between 0 (off) and 100 (loudest.)".
kiarocks kiarocks

2012/2/12

#
Ok, i did research and found this:
public static float convertMinMax(int val, float min, float max)
    {
        float range = max - min;
        float newVal = val / (100 / range);
        return newVal + min;
    }
and
public synchronized void setVolume(int level)
    {
        this.masterVolume = level;
        if (soundClip != null) {
            if (soundClip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
                FloatControl volume = (FloatControl) soundClip.getControl(FloatControl.Type.MASTER_GAIN);
                volume.setValue(SoundUtils.convertMinMax(level, volume.getMinimum(), volume.getMaximum()));
            }
        }
    }
Thats the algorithm.
kiarocks kiarocks

2012/2/12

#
You hear sound at about 20 volume level.
darkmist255 darkmist255

2012/2/14

#
Hmm... Might just do some trial and error then, that's always been a second option.
You need to login to post a reply.