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.
Ryan C. Gordon 2017-01-15 05:01:59 -05:00
parent 1e4820951f
commit 1e66d457d7
2 changed files with 9 additions and 9 deletions

View File

@ -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));
}

View File

@ -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]) {