The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
[SDL 1.3] SDL_MixAudio makes loud noise
Unga
Guest

Hi all

I use SDL 1.3 on FreeBSD 8.1.


Following works fine:
memcpy(stream, (uint8_t *)audio_buf + audio_buf_index, len1);

But following make loud continuous noise:
SDL_MixAudio(stream, (uint8_t *)audio_buf + audio_buf_index, len1, SDL_MIX_MAXVOLUME);

Do other users of SDL_MixAudio() experience similar issue? If it work fine, could you mention what's your OS?

How could I get SDL_MixAudio() to work? It's very important to me as a volume control.

Many thanks in advance.

Best regards
Unga
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
[SDL 1.3] SDL_MixAudio makes loud noise
Unga
Guest

----- Original Message -----

Quote:
From: Unga
To: ""
Cc:
Sent: Friday, October 21, 2011 12:52 PM
Subject: [SDL] [SDL 1.3] SDL_MixAudio makes loud noise

Hi all

I use SDL 1.3 on FreeBSD 8.1.


Following works fine:
memcpy(stream, (uint8_t *)audio_buf + audio_buf_index, len1);

But following make loud continuous noise:
SDL_MixAudio(stream, (uint8_t *)audio_buf + audio_buf_index, len1,
SDL_MIX_MAXVOLUME);

Do other users of SDL_MixAudio() experience similar issue? If it work fine,
could you mention what's your OS?

How could I get SDL_MixAudio() to work? It's very important to me as a
volume control.

Many thanks in advance.

Best regards
Unga

SDL_MixAudio() is implemented in src/audio/SDL_audio.c:

/*
 * Moved here from SDL_mixer.c, since it relies on internals of an opened
 *  audio device (and is deprecated, by the way!).
 */
void
SDL_MixAudio(Uint8 * dst, const Uint8 * src, Uint32 len, int volume)
{

}

Why it say deprecated? Then replaced with what?

Regards
Unga
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
[SDL 1.3] SDL_MixAudio makes loud noise
Ryan C. Gordon
Guest

Quote:
Quote:
Following works fine:
memcpy(stream, (uint8_t *)audio_buf + audio_buf_index, len1);

But following make loud continuous noise:
SDL_MixAudio(stream, (uint8_t *)audio_buf + audio_buf_index, len1,
SDL_MIX_MAXVOLUME);

In SDL 1.2, the audio buffer passed to you was initialized to silence
before your callback ran. Since your callback is just going to rewrite
that whole buffer anyhow, it doesn't make sense to initialize it, so we
no longer do that in 1.3.

The memcpy() works because the buffer gets completely initialized by
you. The MixAudio call isn't working because you're mixing against
uninitialized memory.

Try adding a "memset(stream, 0, len1);" before your MixAudio call.

Quote:
Why it say deprecated? Then replaced with what?

SDL_MixAudioFormat(). SDL_MixAudio() could be generally useful, but its
behavior is dictated by the format of the default audio device, and
fails when the device isn't opened...which was a problem in general, but
moreso when there can be multiple devices. The new API call is
independent of any device, and can be used even if no device is opened
at all.

--ryan.

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org