Skip to content

Commit 98af049

Browse files
authored
milkdropwaveform samples (#456)
be safe and validate samples<2048, also don't use numsamples
1 parent 9c8d8be commit 98af049

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/libprojectM/Renderer/MilkdropWaveform.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
MilkdropWaveform::MilkdropWaveform(): RenderItem(),
1717
x(0.5), y(0.5), r(1), g(0), b(0), a(1), mystery(0), mode(Line), additive(false), dots(false), thick(false),
1818
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) {
2020

2121
Init();
2222
}
@@ -35,6 +35,13 @@ void MilkdropWaveform::InitVertexAttrib() {
3535

3636
void MilkdropWaveform::Draw(RenderContext &context)
3737
{
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+
3845
WaveformMath(context);
3946

4047
glBindBuffer(GL_ARRAY_BUFFER, m_vboID);
@@ -194,8 +201,8 @@ void MilkdropWaveform::MaximizeColors(RenderContext &context)
194201

195202
void MilkdropWaveform::WaveformMath(RenderContext &context)
196203
{
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;
199206
// scale PCM data based on vol_history to make it more or less independent of the application output volume
200207
const float vol_scale = context.beatDetect->getPCMScale();
201208

@@ -221,8 +228,6 @@ void MilkdropWaveform::WaveformMath(RenderContext &context)
221228
rot = 0;
222229
aspectScale=1.0;
223230

224-
samples = context.beatDetect->pcm->numsamples;
225-
226231
float inv_nverts_minus_one = 1.0f/(float)(samples);
227232

228233
float last_value = vol_scale * (pcmdataR[samples-1]+pcmdataL[samples-1]);
@@ -342,14 +347,11 @@ void MilkdropWaveform::WaveformMath(RenderContext &context)
342347
rot = -mystery*90;
343348
aspectScale =1.0f+wave_x_temp;
344349
wave_x_temp=-1*(x-1.0f);
345-
samples = context.beatDetect->pcm->numsamples;
346350

347-
for ( int i=0;i< samples;i++)
351+
for ( int i=0; i< samples;i++)
348352
{
349-
350353
wavearray[i][0]=i/(float) samples;
351354
wavearray[i][1]=vol_scale*pcmdataR[i]*.04f*scale+wave_x_temp;
352-
353355
}
354356
// printf("%f %f\n",renderTarget->texsize*wave_y_temp,wave_y_temp);
355357

@@ -363,8 +365,6 @@ void MilkdropWaveform::WaveformMath(RenderContext &context)
363365
rot = -mystery*90;
364366
aspectScale =1.0f+wave_x_temp;
365367

366-
367-
samples = context.beatDetect->pcm->numsamples;
368368
two_waves = true;
369369

370370
const float y_adj = y*y*.5f;

0 commit comments

Comments
 (0)