Jump to content
  • Advertisement
Sign in to follow this  
Thunderstrike

SDL sound delay

This topic is 4823 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! My problem is that when I play some chunk using Mix_PlayChannel(), it sounds about a second later than the call of the function. I am using SDL 1.2.8 with SDL_mixer 1.2.6 and mingw32(Dev-C++). Here are some snippets:
 mixer::mixer(int frequency, int audio_channels, int chunksize)
{
 music=NULL;
 Uint16 format=AUDIO_S16SYS;
 if((Mix_OpenAudio(frequency,format,audio_channels,chunksize))<0)
  printf("Audio startup error: %s\r\n",Mix_GetError());
}  
sound::sound()
{
 chunk=NULL;
 channel=-1; 
}
int sound::loadfile(char* soundfile)
{
 if(chunk) Mix_FreeChunk(chunk);
 chunk=Mix_LoadWAV(soundfile);
 return 0;
}
int sound::play(int channelreq,int loop)
{
 return channel=Mix_PlayChannel(channelreq,chunk,loop); 
}


No more than a wrapper class. Here is how I load the sound:
    mx=new mixer(44100,2,512);
    mx->loadfile("mus.ogg");
    mx->play(-1);

    down=mx->newsound();			
    down->loadfile("down.wav");	


After this, down->play(-1,0) delays a sec before I hear the sound. I've tried several buffer sizes, frequencies, etc. to no avail. Have you got any ideas? Thanks in advance, Thunder

Share this post


Link to post
Share on other sites
Advertisement
You could try doing the same thing with FMOD and see if you get the same result. You also might want to attempt to disable hardware audio as that caused so many headaches for me when working with third party audio libraries.

Share this post


Link to post
Share on other sites
Thanks for the advice.

FMOD does indeed play fine.
However, it is not a free library, so i would be happier to go with SDL_Mixer.
Can you think of any reasons for that delay?

Thanks,
Thunder

Share this post


Link to post
Share on other sites
I'm getting the same problem with a click.wav that I use for the menu screen when I click on a button. It's very irritating. Now it looks like my program is slow as hell while it's just the audio part :)

The sound part of SDL just sucks, might need to use something else for it.

Share this post


Link to post
Share on other sites
is it a second each time you play it or just the first time? I take it you are allowing time for it to load the file into the buffer etc.

Share this post


Link to post
Share on other sites
It's just everytime, and I loaded the music files before the loop started so I didn't load them everytime before I play.

Share this post


Link to post
Share on other sites
I have encountered similar audio output delays in the past but I don't think it's to do directly with SDL.

from what I can tell SDL tries to use your system's DirectSound capabilities and if it can't do DirectX for whatever reason then it will revert to the winmm (Windows Multimedia library) functions (just like it does with DirectDraw vs. GDI rendering)

btw I have found Audiere to have the same delay problems with the winmm driver (up to 500ms second or so)

In other words, make sure your system supports DirectSound (dxdiag) and SDL_mixer acually makes use of it.

a wild guess but it may help.

Share this post


Link to post
Share on other sites
Thanks, but as I've said, there is no noticeable delay with FMOD, but that one needs licensing.
And yes, it happens every time the song is played, and the waves are loaded at startup.
Any other ideas?

Thunder

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I've had that problem before. If you try different chunk sizes that may help.

Share this post


Link to post
Share on other sites
If you mean the audio buffer size, then i've tried settings from 64 to 65535 bytes with no success. Obviously at 65535 the delay was much worse than with 64 byte chunk size, however there was still a second delay with 64 bytes.

Thunder

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!