-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImpulseGen.cpp
More file actions
74 lines (64 loc) · 1.77 KB
/
ImpulseGen.cpp
File metadata and controls
74 lines (64 loc) · 1.77 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
/*
VocoderSynth is a DSP plugin.
Copyright 2024 Tim Krause
This file is part of VocoderSynth
VocoderSynth is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
VocoderSynth is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with VocoderSynth. If not, see
<https://www.gnu.org/licenses/>.
Contact: tim.krause@twkrause.ca
*/
#include "ImpulseGen.h"
ImpulseGen::ImpulseGen(void)
{
for(int i=0;i<N_SINC_WINDOW;i++){
accumulator[i] = 0.0f;
}
i_acc = 0;
Tacc = 0.0f;
Tperiod = 96.0f;
}
void ImpulseGen::Impulse(float alpha)
{
int i_ss = (int)(alpha * N_SINC_SS);
float *p_impulse = sincTable.data[i_ss];
float *p_acc = &accumulator[i_acc];
int N_loop1 = N_SINC_WINDOW - i_acc;
int N_loop2 = i_acc;
for(int i=0;i<N_loop1;i++){
*(p_acc++) += *(p_impulse++);
}
if(N_loop2){
p_acc = accumulator;
for(int i=0;i<N_loop2;i++){
*(p_acc++) += *(p_impulse++);
}
}
}
float ImpulseGen::Evaluate(void)
{
float deltaT = Tacc - Tperiod;
float result;
if(deltaT <= -1.0f){
Tacc += 1.0f;
}else if(deltaT <= 0.0f){
Impulse(-deltaT);
Tacc = 1.0f + deltaT;
}else{
Impulse(0.0f);
Tacc = 0.0f;
}
result = accumulator[i_acc];
accumulator[i_acc] = 0.0f;
i_acc++;
if(i_acc == N_SINC_WINDOW)
i_acc = 0;
return result;
}