SDL_mixer example?

Started by
9 comments, last by gaerg 14 years, 2 months ago
I'm having trouble getting my SDL_mixer program to work. I have looked for help in several places and everything is set up correctly. Only problem is that the sound comes with lag no matter how I initialize the sounds. I would like to request a SDL_mixer example with a compiled exe, source and dlls. I've looked all over for a simple example to see whether the problem is with my dlls or header versions or whatever it is. But haven't found an open source example with an exe and the possibility to play the sound by pressing a key. This shouldn't be too hard to make. Thanks in advance.
Advertisement
I don't have such a sample available, but here's a couple of questions for you:

1. What buffer size are you using?

2. It sounds like you're using Windows; which version are you using?

I've never encountered this problem myself, but from reading online I get the impression that it comes up occasionally (and is often related to system-specific hardware and/or driver issues).

In theory though, as long as your buffer size is set to a reasonable value, you shouldn't be seeing unreasonable lag. If you really get stuck, you might consider putting together a minimal working example that demonstrates the behavior in question, and then post it here so that we can take a look at it. You could also post on the SDL forums and see if anyone there can help you.
Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096)

Tried with 44100 and 1024 values too. Same problem. I'm using Win XP Professional 2002 SP 3. I've compiled the same thing on our school's computers and the problem is the same. Sounds work fine on other (non open source) games that use SDL_mixer.

The problem is just that the sound comes with a one or a half second delay.
Quote:Original post by gaerg
Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096)

Tried with 44100 and 1024 values too. Same problem. I'm using Win XP Professional 2002 SP 3. I've compiled the same thing on our school's computers and the problem is the same. Sounds work fine on other (non open source) games that use SDL_mixer.

The problem is just that the sound comes with a one or a half second delay.
All I can tell you is that the behavior you describe is not typical. It sounds like something is wrong with your program, or that there's a hardware and/or driver problem with the systems you're testing on. Since you say other games that use SDL + SDL_mixer for sound seem to work fine, it seems like the problem is probably specific to your application (e.g. related to the implementation or to the sound files you're using).

Again, I'd recommend putting together a minimal working example (e.g. a single source file and an accompanying sound file) that demonstrates the behavior. Either you'll find the source of the problem in the course of creating the example, or if not, you'll have something you can post here for us to take a look at and maybe try out ourselves to see if we get the same behavior.
Quote:Original post by gaerg
Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096)

Tried with 44100 and 1024 values too. Same problem. I'm using Win XP Professional 2002 SP 3. I've compiled the same thing on our school's computers and the problem is the same. Sounds work fine on other (non open source) games that use SDL_mixer.

The problem is just that the sound comes with a one or a half second delay.


I'm getting the same here with using mingw under windows. no other application was running that used the sound card when this happened.
Quote:Original post by jyk
Quote:Original post by gaerg
Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096)

Tried with 44100 and 1024 values too. Same problem. I'm using Win XP Professional 2002 SP 3. I've compiled the same thing on our school's computers and the problem is the same. Sounds work fine on other (non open source) games that use SDL_mixer.

The problem is just that the sound comes with a one or a half second delay.
All I can tell you is that the behavior you describe is not typical. It sounds like something is wrong with your program, or that there's a hardware and/or driver problem with the systems you're testing on. Since you say other games that use SDL + SDL_mixer for sound seem to work fine, it seems like the problem is probably specific to your application (e.g. related to the implementation or to the sound files you're using).

Again, I'd recommend putting together a minimal working example (e.g. a single source file and an accompanying sound file) that demonstrates the behavior. Either you'll find the source of the problem in the course of creating the example, or if not, you'll have something you can post here for us to take a look at and maybe try out ourselves to see if we get the same behavior.


ok, try this out , please tell me if you feel a delay in the sound after you press direction keys to move the piece, thanks
Quote:ok, try this out , please tell me if you feel a delay in the sound after you press direction keys to move the piece, thanks
I ran the app in Win XP and observed the lag that you're referring to. I then dropped the sound file from your application into my own game, and no lag. This leads me to believe that there's something particular to your app that is causing the problem.

I know it can be a pain, but if the problem can't be resolved through other means, I really suggest (to both you and the OP) that you create a minimal working example demonstrating the behavior. Again, often in the course of creating such an example, you'll strip something out and all of a sudden it'll work, which will provide a hint as to what's causing the problem (and may even lead you to a solution). And if that *doesn't* happen, then you end up with a simple example application that you can post to forums such as GDNet or the SDL boards, and/or submit as part of a bug report.

One other thing. When I tested the sound in my own app, I was also using my own copies of the SDL and SDL_mixer .dll's. I'm not sure what the implications of this might be, but if you find that even a simple test app exhibits the same behavior, it might be a problem with the .dll's that you're using (although I'm not sure what that problem might be).
jyk , thank you for testing.
before writing a minimal working example I'd like to point out what I read in the SDL_mixer documentation:


Quote:
4.1.4 Mix_OpenAudio

SDL must be initialized with SDL_INIT_AUDIO before this call. frequency would be 44100 for 44.1KHz, which is CD audio rate. Most games use 22050, because 44100 requires too much CPU power on older computers. chunksize is the size of each mixed sample. The smaller this is the more your hooks will be called. If make this too small on a slow system, sound may skip. If made to large, sound effects will lag behind the action more. You want a happy medium for your target computer. You also may make this 4096, or larger, if you are just playing music. MIX_CHANNELS(8) mixing channels will be allocated by default.


This leads to the conclusion that there's something wrong with how I'm using Mix_OpenAudio , how do you call it, what parameters are you using ?

I'm using the following:

        int audio_rate = 22050;        Uint16 audio_format = AUDIO_S16;         int audio_channels = 2;        int audio_buffers = 4096;        if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers))


Ah yes , while writing this it seems I've solved it, I peeked in the code of supermariowars here and saw it used Mix_OpenAudio(44100, AUDIO_S16, 2, 2048); and built it again and now it seems the problem is solved.
Like I said I have tried various buffer sizes and frequencies. Here is an example of the code: http://pearl.plunder.com/x/$bZDi3nDhGg7xnwPh36pfRHjxgtyJ-_tW/97350848a3/?/mixer.zip (sorry couldn't figure out how to make a link here)
Pressing R plays the sound. The source and DLLs are there as well.
Quote:Original post by gaerg
Like I said I have tried various buffer sizes and frequencies. Here is an example of the code: http://pearl.plunder.com/x/$bZDi3nDhGg7xnwPh36pfRHjxgtyJ-_tW/97350848a3/?/mixer.zip (sorry couldn't figure out how to make a link here)
Pressing R plays the sound. The source and DLLs are there as well.
I tried your app and observed the lag. Then I replaced your .dll's (SDL and SDL_mixer) with mine, and the lag was gone.

Where did you get your .dll's? Did you download the binaries, or did you build the libraries yourself?

If you haven't already, you might try downloading the latest binaries. If that doesn't fix it, you could try downloading the latest source distribution and building the libraries yourself.

Unfortunately I can't tell you why your .dll's are exhibiting this behavior, but it seems clear that that is where the problem lies.

This topic is closed to new replies.

Advertisement