jass.generators
Class ModalObjectWithOneContact

java.lang.Object
  extended by jass.engine.Out
      extended by jass.engine.InOut
          extended by jass.generators.ModalObjectWithOneContact
All Implemented Interfaces:
Sink, Source
Direct Known Subclasses:
ModalObjectWithOneContactInterpolated, QuenchableModalObjectWithOneContact, StickyModalObjectWithOneContact

public class ModalObjectWithOneContact
extends InOut

Vibration model of object, capable of playing sound.

Author:
Kees van den Doel (kvdoel@cs.ubc.ca)

Field Summary
protected  float[] ampR
          Reson filter gain.
protected  float b1
          Current barycentric coordinates of location.
protected  float b2
          Current barycentric coordinates of location.
protected  float b3
          Current barycentric coordinates of location.
protected  float[] c_i
          Cached values.
 ModalModel modalModel
          Modal data.
protected  int p1
          Current barycentric location points.
protected  int p2
          Current barycentric location points.
protected  int p3
          Current barycentric location points.
protected  float[] R2
          The transfer function of a reson filter is H(z) = 1/(1-twoRCosTheta/z + R2/z*z).
protected  float rollGain
           
 float srate
          Sampling rate in Hertz.
protected  float[] tmpBuf
          Temp storage
protected  float[] twoRCosTheta
          The transfer function of a reson filter is H(z) = 1/(1-twoRCosTheta/z + R2/z*z).
protected  float[] yt_1
          State of filters.
protected  float[] yt_2
          State of filters.
 
Fields inherited from class jass.engine.InOut
sourceContainer, sourcePassivity, srcBuffers
 
Fields inherited from class jass.engine.Out
buf, bufferSize, bufOld, lock
 
Constructor Summary
ModalObjectWithOneContact(float srate, int nf, int np, int bufferSize)
          Create and initialize, but don't set any modal parameters.
ModalObjectWithOneContact(int bufferSize)
          Constructor for derived classes to call super
ModalObjectWithOneContact(ModalModel m, float srate, int bufferSize)
          Create and initialize with provided modal data.
 
Method Summary
 java.lang.Object addSource(Source s)
          Add a Source.
protected  void allocate(int nf, int np)
          Allocate data.
 void clearHistory()
          Set state to non-vibrating.
protected  void computeBuffer()
          Compute the next buffer and store in member float[] buf.
 void computeFilter()
          Compute the filter coefficients used for real-time rendering from the modal model parameters.
protected  void computeLocation()
          Compute gains.
protected  void computeModalFilterBank(float[] output, float[] force, int nsamples)
          Apply external force[] and compute response through bank of modal filters.
 void computeResonCoeff()
          Compute the reson coefficients from the modal model parameters.
 void setDamping(float dscale)
          Scale dampings.
 void setFrequencyScale(float fscale)
          Scale frequencies.
 void setGain(float a)
          Scale gains.
 void setLocation(int p1, int p2, int p3, float b1, float b2, float b3)
          Compute the gain coefficients from the modal model parameters at point p, given inside triangle of point p1,p2,p3, with barycentric coordinated b1,b2,b3
 void setNf(int nf)
          Reduce number of modes used.
 
Methods inherited from class jass.engine.InOut
addSource, getBuffer, getSources, removeSource, resetTime
 
Methods inherited from class jass.engine.Out
clearBuffer, copyToOld, getBuffer, getBufferSize, getTime, peekAtBuffer, setBufferSize, setTime, setTimeAndNotify
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

srate

public float srate
Sampling rate in Hertz.


modalModel

public ModalModel modalModel
Modal data.


p1

protected int p1
Current barycentric location points.


p2

protected int p2
Current barycentric location points.


p3

protected int p3
Current barycentric location points.


b1

protected float b1
Current barycentric coordinates of location.


b2

protected float b2
Current barycentric coordinates of location.


b3

protected float b3
Current barycentric coordinates of location.


yt_1

protected float[] yt_1
State of filters.


yt_2

protected float[] yt_2
State of filters.


R2

protected float[] R2
The transfer function of a reson filter is H(z) = 1/(1-twoRCosTheta/z + R2/z*z).


twoRCosTheta

protected float[] twoRCosTheta
The transfer function of a reson filter is H(z) = 1/(1-twoRCosTheta/z + R2/z*z).


ampR

protected float[] ampR
Reson filter gain.


c_i

protected float[] c_i
Cached values.


tmpBuf

protected float[] tmpBuf
Temp storage


rollGain

protected float rollGain
Constructor Detail

ModalObjectWithOneContact

public ModalObjectWithOneContact(int bufferSize)
Constructor for derived classes to call super

Parameters:
bufferSize - Buffer size used for real-time rendering.

ModalObjectWithOneContact

public ModalObjectWithOneContact(float srate,
                                 int nf,
                                 int np,
                                 int bufferSize)
Create and initialize, but don't set any modal parameters.

Parameters:
srate - sampling rate in Hertz.
nf - number of modes.
np - number of locations.
bufferSize - Buffer size used for real-time rendering.

ModalObjectWithOneContact

public ModalObjectWithOneContact(ModalModel m,
                                 float srate,
                                 int bufferSize)
Create and initialize with provided modal data.

Parameters:
m - modal model to load.
srate - sampling rate in Hertz.
bufferSize - Buffer size used for real-time rendering.
Method Detail

addSource

public java.lang.Object addSource(Source s)
                           throws SinkIsFullException
Add a Source. Overrides Sink interface implementation from InOut. Allow only one Source.

Specified by:
addSource in interface Sink
Overrides:
addSource in class InOut
Parameters:
s - Source to add.
Returns:
object representing Source in Sink (may be null).
Throws:
SinkIsFullException

setDamping

public void setDamping(float dscale)
Scale dampings.

Parameters:
d - damping scale.

setGain

public void setGain(float a)
Scale gains.

Parameters:
a - gain scale.

setFrequencyScale

public void setFrequencyScale(float fscale)
Scale frequencies.

Parameters:
fscale - frequency scale.

setNf

public void setNf(int nf)
Reduce number of modes used.

Parameters:
nf - number of modes to use.

allocate

protected void allocate(int nf,
                        int np)
Allocate data.

Parameters:
nf - number of modes.
np - number of locations.

computeFilter

public void computeFilter()
Compute the filter coefficients used for real-time rendering from the modal model parameters.


computeResonCoeff

public void computeResonCoeff()
Compute the reson coefficients from the modal model parameters. Cache values used in setLocation(int, int, int, float, float, float).


computeLocation

protected void computeLocation()
Compute gains. Check also if any frequency is above Nyquist rate. If so set its gain to zero.


setLocation

public void setLocation(int p1,
                        int p2,
                        int p3,
                        float b1,
                        float b2,
                        float b3)
Compute the gain coefficients from the modal model parameters at point p, given inside triangle of point p1,p2,p3, with barycentric coordinated b1,b2,b3

Parameters:
p1 - location index 1.
p2 - location index 2.
p3 - location index 3.
b1 - barycentric coordinate 1.
b2 - barycentric coordinate 2.
b3 - barycentric coordinate 3.

clearHistory

public void clearHistory()
Set state to non-vibrating.


computeBuffer

protected void computeBuffer()
Compute the next buffer and store in member float[] buf.

Specified by:
computeBuffer in class Out

computeModalFilterBank

protected void computeModalFilterBank(float[] output,
                                      float[] force,
                                      int nsamples)
Apply external force[] and compute response through bank of modal filters.

Parameters:
output - user provided output buffer.
force - input force.
nsamples - number of samples to compute.