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

jm.audio.synth.Comb Maven / Gradle / Ivy

There is a newer version: 1.6.4.1
Show newest version
/*



Copyright (C) 2000 Andrew Sorensen & Andrew Brown

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or any
later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

package jm.audio.synth;

import java.io.IOException;
import jm.audio.AudioObject;
import jm.audio.AOException;
import jm.music.data.Note;

/**
 * Comb filters ...
 * @author Andrew Sorensen
 * @version 1.0,Sun Feb 25 18:42:46  2001
 */

public final class Comb extends AudioObject{
	//The gain of this comb filter 
	private float decay;

	//The delay (in samples) to use with this comb filter
	private int delay;

	//Number of samples to delay by
	private float[] delayLine;

	//Delay line current index
	private int delayIndex;
	
	//----------------------------------------------
	// Constructors
	//----------------------------------------------
	/**
	 * @param delay delay in milliseconds
  	 * 
	 */
	public Comb(AudioObject ao, int delay){
		this(ao,delay,0.5);
	}

	/**
	 * @param delay delay in milliseconds
	 * @param gain as a percent
	 */
	public Comb(AudioObject ao, int delay, double decay){
		super(ao, "[Comb]");
		this.decay = (float)decay;
		this.delay = delay;
	}

	//----------------------------------------------
	// Methods
	//----------------------------------------------
	/**
	 * @param buffer any number of incoming samples 
	 */
	public int work(float[] buffer)throws AOException{
		int returned = this.previous[0].nextWork(buffer);
		int i=0;
		for(;i= delayLine.length){
				delayIndex = 0;
			}
		}
		return i;	
	}

	/**
	 * 
	 */
	public void build(){
		int sampleDelay = (int)((float)((float)this.delay/(float)1000) * this.sampleRate); 
		this.delayLine = new float[sampleDelay*this.channels];
		this.delayIndex = 0;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy