21
21
22
22
#include < lsp-plug.in/dsp/dsp.h>
23
23
#include < lsp-plug.in/dsp-units/util/MeterGraph.h>
24
+ #include < lsp-plug.in/stdlib/math.h>
24
25
25
26
namespace lsp
26
27
{
@@ -43,7 +44,7 @@ namespace lsp
43
44
fCurrent = 0 .0f ;
44
45
nCount = 0 ;
45
46
nPeriod = 1 ;
46
- bMinimize = false ;
47
+ enMethod = MM_ABS_MAXIMUM ;
47
48
}
48
49
49
50
void MeterGraph::destroy ()
@@ -67,21 +68,31 @@ namespace lsp
67
68
68
69
void MeterGraph::process (float sample)
69
70
{
70
- // Make sample positive
71
- if (sample < 0 .0f )
72
- sample = - sample;
73
-
74
- if (bMinimize)
75
- {
76
- // Update current sample
77
- if ((nCount == 0 ) || (fCurrent < sample))
78
- fCurrent = sample;
79
- }
80
- else
71
+ // Update current sample
72
+ switch (enMethod)
81
73
{
82
- // Update current sample
83
- if ((nCount == 0 ) || (fCurrent > sample))
84
- fCurrent = sample;
74
+ case MM_SIGN_MINIMUM:
75
+ if ((nCount == 0 ) || (fabsf (fCurrent ) > fabsf (sample)))
76
+ fCurrent = sample;
77
+ break ;
78
+
79
+ case MM_SIGN_MAXIMUM:
80
+ if ((nCount == 0 ) || (fabsf (fCurrent ) < fabsf (sample)))
81
+ fCurrent = sample;
82
+ break ;
83
+
84
+ case MM_ABS_MINIMUM:
85
+ sample = fabsf (sample);
86
+ if ((nCount == 0 ) || (fCurrent > sample))
87
+ fCurrent = sample;
88
+ break ;
89
+
90
+ default :
91
+ case MM_ABS_MAXIMUM:
92
+ sample = fabsf (sample);
93
+ if ((nCount == 0 ) || (fCurrent < sample))
94
+ fCurrent = sample;
95
+ break ;
85
96
}
86
97
87
98
// Increment number of samples processed
@@ -95,128 +106,120 @@ namespace lsp
95
106
96
107
void MeterGraph::process (const float *s, size_t n)
97
108
{
98
- if (bMinimize )
109
+ while (n > 0 )
99
110
{
100
- while (n > 0 )
101
- {
102
- // Determine amount of samples to process
103
- ssize_t can_do = lsp_min (ssize_t (n), ssize_t (nPeriod - nCount));
111
+ // Determine amount of samples to process
112
+ ssize_t can_do = lsp_min (ssize_t (n), ssize_t (nPeriod - nCount));
104
113
105
- // Process the samples
106
- if (can_do > 0 )
114
+ // Process the samples
115
+ if (can_do > 0 )
116
+ {
117
+ // Process samples
118
+ switch (enMethod)
107
119
{
108
- // Get maximum sample
109
- float sample = dsp::abs_min (s, can_do);
110
- if ((nCount == 0 ) || (fCurrent > sample))
111
- fCurrent = sample;
112
-
113
- // Update counters and pointers
114
- nCount += can_do;
115
- n -= can_do;
116
- s += can_do;
120
+ case MM_SIGN_MINIMUM:
121
+ {
122
+ const float sample = dsp::sign_min (s, can_do);
123
+ if ((nCount == 0 ) || (fabsf (fCurrent ) > fabsf (sample)))
124
+ fCurrent = sample;
125
+ break ;
126
+ }
127
+ case MM_SIGN_MAXIMUM:
128
+ {
129
+ const float sample = dsp::sign_max (s, can_do);
130
+ if ((nCount == 0 ) || (fabsf (fCurrent ) < fabsf (sample)))
131
+ fCurrent = sample;
132
+ break ;
133
+ }
134
+ case MM_ABS_MINIMUM:
135
+ {
136
+ const float sample = dsp::abs_min (s, can_do);
137
+ if ((nCount == 0 ) || (fCurrent > sample))
138
+ fCurrent = sample;
139
+ break ;
140
+ }
141
+ default :
142
+ case MM_ABS_MAXIMUM:
143
+ {
144
+ const float sample = dsp::abs_max (s, can_do);
145
+ if ((nCount == 0 ) || (fCurrent > sample))
146
+ fCurrent = sample;
147
+ break ;
148
+ }
117
149
}
118
150
119
- // Check that need to switch to next sample
120
- if (nCount >= nPeriod)
121
- {
122
- // Append current sample to buffer
123
- sBuffer .process (fCurrent );
124
- nCount = 0 ;
125
- }
151
+ // Update counters and pointers
152
+ nCount += can_do;
153
+ n -= can_do;
154
+ s += can_do;
126
155
}
127
- }
128
- else
129
- {
130
- while (n > 0 )
131
- {
132
- // Determine amount of samples to process
133
- ssize_t can_do = lsp_min (ssize_t (n), ssize_t (nPeriod - nCount));
134
156
135
- // Process the samples
136
- if (can_do > 0 )
137
- {
138
- // Get maximum sample
139
- float sample = dsp::abs_max (s, can_do);
140
- if ((nCount == 0 ) || (fCurrent < sample))
141
- fCurrent = sample;
142
-
143
- // Update counters and pointers
144
- nCount += can_do;
145
- n -= can_do;
146
- s += can_do;
147
- }
148
-
149
- // Check that need to switch to next sample
150
- if (nCount >= nPeriod)
151
- {
152
- // Append current sample to buffer and update counter
153
- sBuffer .process (fCurrent );
154
- nCount = 0 ;
155
- }
157
+ // Check that need to switch to next sample
158
+ if (nCount >= nPeriod)
159
+ {
160
+ // Append current sample to buffer
161
+ sBuffer .process (fCurrent );
162
+ nCount = 0 ;
156
163
}
157
164
}
158
165
}
159
166
160
167
void MeterGraph::process (const float *s, float gain, size_t n)
161
168
{
162
- if (bMinimize )
169
+ while (n > 0 )
163
170
{
164
- while (n > 0 )
165
- {
166
- // Determine amount of samples to process
167
- ssize_t can_do = lsp_min (ssize_t (n), ssize_t (nPeriod - nCount));
171
+ // Determine amount of samples to process
172
+ ssize_t can_do = lsp_min (ssize_t (n), ssize_t (nPeriod - nCount));
168
173
169
- // Process the samples
170
- if (can_do > 0 )
174
+ // Process the samples
175
+ if (can_do > 0 )
176
+ {
177
+ // Process samples
178
+ switch (enMethod)
171
179
{
172
- // Get maximum sample
173
- float sample = dsp::abs_min (s, can_do) * gain;
174
- if ((nCount == 0 ) || (fCurrent > sample))
175
- fCurrent = sample;
176
-
177
- // Update counters and pointers
178
- nCount += can_do;
179
- n -= can_do;
180
- s += can_do;
180
+ case MM_SIGN_MINIMUM:
181
+ {
182
+ const float sample = dsp::sign_min (s, can_do) * gain;
183
+ if ((nCount == 0 ) || (fabsf (fCurrent ) > fabsf (sample)))
184
+ fCurrent = sample;
185
+ break ;
186
+ }
187
+ case MM_SIGN_MAXIMUM:
188
+ {
189
+ const float sample = dsp::sign_max (s, can_do) * gain;
190
+ if ((nCount == 0 ) || (fabsf (fCurrent ) < fabsf (sample)))
191
+ fCurrent = sample;
192
+ break ;
193
+ }
194
+ case MM_ABS_MINIMUM:
195
+ {
196
+ const float sample = dsp::abs_min (s, can_do) * gain;
197
+ if ((nCount == 0 ) || (fCurrent > sample))
198
+ fCurrent = sample;
199
+ break ;
200
+ }
201
+ default :
202
+ case MM_ABS_MAXIMUM:
203
+ {
204
+ const float sample = dsp::abs_max (s, can_do) * gain;
205
+ if ((nCount == 0 ) || (fCurrent > sample))
206
+ fCurrent = sample;
207
+ break ;
208
+ }
181
209
}
182
210
183
- // Check that need to switch to next sample
184
- if (nCount >= nPeriod)
185
- {
186
- // Append current sample to buffer
187
- sBuffer .process (fCurrent );
188
- nCount = 0 ;
189
- }
211
+ // Update counters and pointers
212
+ nCount += can_do;
213
+ n -= can_do;
214
+ s += can_do;
190
215
}
191
- }
192
- else
193
- {
194
- while (n > 0 )
195
- {
196
- // Determine amount of samples to process
197
- ssize_t can_do = lsp_min (ssize_t (n), ssize_t (nPeriod - nCount));
198
-
199
- // Process the samples
200
- if (can_do > 0 )
201
- {
202
- // Get maximum sample
203
- float sample = dsp::abs_max (s, can_do) * gain;
204
- if ((nCount == 0 ) || (fCurrent < sample))
205
- fCurrent = sample;
206
-
207
- // Update counters and pointers
208
- nCount += can_do;
209
- n -= can_do;
210
- s += can_do;
211
- }
212
216
213
- // Check that need to switch to next sample
214
- if (nCount >= nPeriod)
215
- {
216
- // Append current sample to buffer and update counter
217
- sBuffer .process (fCurrent );
218
- nCount = 0 ;
219
- }
217
+ // Check that need to switch to next sample
218
+ if (nCount >= nPeriod)
219
+ {
220
+ // Append current sample to buffer
221
+ sBuffer .process (fCurrent );
222
+ nCount = 0 ;
220
223
}
221
224
}
222
225
}
@@ -227,7 +230,7 @@ namespace lsp
227
230
v->write (" fCurrent" , fCurrent );
228
231
v->write (" nCount" , nCount);
229
232
v->write (" nPeriod" , nPeriod);
230
- v->write (" bMinimize " , bMinimize );
233
+ v->write (" enMethod " , enMethod );
231
234
}
232
235
} /* namespace dspu */
233
236
} /* namespace lsp */
0 commit comments