public void setGain( float g )
    {
        // Make sure there is a gain control
        if( gainControl == null )
            return;
        
        // make sure the value is valid (between 0 and 1)
        float gain = g;
        if( gain < 0.0f )
            gain = 0.0f;
        if( gain > 1.0f )
            gain = 1.0f;
        
        double minimumDB = gainControl.getMinimum();
        double maximumDB = initialGain;

        // convert the supplied linear gain into a "decible change" value
        // minimumDB is no volume
        // maximumDB is maximum volume
        // (Number of decibles is a logrithmic function of linear gain)
        double ampGainDB = ( (10.0f / 20.0f) * maximumDB ) - minimumDB;
        double cste = Math.log(10.0) / 20;
        float valueDB = (float) ( minimumDB + (1 / cste) * Math.log( 1 +
                                                (Math.exp(cste * ampGainDB) - 1)
                                                * gain ) );
        // Update the gain:
        gainControl.setValue( valueDB );
    }