16
16
MilkdropWaveform::MilkdropWaveform (): RenderItem(),
17
17
x(0.5 ), y(0.5 ), r(1 ), g(0 ), b(0 ), a(1 ), mystery(0 ), mode(Line), additive(false ), dots(false ), thick(false ),
18
18
modulateAlphaByVolume(false ), maximizeColors(false ), scale(10 ), smoothing(0 ),
19
- modOpacityStart(0 ), modOpacityEnd(1 ), rot(0 ), samples(0 ), loop(false ) {
19
+ modOpacityStart(0 ), modOpacityEnd(1 ), rot(0 ), samples(512 ), loop(false ) {
20
20
21
21
Init ();
22
22
}
@@ -35,6 +35,13 @@ void MilkdropWaveform::InitVertexAttrib() {
35
35
36
36
void MilkdropWaveform::Draw (RenderContext &context)
37
37
{
38
+ // wavearray is 2048 so don't exceed that
39
+ // TODO use named constant
40
+ if (samples > 2048 )
41
+ samples = 2048 ;
42
+ if (samples > (int )PCM::maxsamples)
43
+ samples = (int )PCM::maxsamples;
44
+
38
45
WaveformMath (context);
39
46
40
47
glBindBuffer (GL_ARRAY_BUFFER, m_vboID);
@@ -194,8 +201,8 @@ void MilkdropWaveform::MaximizeColors(RenderContext &context)
194
201
195
202
void MilkdropWaveform::WaveformMath (RenderContext &context)
196
203
{
197
- float *pcmdataR = context.beatDetect ->pcm ->pcmdataR ;
198
- float *pcmdataL = context.beatDetect ->pcm ->pcmdataL ;
204
+ const float *pcmdataR = context.beatDetect ->pcm ->pcmdataR ;
205
+ const float *pcmdataL = context.beatDetect ->pcm ->pcmdataL ;
199
206
// scale PCM data based on vol_history to make it more or less independent of the application output volume
200
207
const float vol_scale = context.beatDetect ->getPCMScale ();
201
208
@@ -221,8 +228,6 @@ void MilkdropWaveform::WaveformMath(RenderContext &context)
221
228
rot = 0 ;
222
229
aspectScale=1.0 ;
223
230
224
- samples = context.beatDetect ->pcm ->numsamples ;
225
-
226
231
float inv_nverts_minus_one = 1 .0f /(float )(samples);
227
232
228
233
float last_value = vol_scale * (pcmdataR[samples-1 ]+pcmdataL[samples-1 ]);
@@ -342,14 +347,11 @@ void MilkdropWaveform::WaveformMath(RenderContext &context)
342
347
rot = -mystery*90 ;
343
348
aspectScale =1 .0f +wave_x_temp;
344
349
wave_x_temp=-1 *(x-1 .0f );
345
- samples = context.beatDetect ->pcm ->numsamples ;
346
350
347
- for ( int i=0 ;i< samples;i++)
351
+ for ( int i=0 ; i< samples;i++)
348
352
{
349
-
350
353
wavearray[i][0 ]=i/(float ) samples;
351
354
wavearray[i][1 ]=vol_scale*pcmdataR[i]*.04f *scale+wave_x_temp;
352
-
353
355
}
354
356
// printf("%f %f\n",renderTarget->texsize*wave_y_temp,wave_y_temp);
355
357
@@ -363,8 +365,6 @@ void MilkdropWaveform::WaveformMath(RenderContext &context)
363
365
rot = -mystery*90 ;
364
366
aspectScale =1 .0f +wave_x_temp;
365
367
366
-
367
- samples = context.beatDetect ->pcm ->numsamples ;
368
368
two_waves = true ;
369
369
370
370
const float y_adj = y*y*.5f ;
0 commit comments