PDA

View Full Version : Sound in games



Emill
December 28th, 2008, 03:02 PM
Hello. I want sound and music in my games. I've tried sdl_mixer but I get too much latency on the sound effects, and if I change the buffer size, the quality on the music gets too bad. I use midi music and wav sound effects. What to do?

slavik
December 28th, 2008, 03:46 PM
I think there is a separate sound library for SDL ... SDL_sound I think.

I believe that for wav, you have to preload the sound and then tell it to play, or some such.

Emill
December 28th, 2008, 04:16 PM
I can't find any examples for SDL_sound how to play sounds. I don't see any "PlaySound" function in the API documentation.

cb951303
December 28th, 2008, 04:59 PM
I can't find any examples for SDL_sound how to play sounds. I don't see any "PlaySound" function in the API documentation.

you can try OpenAL?
Devmaster has a series of openal articles: http://www.devmaster.net/articles.php (at the bottom)

Emill
December 28th, 2008, 06:04 PM
OpenAL seems to have too much latency too when I test this: http://www.devmaster.net/articles/openal-tutorials/lesson1.php

I compare with an old DirectX 5 game I run in wine, and that has almost no latency.

cb951303
December 28th, 2008, 06:35 PM
I tried both couple of months ago and never had latency problem. are you sure it's not something with your system rather than the libraries?

Emill
December 28th, 2008, 06:56 PM
How many ms is your latency? Mine is about 200 ms for OpenAL. How can I see if I have done something to my system? I use PulseAudio.

cb951303
December 28th, 2008, 07:06 PM
How many ms is your latency? Mine is about 200 ms for OpenAL. How can I see if I have done something to my system? I use PulseAudio.

I don't know now it was a couple of months ago and I don't have the codes now but latency was not noticeable. 200ms is noticeable though.
are you using 8.10. PulseAudio was very buggy in early versions and it got really really better in 8.10 (Still it needs works though)

Emill
December 28th, 2008, 09:49 PM
I changed the settings in SDL_mixer to
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024)
and now it's OK. It could have been better but this works :)