@@ -33,7 +33,107 @@ public JAIDSPEnvelope(JEnvelopeVector[] env, short init, bool dbg = false)
33
33
debug = dbg ;
34
34
swapNextVector ( ) ;
35
35
}
36
+ public static readonly float [ ] CURVE_LINEAR = {
37
+ 1.0f ,
38
+ 0.9375f ,
39
+ 0.875f ,
40
+ 0.8125f ,
41
+ 0.75f ,
42
+ 0.6875f ,
43
+ 0.625f ,
44
+ 0.5625f ,
45
+ 0.5f ,
46
+ 0.4375f ,
47
+ 0.375f ,
48
+ 0.3125f ,
49
+ 0.25f ,
50
+ 0.1875f ,
51
+ 0.125f ,
52
+ 0.0625f ,
53
+ 0
54
+ } ;
55
+
56
+ public static readonly float [ ] CURVE_SQUAREROOT = {
57
+ 1.0f ,
58
+ 0.878906f ,
59
+ 0.765625f ,
60
+ 0.660156f ,
61
+ 0.5625f ,
62
+ 0.472656f ,
63
+ 0.390625f ,
64
+ 0.316406f ,
65
+ 0.25f ,
66
+ 0.191406f ,
67
+ 0.140625f ,
68
+ 0.097656f ,
69
+ 0.0625f ,
70
+ 0.0351562f ,
71
+ 0.015625f ,
72
+ 0.00390625f ,
73
+ 0
74
+ } ;
75
+
76
+ public static readonly float [ ] CURVE_SQUARE = {
77
+ 1.0f ,
78
+ 0.96824598f ,
79
+ 0.935414f ,
80
+ 0.90138799f ,
81
+ 0.86602497f ,
82
+ 0.82915598f ,
83
+ 0.790569f ,
84
+ 0.75f ,
85
+ 0.707107f ,
86
+ 0.66143799f ,
87
+ 0.61237198f ,
88
+ 0.559017f ,
89
+ 0.5f ,
90
+ 0.43301299f ,
91
+ 0.353553f ,
92
+ 0.25f ,
93
+ 0
94
+ } ;
95
+
96
+ public static readonly float [ ] CURVE_SAMPLECELL = {
97
+ 1.0f ,
98
+ 0.970489f ,
99
+ 0.781274f ,
100
+ 0.54628098f ,
101
+ 0.39979199f ,
102
+ 0.28931499f ,
103
+ 0.21210399f ,
104
+ 0.15747599f ,
105
+ 0.112613f ,
106
+ 0.081789598f ,
107
+ 0.0579852f ,
108
+ 0.0436415f ,
109
+ 0.0308237f ,
110
+ 0.0237129f ,
111
+ 0.0152593f ,
112
+ 0.00915555f ,
113
+ 0
114
+ } ;
115
+
116
+ public static float InterpolateTable ( float [ ] curve , float depth )
117
+ {
118
+ if ( depth > 1 )
119
+ depth = 1 ;
120
+
121
+ var real = depth * ( curve . Length - 1 ) ;
122
+ var integer = ( int ) Math . Floor ( real ) ;
123
+ var frac = real - integer ;
36
124
125
+ var d1 = curve [ integer ] ;
126
+ var d2 = 0f ;
127
+ if ( integer < curve . Length - 1 )
128
+ d2 = curve [ integer + 1 ] ;
129
+
130
+ return d1 + ( d2 - d1 ) * frac ;
131
+ }
132
+
133
+ public static float InterpolateTableInverse ( float [ ] curve , float depth )
134
+ {
135
+ return 1f - InterpolateTable ( curve , depth ) ;
136
+ }
37
137
private void swapNextVector ( )
38
138
{
39
139
@@ -52,7 +152,7 @@ private void swapNextVector()
52
152
var envVal = eVector . value ;
53
153
valueDelta = envVal - Value ;
54
154
lastValue = Value ;
55
-
155
+
56
156
if ( eVector . time == 0 )
57
157
{
58
158
Value = eVector . value ;
@@ -76,34 +176,32 @@ public unsafe bool update(double ms)
76
176
swapNextVector ( ) ;
77
177
return false ;
78
178
}
79
-
80
- var deltaDepth = lastDuration - currentDuration ;
81
- var fdeltaDepth = deltaDepth / lastDuration ;
82
179
83
- if ( fdeltaDepth > 1 )
84
- fdeltaDepth = 1f ;
180
+ var deltaDepth = lastDuration - currentDuration ;
181
+ var fdeltaDepth = ( float ) ( deltaDepth / lastDuration ) ;
85
182
86
- switch ( currentMode )
87
- {
88
- case JEnvelopeVectorMode . Linear :
89
- Value = ( short ) ( lastValue + ( valueDelta * fdeltaDepth ) ) ;
90
- break ;
91
- case JEnvelopeVectorMode . Square :
92
- Value = ( short ) ( lastValue + valueDelta * Math . Pow ( fdeltaDepth , 2 ) ) ;
93
- break ;
94
- case JEnvelopeVectorMode . SampleCell :
95
- Value = ( short ) ( lastValue + valueDelta * ( Math . Pow ( fdeltaDepth - 1 , 3 ) + 1f ) ) ;
96
- break ;
97
- case JEnvelopeVectorMode . SqRoot :
98
- Value = ( short ) ( lastValue + valueDelta * Math . Sqrt ( fdeltaDepth ) ) ;
99
- break ;
100
-
101
- }
183
+ if ( fdeltaDepth > 1 )
184
+ fdeltaDepth = 1f ;
185
+ var table = CURVE_LINEAR ;
186
+
187
+ switch ( currentMode )
188
+ {
189
+ case JEnvelopeVectorMode . Square :
190
+ table = CURVE_SQUARE ;
191
+ break ;
192
+ case JEnvelopeVectorMode . SampleCell :
193
+ table = CURVE_SAMPLECELL ;
194
+ break ;
195
+ case JEnvelopeVectorMode . SqRoot :
196
+ table = CURVE_SQUAREROOT ;
197
+ break ;
198
+ }
102
199
103
- fValue = ( float ) Value / ( float ) 0x7FFF ;
200
+ Value = ( short ) ( lastValue + valueDelta * InterpolateTableInverse ( table , fdeltaDepth ) ) ;
201
+ fValue = Value / 32767f ;
104
202
105
203
if ( currentDuration > 0 )
106
- currentDuration -= ms ;
204
+ currentDuration -= ms ;
107
205
else
108
206
swapNextVector ( ) ;
109
207
0 commit comments