Commit a7f86f2fd22b0d11a7b224f445678372c6061d64

Ryan C. Gordon 2017-01-22T20:18:59

audio: don't cast to double in SDL_ConvertStereoToMono(). It's expensive and (hopefully) unnecessary. If this becomes an overflow problem, we could multiply both values by 0.5f before adding them, but let's see if we can get by without the extra multiplication first.

1
2
3
4
5
6
7
8
9
10
11
12
13
diff --git a/src/audio/SDL_audiocvt.c b/src/audio/SDL_audiocvt.c
index a922fd3..1c3d56a 100644
--- a/src/audio/SDL_audiocvt.c
+++ b/src/audio/SDL_audiocvt.c
@@ -41,7 +41,7 @@ SDL_ConvertStereoToMono(SDL_AudioCVT * cvt, SDL_AudioFormat format)
     SDL_assert(format == AUDIO_F32SYS);
 
     for (i = cvt->len_cvt / 8; i; --i, src += 2) {
-        *(dst++) = (float) ((((double) src[0]) + ((double) src[1])) * 0.5);
+        *(dst++) = (src[0] + src[1]) * 0.5f;
     }
 
     cvt->len_cvt /= 2;