plectrum

Plectrum: instrument tuner for Android
Log | Files | Refs | README | LICENSE

FadeOut.java (1062B)


      1 package be.tarsos.dsp;
      2 
      3 import be.tarsos.dsp.AudioEvent;
      4 import be.tarsos.dsp.AudioProcessor;
      5 import be.tarsos.dsp.GainProcessor;
      6 
      7 public class FadeOut implements AudioProcessor
      8 {
      9 	// VARIABLES
     10 	private double duration;
     11 	private double firstTime=-1;
     12 	private double time;
     13 	private boolean isFadeOut=false;
     14 	private GainProcessor gp=new GainProcessor(0.9);
     15 	
     16 	// METHODS
     17 	
     18 	// Constructor
     19 	public FadeOut(double d) // d=duration of the fade out in seconds
     20 	{
     21 		this.duration=d;
     22 	}
     23 	
     24 	// Start fade out processing
     25 	public void startFadeOut()
     26 	{
     27 		this.isFadeOut=true;
     28 	}
     29 	
     30 	@Override
     31 	public boolean process(AudioEvent audioEvent)
     32 	{
     33 		// Don't do anything before the beginning of Fade Out
     34 		if(isFadeOut==true)
     35 		{
     36 			if(firstTime==-1)
     37 				firstTime=audioEvent.getTimeStamp();
     38 
     39 			// Decrease the gain according to time since the beginning of the Fade Out
     40 			time=audioEvent.getTimeStamp()-firstTime;
     41 			gp.setGain(1-time/duration);
     42 			gp.process(audioEvent);
     43 		}
     44 		return true;
     45 	}
     46 	
     47 	@Override
     48 	public void processingFinished()
     49 	{
     50 		gp.processingFinished();
     51 	}
     52 }