tags:

views:

30

answers:

1

Im trying to implement fade in effect to my mp3 player. I´m using FloatControl volumeControl = (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN); because FloatControl.Type.VOLUME throws an exception(Unavaliable Control) I dont know why. I need some help with the algorithm, because its not working ok. Heres the code:

public class FloatControlFader
{
    public static void fadeIn(final FloatControl control, final float from,
            final float to, final int seconds)
    {
        final float vps = ((to-from) / (seconds*10));//Volume incrased/100millisecond
        control.setValue(from);
        Thread t = new Thread(new Runnable(){

            public void run() {
                for(int i=0; i < seconds*10; i++)
                {
                    try
                    {
                        Thread.sleep(100);
                    }
                    catch (InterruptedException ex)
                    {

                    }
                    System.out.println(control.getValue()); //for DEBUG
                    control.setValue(control.getValue() + vps);
                }
            }

        });
        t.start();
    }
}

Would appreciate any help, thanks!

+1  A: 

Remember the human ear does not hear linearly so increasing by a steady X vps is not going to sound like a smooth fade. You need to put a log function in there. Then you need to map the linear increases to log values. This is of course all assuming the volume control units are not in decibels. If you're increasing by db then you're fine.

Nick
Thank you, I didnt know that. I am trying to figure out if the FloatControl uses Db or not
fredcrs
how can I map those values using log?
fredcrs
I cant get it working using Log. Dont know how to map it to a log function. Can u help me?
fredcrs