All Downloads are FREE. Search and download functionalities are using the official Maven repository.

be.tarsos.dsp.FadeOut Maven / Gradle / Ivy

There is a newer version: 2.4-1
Show newest version
package be.tarsos.dsp;

import be.tarsos.dsp.AudioEvent;
import be.tarsos.dsp.AudioProcessor;
import be.tarsos.dsp.GainProcessor;

public class FadeOut implements AudioProcessor
{
	// VARIABLES
	private double duration;
	private double firstTime=-1;
	private double time;
	private boolean isFadeOut=false;
	private GainProcessor gp=new GainProcessor(0.9);
	
	// METHODS
	
	// Constructor
	public FadeOut(double d) // d=duration of the fade out in seconds
	{
		this.duration=d;
	}
	
	// Start fade out processing
	public void startFadeOut()
	{
		this.isFadeOut=true;
	}
	
	@Override
	public boolean process(AudioEvent audioEvent)
	{
		// Don't do anything before the beginning of Fade Out
		if(isFadeOut==true)
		{
			if(firstTime==-1)
				firstTime=audioEvent.getTimeStamp();

			// Decrease the gain according to time since the beginning of the Fade Out
			time=audioEvent.getTimeStamp()-firstTime;
			gp.setGain(1-time/duration);
			gp.process(audioEvent);
		}
		return true;
	}
	
	@Override
	public void processingFinished()
	{
		gp.processingFinished();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy