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

jm.audio.synth.Grain2 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 jm.music.data.Note;
import jm.audio.AudioObject;
import jm.audio.Instrument;
import jm.audio.AOException;

/**
 * An Audio Object for granulation
 * @author Timothy Opie
 * @version 1.0, Saturday, May 1, 2004
 */

public final class Grain2 extends AudioObject{
	//----------------------------------------------
	// Attributes 
	//----------------------------------------------

	private int grainSampSize = 1000; // Size of grains in samples
	private int spaceSamp = 1000; // space between grains in samples
	private int grainCount = 0;
	private int spaceCount = 0;
	private int offset=0;
	private boolean grainOn = true; //To cheack whether a grain is on or not

	//----------------------------------------------
	// Constructors 
	//----------------------------------------------
	public Grain2(AudioObject ao, int grainSampSize, int spaceSamp, boolean grainOn, int chan, int offset){
		super(ao, "[Grain]");
		this.grainSampSize = grainSampSize * chan;
		this.spaceSamp = spaceSamp * chan;
		this.grainOn = grainOn;
		this.offset = offset;
	}


	/**
	 * @param buffer The sample buffer.
	 * @return The number of samples processed
	 */
	public int work(float[] buffer)throws AOException{
		int returned=this.previous[0].nextWork(buffer);
		int tempoffset=offset;
		if(offset>0) {
			for(int counter=0;counter




© 2015 - 2025 Weber Informatics LLC | Privacy Policy