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

« back to all changes in this revision

Viewing changes to synti/stklib/PRCRev.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
/* PRCRev, a simple reverb unit            */
 
3
/* by Perry Cook, 1996.                    */
 
4
/* Incorporated into the Reverb superclass */
 
5
/* by Gary Scavone, 1998.                  */
 
6
/*                                         */
 
7
/* This is based on some of the famous     */
 
8
/* Stanford CCRMA reverbs (NRev, KipRev)   */
 
9
/* all based on the the Chowning/Moorer/   */
 
10
/* Schroeder reverberators, which use      */
 
11
/* networks of simple allpass and comb     */
 
12
/* delay filters.  This particular         */
 
13
/* structure consists of 2 allpass units   */
 
14
/* in series followed by 2 comb filters in */
 
15
/* parallel.                               */
 
16
/*******************************************/
 
17
 
 
18
#include "PRCRev.h"
 
19
 
 
20
PRCRev :: PRCRev(MY_FLOAT T60)
 
21
{
 
22
  int lens[4]={353,1097,1777,2137};
 
23
  double srscale = SRATE / 44100.0;
 
24
  int val, i;
 
25
 
 
26
  if (SRATE < 44100.0) {
 
27
        for (i=0; i<4; i++)     {
 
28
          val = (int) floor(srscale * lens[i]);
 
29
          if ((val & 1) == 0) val++;
 
30
          while (!this->isprime(val)) val += 2;
 
31
          lens[i] = val;
 
32
        }
 
33
  }
 
34
  for (i=0; i<2; i++)
 
35
        {
 
36
          APdelayLine[i] = new DLineN(lens[i] + 2);
 
37
          APdelayLine[i]->setDelay(lens[i]);
 
38
          CdelayLine[i] = new DLineN(lens[i+2] + 2);
 
39
          CdelayLine[i]->setDelay(lens[i+2]);
 
40
          combCoeff[i] = pow(10,(-3 * lens[i+2] / (T60 * SRATE)));
 
41
        }
 
42
 
 
43
  allPassCoeff = (MY_FLOAT) 0.7;
 
44
  effectMix = (MY_FLOAT) 0.5;
 
45
  this->clear();
 
46
}
 
47
 
 
48
PRCRev :: ~PRCRev()
 
49
{
 
50
  delete APdelayLine[0];
 
51
  delete APdelayLine[1];
 
52
  delete CdelayLine[0];
 
53
  delete CdelayLine[1];
 
54
}
 
55
 
 
56
void PRCRev :: clear()
 
57
{
 
58
  APdelayLine[0]->clear();
 
59
  APdelayLine[1]->clear();
 
60
  CdelayLine[0]->clear();
 
61
  CdelayLine[1]->clear();
 
62
  lastOutL = (MY_FLOAT) 0.0;
 
63
  lastOutR = (MY_FLOAT) 0.0;
 
64
}
 
65
 
 
66
void PRCRev :: setEffectMix(MY_FLOAT mix)
 
67
{
 
68
  effectMix = mix;
 
69
}
 
70
 
 
71
MY_FLOAT PRCRev :: lastOutput()
 
72
{
 
73
  return (lastOutL + lastOutR) * (MY_FLOAT) 0.5;
 
74
}
 
75
 
 
76
MY_FLOAT PRCRev :: lastOutputL()
 
77
{
 
78
  return lastOutL;
 
79
}
 
80
 
 
81
MY_FLOAT PRCRev :: lastOutputR()
 
82
{
 
83
  return lastOutR;
 
84
}
 
85
 
 
86
MY_FLOAT PRCRev :: tick(MY_FLOAT input)
 
87
{
 
88
  MY_FLOAT temp,temp0,temp1,temp2,temp3;
 
89
 
 
90
  temp = APdelayLine[0]->lastOut();
 
91
  temp0 = allPassCoeff * temp;
 
92
  temp0 += input;
 
93
  APdelayLine[0]->tick(temp0);
 
94
  temp0 = -(allPassCoeff * temp0) + temp;
 
95
    
 
96
  temp = APdelayLine[1]->lastOut();
 
97
  temp1 = allPassCoeff * temp;
 
98
  temp1 += temp0;
 
99
  APdelayLine[1]->tick(temp1);
 
100
  temp1 = -(allPassCoeff * temp1) + temp;
 
101
    
 
102
  temp2 = temp1 + (combCoeff[0] * CdelayLine[0]->lastOut());
 
103
  temp3 = temp1 + (combCoeff[1] * CdelayLine[1]->lastOut());
 
104
 
 
105
  lastOutL = effectMix * (CdelayLine[0]->tick(temp2));
 
106
  lastOutR = effectMix * (CdelayLine[1]->tick(temp3));
 
107
  temp = (MY_FLOAT) (1.0 - effectMix) * input;
 
108
  lastOutL += temp;
 
109
  lastOutR += temp;
 
110
    
 
111
  return (lastOutL + lastOutR) * (MY_FLOAT) 0.5;
 
112
 
 
113
}