📄 voicebuffer.java
字号:
// storage size of token like a buffer
package ptolemy.actor.lib;
import ptolemy.actor.IOPort;
import ptolemy.actor.TypedIOPort;
import ptolemy.data.ArrayToken;
import ptolemy.data.Token;
import ptolemy.data.type.ArrayType;
import ptolemy.data.type.BaseType;
import ptolemy.data.BooleanToken;
import ptolemy.data.IntToken;
import ptolemy.data.DoubleToken;
import ptolemy.data.type.Type;
import ptolemy.data.expr.Parameter;
import ptolemy.kernel.CompositeEntity;
import ptolemy.kernel.util.*;
//////////////////////////////////////////////////////////////////////////
//// VoiceBuffer
/*
An actor that storage token like a buffer ,when reset is actor has a single input
multiport, and a single output port. The types on the input and the output
port must both be the same type. During each firing, this actor reads
up to one ArrayToken from each channel of the input port and storage it to
the ArrayToken of the same type until reset is false, then send it to the output port.
If no token is available on a particular channel, then there will be no contribution to
the output.
@author HuiYan
*/
public class VoiceBuffer extends Transformer {
/** Construct an actor with the given container and name.
* @param container The container.
* @param name The name of this actor.
* @exception IllegalActionException If the actor cannot be contained
* by the proposed container.
* @exception NameDuplicationException If the container already has an
* actor with this name.
*/
public VoiceBuffer(CompositeEntity container, String name)
throws NameDuplicationException, IllegalActionException {
super(container, name);
// The input is a multiport.
input.setMultiport(true);
reset = new TypedIOPort(this, "reset", true, false);
reset.setTypeEquals(BaseType.BOOLEAN);
Size = new Parameter(this, "Size");
Size.setExpression("1");
// Set type constraints.
input.setTypeEquals(new ArrayType(BaseType.UNKNOWN));
output.setTypeAtLeast(input);
Size.setTypeEquals(BaseType.INT);
}
///////////////////////////////////////////////////////////////////
//// ports and parameters ////
/** The value is the size of buffer */
public Parameter Size;
/** The reset port of type BooleanToken. If this port
* receives a True token, then the VoiceBuffer state will be reset to zero
token ,all token will be send to the output .
*/
public TypedIOPort reset;
///////////////////////////////////////////////////////////////////
//// public methods ////
/** Clone the actor into the specified workspace. This calls the
* base class and then creates new ports and parameters.
* @param workspace The workspace for the new object.
* @return A new actor.
* @exception CloneNotSupportedException If a derived class contains
* an attribute that cannot be cloned.
*/
public Object clone(Workspace workspace)
throws CloneNotSupportedException {
VoiceBuffer newObject = (VoiceBuffer)(super.clone(workspace));
// Set the type constraints.
newObject.output.setTypeAtLeast(newObject.input);
return newObject;
}
public void fire() throws IllegalActionException {
BooleanToken r;
int size=((IntToken)Size.getToken()).intValue();
Token[]_tokenArray=input.get(0,size);
// Check whether to reset.
if (reset.hasToken(0))
{ r = (BooleanToken)reset.get(0);
if (r.booleanValue()) {
//int size=((IntToken)Size.getToken()).intValue();
//Token[]_tokenArray=input.get(0,size);
output.send(0,new ArrayToken(_tokenArray));
}
}
}
public void initialize() throws IllegalActionException {
super.initialize();
}
public boolean postfire() throws IllegalActionException {
return super.postfire();
}
///////////////////////////////////////////////////////////////////
//// private variable ////
private Token []_tokenArray ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -