-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWaveGen.cpp
More file actions
802 lines (644 loc) · 18.2 KB
/
Copy pathWaveGen.cpp
File metadata and controls
802 lines (644 loc) · 18.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
// Copyright (C) 2022-2025 Theo Niessink <theo@taletn.com>
// This work is free. You can redistribute it and/or modify it under the
// terms of the Do What The Fuck You Want To Public License, Version 2,
// as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
#include "WaveGen.h"
#include <math.h>
#include <string.h>
namespace TG101 {
/* static double LFOSpeed(const int speed)
{
assert(speed >= 0 && speed <= 7);
static const char tbl[8] = { 1, 12, 19, 25, 31, 35, 37, 42 };
const int delta = tbl[speed];
int lfo = 0, timer = 0, n = 0;
while (lfo < 256)
{
timer += delta;
n++;
lfo += timer >> 10;
timer &= 1023;
}
static const double sampleRate = 9.4e+06 / 224.0;
return sampleRate / (double)n;
} */
const double WaveGen::mLFOSpeedTbl[8] =
{
0.16008104596819196, // 0.160 Hz
1.9209139299773741, // 1.921
3.0413310417658874, // 3.041
4.0019345521920384, // 4.002
4.9620770621125357, // 4.962
5.6027083730688537, // 5.603
5.9229761064623450, // 5.923
6.7228910147846386 // 6.723
};
/* static double VibratoDepth(int depth, const int sign)
{
assert(depth >= 0 && depth <= 7);
assert(sign == 0 || sign == 1);
static const char tbl[8] = { 0, 2, 3, 4, 6, 12, 24, 48 };
depth = tbl[depth] | 1024;
const double x = (double)depth / 1024.0;
const double y = !sign ? 1.0 - 1.0 / x : x - 1.0;
return y * 4.0;
} */
const double WaveGen::mVibratoDepthTbl[8][2] =
{
{ 0.0, 0.0 }, // 0.000 cent
{ 0.0077972709551656920, 0.0078125 }, // 3.378
{ 0.011684518013631938, 0.01171875 }, // 5.065
{ 0.015564202334630350, 0.015625 }, // 6.749
{ 0.023300970873786408, 0.0234375 }, // 10.114
{ 0.046332046332046332, 0.046875 }, // 20.170
{ 0.091603053435114504, 0.09375 }, // 40.108
{ 0.17910447761194030, 0.1875 } // 79.307
};
/* static double TremoloDepth(int depth)
{
assert(depth >= 0 && depth <= 7);
static const char tbl[8] = { 0, 19, 31, 39, 47, 63, 79, 127 };
depth = tbl[depth];
const double y = (double)depth / 1024.0;
return y * 2.0;
} */
const float WaveGen::mTremoloDepthTbl[8] =
{
0.0f, // 0.000 dB
0.037109375f, // 1.781
0.060546875f, // 2.906
0.076171875f, // 3.656
0.091796875f, // 4.406
0.123046875f, // 5.906
0.154296875f, // 7.406
0.248046875f // 11.91
};
/* static double EGLevel(const int idx)
{
assert(idx >= 0 && idx < 18);
return 32.0 / (double)(19 << (17 - idx));
} */
const float WaveGen::mEGLevelTbl[18] =
{
1.28495066e-05f, // -96 dB
2.56990132e-05f, // -90
5.13980263e-05f, // -84
0.000102796053f, // -78
0.000205592105f, // -72
0.000411184211f, // -66
0.000822368421f, // -60
0.00164473684f, // -54
0.00328947368f, // -48
0.00657894737f, // -42
0.0131578947f, // -36
0.0263157895f, // -30
0.0526315789f, // -24
0.105263158f, // -18
0.210526316f, // -12
0.421052632f, // -6
0.842105263f, // 0
1.68421053f // +6
};
/* static int PanMix(const int pan)
{
assert(pan >= 0 && pan <= 15);
int L = pan;
int R = 16 - pan;
L = L <= 8 ? L : 0;
R = R <= 8 ? R : 0;
L = wdl_min(L, 7);
R = wdl_min(R, 7);
return (R << 3) | L;
} */
const unsigned char WaveGen::mPanMixTbl[16] =
{
// R L
000, // 0 0 dB
001, // 0 -3
002, // 0 -6
003, // 0 -9
004, // 0 -12
005, // 0 -15
006, // 0 -18
007, // 0 -inf
077, // -inf -inf
070, // -inf 0
060, // -18 0
050, // -15 0
040, // -12 0
030, // -9 0
020, // -6 0
010 // -3 0
};
/* static double PanGain(const int pan)
{
assert(pan >= 0 && pan <= 7);
const int a = 4 - (pan & 1);
const int b = 4 << (pan >> 1);
return (double)(pan < 7 ? a : 0) / (double)b;
} */
const float WaveGen::mPanGainTbl[8] =
{
1.0f, // 0 dB
0.75f, // -3
0.5f, // -6
0.375f, // -9
0.25f, // -12
0.1875f, // -15
0.125f, // -18
0.0f // -inf
};
const float WaveGen::mReverbDepthTbl[9] =
{
0.0f, // 0: min
0.09375f, // 1
0.125f, // 2
0.1875f, // 3
0.25f, // 4
0.375f, // 5
0.5f, // 6
0.75f, // 7
1.0f // 8: max
};
/* static double AttackRate(const int idx)
{
assert(idx >= 0 && idx < 57);
const int rate = 4 + idx;
const int delta = ((rate & 3) | 4) << (rate >> 2);
int env = 672, timer = 0, n = 0;
while (env > 0)
{
timer += delta;
n++;
while (timer >= 32768)
{
env -= (env >> 4) + 1;
env = wdl_max(env, 0);
timer -= 32768;
}
}
static const double sampleRate = 9.4e+06 / 224.0;
return sampleRate * -4.3099042801755010 / (double)n;
} */
const double WaveGen::mAttackRateTbl[57] =
{
-0.65904141869208996, // 6539.66 ms
-0.82380027244635580, // 5231.73
-0.98856032693562696, // 4359.78
-1.1533172295098657, // 3736.96
-1.3180828373841799, // 3269.83
-1.6476005448927116, // 2615.87
-1.9771098473349618, // 2179.90
-2.3066197502169064, // 1868.49
-2.6361656747683598, // 1634.91
-3.2951710717384377, // 1307.95
-3.9542196946699235, // 1089.95
-4.6132395004338128, // 934.25
-5.2723313495367197, // 817.46
-6.5902220745703116, // 653.98
-7.9082664894843739, // 544.99
-9.2262436675257681, // 467.14
-10.544662699073439, // 408.73
-13.180444149140623, // 326.99
-15.816532978968748, // 272.49
-18.451546073710226, // 233.58
-21.089325398146879, // 204.36
-26.360888298281246, // 163.50
-31.630299862628127, // 136.26
-36.903092147420451, // 116.79
-42.178650796293757, // 102.18
-52.714093446373545, // 81.76
-63.260599725256254, // 68.13
-73.791127953695484, // 58.41
-84.357301592587515, // 51.09
-105.39746772407205, // 40.89
-126.47696126888646, // 34.08
-147.52206738540590, // 29.22
-168.71460318517503, // 25.55
-210.79493544814409, // 20.45
-252.95392253777291, // 17.04
-295.04413477081180, // 14.61
-337.42920637035006, // 12.77
-421.58987089628818, // 10.22
-505.20126987292634, // 8.53
-589.12721372803789, // 7.32
-674.85841274070012, // 6.39
-841.21885867212852, // 5.12
-1010.4025397458527, // 4.27
-1174.4289260682314, // 3.67
-1349.7168254814002, // 3.19
-1674.6486538380336, // 2.57
-2009.5783846056403, // 2.14
-2348.8578521364627, // 1.83
-2699.4336509628005, // 1.60
-3349.2973076760672, // 1.29
-4019.1567692112807, // 1.07
-4637.4885798591700, // 0.93
-5319.4721945443421, // 0.81
-6698.5946153521345, // 0.64
-7863.5675919351144, // 0.55
-9043.1027307253816, // 0.48
-10638.944389088684 // 0.41
};
/* static double DecayRate(const int idx)
{
assert(idx >= 0 && idx < 57);
const int rate = 4 + idx;
const int delta = ((rate & 3) | 4) << (rate >> 2);
int env = 0, timer = 0, n = 0;
while (env < 960)
{
timer += delta;
n++;
env += timer >> 15;
timer &= 32767;
}
static const double sampleRate = 9.4e+06 / 224.0;
return sampleRate / (double)n;
} */
const double WaveGen::mDecayRateTbl[57] =
{
0.010672069731212798, // 93702.54 ms
0.013340087164015997, // 74962.03
0.016008104596819196, // 62468.36
0.018676118467435493, // 53544.32
0.021344139462425595, // 46851.27
0.026680174328031994, // 37481.01
0.032016209193638393, // 31234.18
0.037352220311342677, // 26772.17
0.042688278924851190, // 23425.63
0.053360348656063988, // 18740.51
0.064032418387276786, // 15617.09
0.074704374128660896, // 13386.10
0.085376557849702381, // 11712.82
0.10672069731212798, // 9370.25
0.12806483677455357, // 7808.54
0.14940874825732179, // 6693.05
0.17075311569940476, // 5856.41
0.21344139462425595, // 4685.13
0.25612967354910714, // 3904.27
0.29881643261498711, // 3346.54
0.34150623139880952, // 2928.20
0.42688278924851190, // 2342.56
0.51225934709821429, // 1952.14
0.59762860967680245, // 1673.28
0.68301246279761905, // 1464.10
0.85376557849702381, // 1171.28
1.0245186941964286, // 976.07
1.1952572193536049, // 836.64
1.3660249255952381, // 732.05
1.7075311569940476, // 585.64
2.0490373883928571, // 488.03
2.3904463522805875, // 418.33
2.7320498511904762, // 366.03
3.4150623139880952, // 292.82
4.0980747767857143, // 244.02
4.7806203821241415, // 209.18
5.4640997023809524, // 183.01
6.8301246279761905, // 146.41
8.1961495535714286, // 122.01
9.5612407642482830, // 104.59
10.928199404761905, // 91.51
13.660249255952381, // 73.21
16.392299107142857, // 61.00
19.118125610152945, // 52.31
21.856398809523810, // 45.75
27.320498511904762, // 36.60
32.784598214285714, // 30.50
38.218839448347645, // 26.17
43.712797619047619, // 22.88
54.640997023809524, // 18.30
65.569196428571429, // 15.25
76.437678896695290, // 13.08
87.425595238095238, // 11.44
109.28199404761905, // 9.15
131.13839285714286, // 7.63
152.59740259740260, // 6.55
174.85119047619048 // 5.72
};
void WaveGen::LoadWave(const WaveTblHeader* const header, const float* const samplePtr, const double samplePeriod)
{
assert(samplePeriod > 0.0);
const int loop = header->GetLoopAddress();
const int end = header->GetEndAddress();
const int flags = mFlags & ~kFlagLoop;
mFlags = (WaveTblHeader::IsLoopable(loop, end) ? kFlagLoop : 0) | flags;
const int lfoSpeed = header->GetLFOSpeed();
const int vibDepth = header->GetVibratoDepth();
const int attack = header->GetEGAttackRate();
const int decay1 = header->GetEGDecay1Rate();
mAttackRate = attack;
mDecay1Rate = decay1;
const int decay2 = header->GetEGDecay2Rate();
const int level = header->GetEGDecayLevel();
mDecay2Rate = decay2;
const int release = header->GetEGReleaseRate();
const int scale = header->GetEGRateScale();
mReleaseRate = release;
mEGRateScale = scale;
SetLFOSpeed(lfoSpeed, samplePeriod);
SetVibratoDepth(vibDepth);
SetTremoloDepth(header->GetTremoloDepth());
const double len = (double)end;
mSampleLoop = (double)loop / len;
mSampleLen = len / (WaveTbl::GetNativeSampleRate() * samplePeriod);
mSamplePtr = samplePtr;
SetEGDecayLevel(level);
}
void WaveGen::SetEGDecayLevel(int level)
{
assert(level >= 0 && level <= 15);
level = level < 15 ? level : 31;
mDecayLevel = (double)(32 - level) * 0.03125; // 1/32
}
void WaveGen::SetPitch(const int oct, const int fNumber)
{
assert(oct >= -7 && oct <= +7);
assert(fNumber >= 0 && fNumber <= 1023);
mKeyRateScale = (oct << 1) + ((unsigned int)fNumber >> 9);
const double sampleRate = mSampleLen * 262144.0; // 1024*2^(1 + 7)
const int pitch = (fNumber | 1024) << (oct + 7);
mSamplePos.mPeriod = (double)pitch / sampleRate;
}
void WaveGen::SetLFOSpeed(const int speed, const double samplePeriod)
{
assert(speed >= 0 && speed <= 7);
assert(samplePeriod > 0.0);
mLFO.mPeriod = mLFOSpeedTbl[(unsigned int)speed] * samplePeriod;
}
void WaveGen::SetVibratoDepth(const int depth)
{
assert(depth >= 0 && depth <= 7);
const int flags = mFlags & ~kFlagVibrato;
mFlags = (depth ? kFlagVibrato : 0) | flags;
memcpy(mVibratoDepth, mVibratoDepthTbl[(unsigned int)depth], 2 * sizeof(double));
}
void WaveGen::SetTremoloDepth(const int depth)
{
assert(depth >= 0 && depth <= 7);
const int flags = mFlags & ~kFlagTremolo;
mFlags = (depth ? kFlagTremolo : 0) | flags;
mTremoloDepth = (double)mTremoloDepthTbl[(unsigned int)depth];
}
void WaveGen::SetTotalLevel(const int level, const bool smooth)
{
assert(level >= 0 && level <= 127);
const double target = (double)(level ^ 127) * 0.00390625; // 1/256
if (smooth && mTotalLevel != target)
{
assert(IsActive() == true);
mFlags |= kFlagLevelSmooth;
}
else
{
mFlags &= ~kFlagLevelSmooth;
mTotalLevel = target;
}
mLevelDirect = target;
}
void WaveGen::SetPan(const int pan)
{
assert(pan >= 0 && pan <= 15);
const unsigned int mix = mPanMixTbl[(unsigned int)pan];
mPanL = mPanGainTbl[mix & 7];
mPanR = mPanGainTbl[mix >> 3];
}
void WaveGen::SetReverbDepth(const int depth)
{
assert(depth >= 0 && depth <= 8);
mReverbDepth = mReverbDepthTbl[(unsigned int)depth];
}
void WaveGen::KeyOn(const double samplePeriod)
{
assert(samplePeriod > 0.0);
const int flags = mFlags;
if (flags & kFlagKeyOn) return;
mFlags = (kFlagKeyOn | kFlagActive) | flags;
mEGState = kEGStateAttack;
int attack = ApplyEGRateScale(mAttackRate);
mLFO.mPhase = mSamplePos.mPhase = 0.0;
if (attack < 63)
{
double rate = 0.0;
if (attack)
{
attack = wdl_min(attack, 60);
const unsigned int idx = attack - 4;
assert(/* idx >= 0 && */ idx < 57);
rate = 1.0 - exp(mAttackRateTbl[idx] * samplePeriod);
}
mEGLevel = 0.34310850439882698; // 1 - 672/1023
mEGRate = rate;
}
else
{
mEGState = kEGStateDecay1;
SetEGDecayRate(mDecay1Rate, 1.0, samplePeriod);
}
}
void WaveGen::KeyOff(const double samplePeriod)
{
assert(samplePeriod > 0.0);
const int flags = mFlags;
mFlags = flags & ~kFlagKeyOn;
if (!(flags & kFlagActive)) return;
mEGState = kEGStateRelease;
int release = ApplyEGRateScale(mReleaseRate);
double rate = 0.0;
if (release)
{
release = wdl_min(release, 60);
const unsigned int idx = release - 4;
assert(/* idx >= 0 && */ idx < 57);
rate = mDecayRateTbl[idx] * samplePeriod;
}
mEGRate = rate;
}
float WaveGen::GetSample(float* const stereo, const double samplePeriod)
{
assert(IsActive() == true);
const int flags = mFlags;
const double lfo = flags & kFlagLFO ? GetLFOPhase() : 0.0;
const double phase = mSamplePos.mPhase;
double period = mSamplePos.mPeriod;
static const int vibrato = kFlagLFO | kFlagVibrato;
if ((flags & vibrato) == vibrato) period *= GetVibrato(lfo);
double t = phase + period;
if (t >= 1.0)
{
if (!(flags & kFlagLoop)) mFlags = flags & ~kFlagActive;
t += mSampleLoop;
}
mSamplePos.mPhase = t - (double)(int)t;
float sample = WaveTbl::GetSample(mSamplePtr, phase * mSampleLen);
sample *= ProcessEG(lfo, samplePeriod);
stereo[0] = sample * mPanL;
stereo[1] = sample * mPanR;
return sample * mReverbDepth;
}
double WaveGen::GetLFOPhase()
{
const double phase = mLFO.mPhase;
const double period = mLFO.mPeriod;
const double t = phase + period;
mLFO.mPhase = t - (double)(int)t;
return phase;
}
double WaveGen::GetVibrato(double phase) const
{
assert(phase >= 0.0 && phase <= 1.0);
phase += 0.75;
phase -= (double)(int)phase;
const double triangle = fabs(phase - 0.5) - 0.25;
const unsigned int sign = triangle >= 0.0;
return mVibratoDepth[sign] * triangle + 1.0;
}
float WaveGen::ProcessEG(const double lfoPhase, const double samplePeriod)
{
const int state = mEGState;
double level = mEGLevel;
const double rate = mEGRate;
switch (state)
{
case kEGStateAttack:
{
// 1 - 672/1023*(1 - 1/(1 - exp(-4.3099042801755010)))
static const double target = 1.0089454092956391;
level += (target - level) * rate;
if (level < 1.0)
{
mEGLevel = level;
}
else
{
level = 1.0;
mEGState = kEGStateDecay1;
SetEGDecayRate(mDecay1Rate, level, samplePeriod);
}
break;
}
case kEGStateDecay1:
{
const double decayLevel = mDecayLevel;
level -= rate;
if (level > decayLevel)
{
mEGLevel = level;
}
else
{
level = decayLevel;
mEGState = kEGStateDecay2;
SetEGDecayRate(mDecay2Rate, level, samplePeriod);
}
break;
}
case kEGStateDecay2:
{
level -= rate;
level = wdl_max(level, 0.0);
mEGLevel = level;
break;
}
case kEGStateRelease:
{
level -= rate;
if (level > 0.0)
{
mEGLevel = level;
}
else
{
level = 0.0;
mFlags &= ~kFlagActive;
}
break;
}
}
static const int tremolo = kFlagLFO | kFlagTremolo;
const int flags = mFlags;
if ((flags & tremolo) == tremolo)
{
const double triangle = 0.5 - fabs(lfoPhase - 0.5);
level -= triangle * mTremoloDepth;
}
const double totalLevel = mTotalLevel;
level -= totalLevel;
level = wdl_max(level, 0.0);
if (flags & kFlagLevelSmooth)
{
SmoothTotalLevel(totalLevel, samplePeriod);
}
assert(level >= 0.0 && level <= 1.0);
// gain =~ 10^(-96*(1 - level)/20)
level = level * 16.0 + 0.1875; // 3/16
const int i = (int)level;
const float x = (float)(level - (double)i);
const float y0 = mEGLevelTbl[i];
const float y1 = mEGLevelTbl[i + 1];
const float gain = (y1 - y0) * x + y0;
return gain;
}
void WaveGen::SmoothTotalLevel(double level, const double samplePeriod)
{
assert(samplePeriod > 0.0);
const double target = mLevelDirect;
bool done;
if (level > target)
{
// rate = (9.4 MHz)/224 / (2^17/38)
static const double rate = 12.166159493582589; // 82.2 ms
level -= rate * samplePeriod;
done = level <= target;
}
else // if (level < target)
{
// rate = (9.4 MHz)/224 / (2^17/19)
static const double rate = 6.0830797467912946; // 164.4 ms
level += rate * samplePeriod;
done = level >= target;
}
if (done)
{
level = target;
mFlags &= ~kFlagLevelSmooth;
}
mTotalLevel = level;
}
void WaveGen::SetEGDecayRate(int decay, const double level, const double samplePeriod)
{
assert(samplePeriod > 0.0);
double rate = 0.0;
if (decay)
{
decay = ApplyEGRateScale(decay);
decay = wdl_min(decay, 60);
const unsigned int idx = decay - 4;
assert(/* idx >= 0 && */ idx < 57);
rate = mDecayRateTbl[idx] * samplePeriod;
}
mEGLevel = level;
mEGRate = rate;
}
int WaveGen::ApplyEGRateScale(int rate) const
{
assert(rate >= 0 && rate <= 15);
if ((unsigned int)(rate - 1) < 14)
{
rate = (unsigned int)rate << 2;
const unsigned int rateCorrection = mEGRateScale;
const int keyRateScale = mKeyRateScale;
if (rateCorrection < 15)
{
rate += (int)(rateCorrection << 1) + keyRateScale;
rate = wdl_max(rate, 4);
rate = wdl_min(rate, 63);
}
}
else
{
rate = rate ? 63 : rate;
}
return rate;
}
} // namespace TG101