~ubuntu-branches/ubuntu/oneiric/muse/oneiric

« back to all changes in this revision

Viewing changes to synti/stklib/LipFilt.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2002-04-23 17:28:23 UTC
  • Revision ID: james.westby@ubuntu.com-20020423172823-w8yplzr81a759xa3
Tags: upstream-0.5.2
ImportĀ upstreamĀ versionĀ 0.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/************************************************/
 
2
/*  Lip Filter Object by Perry R. Cook, 1995-96 */
 
3
/*  The lip of the brass player has dynamics    */
 
4
/*  which are controlled by the mass, spring    */
 
5
/*  constant, and damping of the lip.  This     */
 
6
/*  filter simulates that behavior and the      */
 
7
/*  transmission/reflection properties as       */
 
8
/*  well.  See Cook TBone and HosePlayer        */
 
9
/*  instruments and articles.                   */
 
10
/************************************************/
 
11
 
 
12
#include "LipFilt.h"
 
13
 
 
14
LipFilt :: LipFilt()
 
15
{
 
16
  MY_FLOAT coeffs[2];
 
17
  filter = new BiQuad;
 
18
  coeffs[0] = (MY_FLOAT) 0.0;
 
19
  coeffs[1] = (MY_FLOAT) 0.0;
 
20
  filter->setZeroCoeffs(coeffs);
 
21
  this->clear();
 
22
}
 
23
 
 
24
LipFilt :: ~LipFilt()
 
25
{
 
26
  delete filter;
 
27
}
 
28
 
 
29
void LipFilt :: clear()
 
30
{
 
31
  filter->clear();
 
32
  lastOutput = (MY_FLOAT) 0.0;
 
33
}
 
34
 
 
35
void LipFilt :: setFreq(MY_FLOAT frequency)
 
36
{
 
37
  MY_FLOAT coeffs[2];
 
38
  coeffs[0] = (MY_FLOAT) 2.0 * (MY_FLOAT) 0.997 * 
 
39
                (MY_FLOAT)  cos(TWO_PI * frequency / SRATE);      /* damping should change with  */
 
40
  coeffs[1] = (MY_FLOAT) (-0.997 * 0.997);  /* lip parameters, but not yet.*/
 
41
  filter->setPoleCoeffs(coeffs);                             
 
42
  filter->setGain((MY_FLOAT) 0.03);
 
43
}
 
44
 
 
45
/*  NOTE:  Here we should add lip tension            */
 
46
/*         settings based on Mass/Spring/Damping     */
 
47
 
 
48
MY_FLOAT LipFilt :: tick(MY_FLOAT mouthSample,MY_FLOAT boreSample)    
 
49
                /*   Perform "Table Lookup" By Polynomial Calculation */
 
50
{
 
51
  MY_FLOAT temp;
 
52
  temp = mouthSample - boreSample;          /* Differential pressure */
 
53
  temp = filter->tick(temp);                /* Force -> position     */
 
54
  temp = temp*temp;                         /* Simple position to area mapping */
 
55
  if (temp > 1.0) temp = (MY_FLOAT) 1.0;    /* Saturation at + 1.0             */
 
56
  lastOutput = temp * mouthSample;          /* Assume mouth input = area       */
 
57
  lastOutput += ((MY_FLOAT) 1.0 - temp) * boreSample;  /* and Bore reflection is compliment. */
 
58
  return lastOutput;
 
59
}
 
60
 
 
61
MY_FLOAT LipFilt :: lastOut()
 
62
{
 
63
  return lastOutput;
 
64
}
 
65