Skip to content

Commit a57a0ec

Browse files
authored
Update audio_stream_effects.c (#3618)
* Update audio_stream_effects.c This may slightly improve performance and be more welcoming for new users despite being an more advanced feature. void * usually throws an error in most compilers and it would be better to just avoid it. Also added <stdbool.h> because booleans are, sometimes, not defined by <stddef.h>. * Update audio_stream_effects.c
1 parent 9322ad0 commit a57a0ec

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

examples/audio/audio_stream_effects.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* raylib [audio] example - Music stream processing effects
44
*
5-
* Example originally created with raylib 4.2, last time updated with raylib 4.2
5+
* Example originally created with raylib 4.2, last time updated with raylib 5.0
66
*
77
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
88
* BSD-like license that allows static linking with closed source software
@@ -13,7 +13,7 @@
1313

1414
#include "raylib.h"
1515

16-
#include <stdlib.h> // Required for: NULL
16+
#include <stdlib.h> // Required for: NULL
1717

1818
// Required delay effect variables
1919
static float *delayBuffer = NULL;
@@ -149,13 +149,17 @@ static void AudioProcessEffectLPF(void *buffer, unsigned int frames)
149149
static const float cutoff = 70.0f / 44100.0f; // 70 Hz lowpass filter
150150
const float k = cutoff / (cutoff + 0.1591549431f); // RC filter formula
151151

152+
// Converts the buffer data before using it
153+
float *bufferData = (float *)buffer;
152154
for (unsigned int i = 0; i < frames*2; i += 2)
153155
{
154-
float l = ((float *)buffer)[i], r = ((float *)buffer)[i + 1];
156+
const float l = bufferData[i];
157+
const float r = bufferData[i + 1];
158+
155159
low[0] += k * (l - low[0]);
156160
low[1] += k * (r - low[1]);
157-
((float *)buffer)[i] = low[0];
158-
((float *)buffer)[i + 1] = low[1];
161+
bufferData[i] = low[0];
162+
bufferData[i + 1] = low[1];
159163
}
160164
}
161165

@@ -176,4 +180,4 @@ static void AudioProcessEffectDelay(void *buffer, unsigned int frames)
176180
delayBuffer[delayWriteIndex++] = ((float *)buffer)[i + 1];
177181
if (delayWriteIndex == delayBufferSize) delayWriteIndex = 0;
178182
}
179-
}
183+
}

0 commit comments

Comments
 (0)