audio: Some fixes to the audio data type converter code. Removed some needless things ("len / sizeof (Uint8)"), and made sure the int32 -> float code uses doubles to avoid working with large integer values in a 32-bit float.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
diff --git a/src/audio/SDL_audiocvt.c b/src/audio/SDL_audiocvt.c
index 88fb1aa..3b7faff 100644
--- a/src/audio/SDL_audiocvt.c
+++ b/src/audio/SDL_audiocvt.c
@@ -196,7 +196,7 @@ SDL_ResampleAudioSimple(const int chans, const double rate_incr,
float *last_sample, const float *inbuf,
const int inbuflen, float *outbuf, const int outbuflen)
{
- const int framelen = chans * sizeof(float);
+ const int framelen = chans * sizeof (float);
const int total = (inbuflen / framelen);
const int finalpos = total - chans;
const double src_incr = 1.0 / rate_incr;
@@ -220,7 +220,7 @@ SDL_ResampleAudioSimple(const int chans, const double rate_incr,
idx += src_incr;
}
- return (int)((dst - outbuf) * sizeof(float));
+ return (int) ((dst - outbuf) * sizeof (float));
}
diff --git a/src/audio/SDL_audiotypecvt.c b/src/audio/SDL_audiotypecvt.c
index 12b34fe..cebfca6 100644
--- a/src/audio/SDL_audiotypecvt.c
+++ b/src/audio/SDL_audiotypecvt.c
@@ -31,14 +31,14 @@
void SDLCALL
SDL_Convert_S8_to_F32(SDL_AudioCVT *cvt, SDL_AudioFormat format)
{
- const Uint8 *src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
+ const Sint8 *src = ((const Sint8 *) (cvt->buf + cvt->len_cvt)) - 1;
float *dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
int i;
LOG_DEBUG_CONVERT("AUDIO_S8", "AUDIO_F32");
- for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
- *dst = (((float) ((Sint8) *src)) * DIVBY127);
+ for (i = cvt->len_cvt; i; --i, --src, --dst) {
+ *dst = (((float) *src) * DIVBY127);
}
cvt->len_cvt *= 4;
@@ -56,7 +56,7 @@ SDL_Convert_U8_to_F32(SDL_AudioCVT *cvt, SDL_AudioFormat format)
LOG_DEBUG_CONVERT("AUDIO_U8", "AUDIO_F32");
- for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
+ for (i = cvt->len_cvt; i; --i, --src, --dst) {
*dst = ((((float) *src) * DIVBY127) - 1.0f);
}
@@ -107,14 +107,14 @@ SDL_Convert_U16_to_F32(SDL_AudioCVT *cvt, SDL_AudioFormat format)
void SDLCALL
SDL_Convert_S32_to_F32(SDL_AudioCVT *cvt, SDL_AudioFormat format)
{
- const Uint32 *src = (const Uint32 *) cvt->buf;
+ const Sint32 *src = (const Sint32 *) cvt->buf;
float *dst = (float *) cvt->buf;
int i;
LOG_DEBUG_CONVERT("AUDIO_S32", "AUDIO_F32");
for (i = cvt->len_cvt / sizeof (Sint32); i; --i, ++src, ++dst) {
- *dst = (((float) *src) * DIVBY2147483647);
+ *dst = (float) (((double) *src) * DIVBY2147483647);
}
if (cvt->filters[++cvt->filter_index]) {
@@ -208,7 +208,7 @@ SDL_Convert_F32_to_S32(SDL_AudioCVT *cvt, SDL_AudioFormat format)
LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S32");
for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
- *dst = (Sint32) (*src * 2147483647.0);
+ *dst = (Sint32) (((double) *src) * 2147483647.0);
}
if (cvt->filters[++cvt->filter_index]) {