Tweaking the audio mixer for redundant cycles
@@ -64,9 +64,10 @@ void AUDIO_ENGINE_mix(AUDIO_ENGINE* audioEngine) {
float right = 0;
for (int c = 0; c < AUDIO_CHANNEL_MAX; c++) {
AUDIO_CHANNEL* channel = (AUDIO_CHANNEL*)(audioEngine->channels[c]);
- if (channel != NULL && channel->enabled) {
- totalEnabled++;
+ if (channel != NULL) {
AUDIO_DATA* audio = channel->audio;
+ if (channel->enabled) {
+ totalEnabled++;
float* readCursor = (float*)(audio->buffer);
readCursor += channel->position * channels;
float volume = channel->volume;
@@ -74,11 +75,12 @@ void AUDIO_ENGINE_mix(AUDIO_ENGINE* audioEngine) {
left += readCursor[0] * cos(pan) * volume;
right += readCursor[1] * sin(pan) * volume;
+ }
channel->position++;
if (channel->loop && channel->position >= audio->length) {
channel->position = 0;
}
- channel->enabled = channel->position < audio->length;
+ channel->enabled = channel->enabled && channel->position < audio->length;
}
}
if (totalEnabled > 1) {
