开发者

java sound, fadeIn effect, using FloatControl

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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜