From fa52c3688156dc8903a85b51f639a8ee4bb13792 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Tue, 17 Jul 2018 23:34:25 -0700 Subject: [PATCH] VGMStream plugin correctly fades channel counts other than stereo. --- Plugins/vgmstream/vgmstream/VGMDecoder.m | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Plugins/vgmstream/vgmstream/VGMDecoder.m b/Plugins/vgmstream/vgmstream/VGMDecoder.m index d83f60b1b..8faad1562 100644 --- a/Plugins/vgmstream/vgmstream/VGMDecoder.m +++ b/Plugins/vgmstream/vgmstream/VGMDecoder.m @@ -77,14 +77,16 @@ long fadeStart = (framesLength > framesRead) ? framesLength : framesRead; long fadeEnd = (framesRead + frames) > totalFrames ? totalFrames : (framesRead + frames); long fadePos; + long i; int64_t fadeScale = (int64_t)(totalFrames - fadeStart) * INT_MAX / framesFade; int64_t fadeStep = INT_MAX / framesFade; - sbuf += (fadeStart - framesRead) * 2; + sbuf += (fadeStart - framesRead) * channels; for (fadePos = fadeStart; fadePos < fadeEnd; ++fadePos) { - sbuf[ 0 ] = (int16_t)((int64_t)(sbuf[ 0 ]) * fadeScale / INT_MAX); - sbuf[ 1 ] = (int16_t)((int64_t)(sbuf[ 1 ]) * fadeScale / INT_MAX); - sbuf += 2; + for (i = 0; i < channels; ++i) { + sbuf[ i ] = (int16_t)((int64_t)(sbuf[ i ]) * fadeScale / INT_MAX); + } + sbuf += channels; fadeScale -= fadeStep; if (fadeScale <= 0) break; }