package de.maramuse.soundcomp.generator;
/*
* Copyright 2010 Jan Schmidt-Reinisch
*
* SoundComp - a sound processing library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; in version 2.1
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* A source for pink noise, generated by filtering from white source
*/
import de.maramuse.soundcomp.process.NamedSource;
import de.maramuse.soundcomp.process.ParameterMap;
import de.maramuse.soundcomp.process.ProcessElement;
import de.maramuse.soundcomp.process.SourceStore;
import de.maramuse.soundcomp.process.StandardParameters;
import de.maramuse.soundcomp.process.Stateful;
import de.maramuse.soundcomp.process.TypeMismatchException;
import de.maramuse.soundcomp.process.UnknownConnectionException;
import de.maramuse.soundcomp.process.ValueType;
import de.maramuse.soundcomp.process.StandardParameters.Parameter;
import de.maramuse.soundcomp.util.NativeObjects;
import de.maramuse.soundcomp.util.ReadOnlyMap;
import de.maramuse.soundcomp.util.ReadOnlyMapImpl;
public class PinkNoise implements ProcessElement, Stateful {
static{
try{
Class.forName("de.maramuse.soundcomp.util.NativeObjects");
}catch(Exception e){
e.printStackTrace();
System.out.println(e.getMessage());
}
}
private long nativeSpace=-1;
static ReadOnlyMapImpl<Integer, ValueType> destMap=new ReadOnlyMapImpl<Integer, ValueType>();
static ReadOnlyMapImpl<Integer, ValueType> sourceMap=new ReadOnlyMapImpl<Integer, ValueType>();
static{
sourceMap.put(StandardParameters.OUT.i, ValueType.STREAM);
}
@Override
public ReadOnlyMap<Integer, ValueType> getDestinationTypes() {
return destMap;
}
private static ParameterMap inputsMap=new ParameterMap();
private static ParameterMap outputsMap=new ParameterMap();
static{
outputsMap.put(StandardParameters.OUT);
}
public PinkNoise() {
// try {
NativeObjects.registerNativeObject(this);
// pf.setSource(StandardParameters.IN.i, wn, StandardParameters.OUT.i);
// } catch (UnknownConnectionException e) { // actually these can never happen
// e.printStackTrace();
// } catch (TypeMismatchException e) {
// e.printStackTrace();
// }
}
PinkNoise(boolean s) {
// try {
// pf.setSource(StandardParameters.IN.i, wn, StandardParameters.OUT.i);
// } catch (UnknownConnectionException e) { // actually these can never happen
// e.printStackTrace();
// } catch (TypeMismatchException e) {
// e.printStackTrace();
// }
}
private String abstractName, instanceName;
// private WhiteNoise wn=new WhiteNoise();
// private PinkFilter pf=new PinkFilter();
private native double ngetValue(long _nativeSpace, int sourceIndex);
@Override
public double getValue(int index) {
return ngetValue(nativeSpace, index);
}
private native void nadvanceOutput(long _nativeSpace);
@Override
public void advanceOutput() {
nadvanceOutput(nativeSpace);
}
private native void nadvanceState(long _nativeSpace);
@Override
public void advanceState() {
nadvanceState(nativeSpace);
}
@Override
public void setSource(int connectionIndex, NamedSource source,
int sourceIndex) throws UnknownConnectionException,
TypeMismatchException {
throw new UnknownConnectionException("no source can be set for PinkNoise");
}
@Override
public ReadOnlyMap<Integer, ValueType> getSourceTypes() {
return sourceMap;
}
/*
*
* @Override public double getValue(int index) { return pf.getValue(index); }
*
* @Override public void advanceOutput() { pf.advanceOutput(); }
*
* @Override public void advanceState() { wn.advanceState(); pf.advanceState(); }
*/
@Override
public String getAbstractName() {
return abstractName;
}
@Override
public String getInstanceName() {
return instanceName;
}
@Override
public void setAbstractName(String abstractName) {
this.abstractName=abstractName;
}
@Override
public void setInstanceName(String instanceName) {
this.instanceName=instanceName;
}
@Override
public long getNativeSpace() {
return nativeSpace;
}
@Override
public ReadOnlyMap<Integer, SourceStore> getSourceMap() {
return ReadOnlyMapImpl.emptyMapIntSource;
}
/**
* @see de.maramuse.soundcomp.process.ProcessElement#clone()
*/
@Override
public PinkNoise clone() {
PinkNoise c=new PinkNoise();
c.abstractName=abstractName;
return c;
}
/*
* (non-Javadoc)
*
* @see de.maramuse.soundcomp.process.ProcessElement#outputsByName()
*/
@Override
public ReadOnlyMap<String, Parameter> outputsByName() {
return outputsMap;
}
/*
* (non-Javadoc)
*
* @see de.maramuse.soundcomp.process.ProcessElement#inputsByName()
*/
@Override
public ReadOnlyMap<String, Parameter> inputsByName() {
return inputsMap;
}
}