SDL_MixAudio

Hello,

I encountered click sounds when playing sounds with SDL. In my
opinion there is a bug in SDL_MixAudio:

static const Uint8 mix8[] =
[…]
#define ADJUST_VOLUME(s, v) (s = (s*v)/SDL_MIX_MAXVOLUME)
[…]
case AUDIO_U8: {
int dst_sample;

          while ( len-- ) {
                  dst_sample = mix8[*dst+*src];
                  ADJUST_VOLUME(dst_sample, volume);
                  *dst = dst_sample;
                  ++dst;
                  ++src;
          }
  }

The call of ADJUST_VOLUME seems to be inadequate here, since
unsigned 8 bit sounds have a baseline at 0x80.

  • Markus

I encountered click sounds when playing sounds with SDL. In my
opinion there is a bug in SDL_MixAudio:

static const Uint8 mix8[] =
[…]
#define ADJUST_VOLUME(s, v) (s = (s*v)/SDL_MIX_MAXVOLUME)
[…]

Yup, that’s a bug. Can you fix it and let me know what it should be?

Something like…
#define ADJUST_VOLUME8(s, v) (s = ((s-128)*v)/SDL_MIX_MAXVOLUME)+128

?
-Sam Lantinga (slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/

I encountered click sounds when playing sounds with SDL. In my
opinion there is a bug in SDL_MixAudio:

static const Uint8 mix8[] =
[…]
#define ADJUST_VOLUME(s, v) (s = (s*v)/SDL_MIX_MAXVOLUME)
[…]

Yup, that’s a bug. Can you fix it and let me know what it should be?

Something like…
#define ADJUST_VOLUME8(s, v) (s = ((s-128)*v)/SDL_MIX_MAXVOLUME)+128

This is the fix. :slight_smile: Subtracting 128 can be included in the table, if its
values are int. Maybe someone knows even better optimizations.

  • Markus

P.S. I sent you a mail about this about a week ago, using
slouken at devolution.com, but got no answer. Maybe it has vanished.

Hi
I’ve multiple sound sources and play them alike:

??? ??? ??? ??? alSourcePlay(Sources[2]);
now I want to play two sounds while one is decreasing volume and the other is increasing. In the end first is not hearable

anymore and second plays at full volume.
How should that look? I’ve tried alike:
? ??? ??? ??? SDL_MixAudio(Sources[2],Sources[1],0,SDL_MIX_MAXVOLUME);

Many thanks

Hi
I’ve multiple sound sources and play them alike:

??? ??? ??? ??? alSourcePlay(Sources[2]);
now I want to play two sounds while one is decreasing volume and the other is increasing. In the end first is not hearable

anymore and second plays at full volume.
How should that look? I’ve tried alike:
? ??? ??? ??? SDL_MixAudio(Sources[2],Sources[1],0,SDL_MIX_MAXVOLUME);

Many thanks