plectrum

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

FadeIn.java (1111B)


      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 FadeIn implements AudioProcessor
      8 {
      9 	// VARIABLES
     10 	
     11 	private double duration;
     12 	private double firstTime=-1;
     13 	private double time;
     14 	private GainProcessor gp=new GainProcessor(0.1);
     15 	private boolean fadingIn=true;
     16 	
     17 	// METHODS
     18 	
     19 	// Constructor
     20 	public FadeIn(double d) // d=duration of the fade in in seconds
     21 	{
     22 		this.duration=d;
     23 	}
     24 	
     25 	// Stop fade in processing immediately
     26 	public void stopFadeIn()
     27 	{
     28 		this.fadingIn=false;
     29 	}
     30 
     31 	@Override
     32 	public boolean process(AudioEvent audioEvent)
     33 	{
     34 		// Don't do anything after the end of the Fade In
     35 		if(fadingIn)
     36 		{
     37 			if(firstTime==-1)
     38 				firstTime=audioEvent.getTimeStamp();
     39 			
     40 			
     41 			// Increase the gain according to time since the beginning of the Fade In
     42 			time=audioEvent.getTimeStamp()-firstTime;
     43 			gp.setGain(time/duration);
     44 			gp.process(audioEvent);
     45 			if(time > duration){
     46 				fadingIn = false;
     47 			}
     48 		}
     49 		return true;
     50 	}
     51 	
     52 	@Override
     53 	public void processingFinished()
     54 	{
     55 		gp.processingFinished();
     56 	}
     57 }