Sign in to follow this  

SDL_mixer borks in windowed mode?

This topic is 4718 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

I've been putting sound and music into my game this weekend with SDL_mixer. I'm using Debian Linux (testing) and building a project with SDL/OpenGL and i have problems with getting the sound to work consistently. Sometimes the sound will just *stop* completely in the middle of the program. It continues to run, just without sound. If i switch to another virtual desktop, it stops. Sometimes, it's just doesn't start at all. I get more consistant results if i use fullscreen mode. But i also cannot switch between fullscreen/windowed mode or it stops again. I plan to unhook the fullscreen toggle for a release build (OpenGL on Windows has a hard time with that), but it would still be nice. Has anyone else experienced problems with SDL_mixer in a windowed environment?

Share this post


Link to post
Share on other sites
I am thinking that the problem lies with the Linux version of the SDL_Mixer - or the Linux itself. I know that I have used SDL_Mixer in Win32 environment without any problems. I assume that you have the latest version. You may want to try getting upgraded sound drivers if possible. I am not linux expert - so I cannot offer anything on settings or the like. I did not see much avaliable on google either - just the entry's from the mailing list.

Quote:
I plan to unhook the fullscreen toggle for a release build (OpenGL on Windows has a hard time with that),


If you can explain the problem - I think I may be able to help you get the toggeling concept working on Win32 platform. I just recently made a little framework demo that used the f/s toggeling with OGL and DX in the same app - so I can explain the model I used.

I hope this helps a bit!
- Drew

Share this post


Link to post
Share on other sites
Quote:
Original post by leiavoia
I've been putting sound and music into my game this weekend with SDL_mixer. I'm using Debian Linux (testing) and building a project with SDL/OpenGL and i have problems with getting the sound to work consistently. Sometimes the sound will just *stop* completely in the middle of the program. It continues to run, just without sound. If i switch to another virtual desktop, it stops. Sometimes, it's just doesn't start at all.

I get more consistant results if i use fullscreen mode. But i also cannot switch between fullscreen/windowed mode or it stops again. I plan to unhook the fullscreen toggle for a release build (OpenGL on Windows has a hard time with that), but it would still be nice.

Has anyone else experienced problems with SDL_mixer in a windowed environment?



I am also running Debian Linux (testing) and making a project with SDL/OpenGL using SDL_mixer (wow, what a coincidence eh?). I have never had any problems with SDL_mixer running in either full-screen or windowed mode. What args are you passing to SDL mixer for chunk size, etc when you initialize it?


Also I suggest you go try playing another SDL-app like Battle for Wesnoth and see if the same problem happens. If it doesn't, then you'll know it's something in your code and not something with SDL_mixer. Let us know how it goes [smile]

Share this post


Link to post
Share on other sites
Quote:
Original post by Roots
I am also running Debian Linux (testing) and making a project with SDL/OpenGL using SDL_mixer (wow, what a coincidence eh?). I have never had any problems with SDL_mixer running in either full-screen or windowed mode. What args are you passing to SDL mixer for chunk size, etc when you initialize it?


My init code looks like this:

/* initialize SDL */
int init_flags = (sound) ? SDL_INIT_AUDIO : 0;
if ( SDL_Init( SDL_INIT_VIDEO | init_flags ) < 0 ) {
LogMgr::Write(LOGMSG_FATAL, "*** SDL Audio/Video Initialization Failed *** : %s", SDL_GetError( ));
game_loop_done = true;
return;
}

if (sound) {
if( Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, AUDIO_S16, 2, 4096) < 0 ) {
LogMgr::Write(LOGMSG_ERROR, "Unable To Open Audio: %s", SDL_GetError( ));
}


Mix_AllocateChannels(16);

int audio_rate, audio_channels;
Uint16 audio_format;
Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
LogMgr::Write(LOGMSG_DEBUG, "Opened audio at %d Hz %d bit %s",
audio_rate,
(audio_format&0xFF),
(audio_channels > 1) ? "stereo" : "mono"
);
}
else {
RM->DisableAudio();
LogMgr::Write(LOGMSG_DEBUG, "Audio Disabled" );
}



Although i've tried some non-defaults and it still faults :-) Can you post your init code so i can try that? Thanks

Share this post


Link to post
Share on other sites
I do not need anything so elaborate as OpenAL however. I won't be needing 3D sound. I do plan on using simple distance/volume changes, but i don't need dopplar effect or 5.1 channel audio or anything over-the-top fancy.

FMOD might of practical use, but i'll stay in the SDL family if possible. FMOD is also not as license-friendly if ever want to go commercial (unlikely, but not out of the question)

Fortunately, i designed the sound system with enough flexability that i could change the the entire backend mechanics without making any changes to the "client" code, and could do so rather easily.

Share this post


Link to post
Share on other sites

// The constructor initializes variables and the audio systems.
GameAudio::GameAudio() {
if (AUDIO_DEBUG) cout << "DEBUG: GameAudio constructor" << endl;
current_track = -1; // No track playing since we haven't loaded any music
music_id = 1;
sound_id = 1;

for (int i = 0; i < MAX_CACHED_MUSIC; i++) {
music_cache[i].id = 0;
music_cache[i].music = NULL;
music_cache[i].time = 0;
}
for (int i = 0; i < MAX_CACHED_SOUNDS; i++) {
sound_cache[i].id = 0;
sound_cache[i].sound = NULL;
sound_cache[i].time = 0;
}

// Notice that we still continue the game even if audio initialization fails.

if(SDL_InitSubSystem(SDL_INIT_AUDIO) == -1) { // Really bad!
cout << "ERROR: Could not initalize SDL audio subsystem: " << SDL_GetError() << endl;
return;
}

// Open 22.05KHz, signed 16bit, system byte order, stereo audio, using 1024 byte chunks
if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 1024) == -1) {
audio_on = false;
cout << "ERROR: Could not initialize mixer audio: " << Mix_GetError() << endl;
}
else {
audio_on = true;
Mix_AllocateChannels(OPEN_CHANNELS);
}
}





That's the constructor to my audio engine, which is more or less complete. I'm still planning to add some tweaks to it and such later down the road, but I'm focusing on more critical parts of code in my game right now. I agree with your reasons for using SDL_mixer instead of a more advanced audio API like OpenAL or FMOD. [smile]


Here's a couple links to my complete audio code if you want to look through it. I've never had any problems what-so-ever with it, so hopefully it works for you too. It's GPL licensed so feel free to use/modify it for your own purposes if you like (as long as you abide by the restrictions of that license that is). Have fun. [grin]

Audio Engine header file
Audio Engine source file

Share this post


Link to post
Share on other sites
Thanks for the code. I've got a goo dportion of my resource manager done (most of it in fact). Instead of having a "sound manager" type of class, the resource manager takes care of simple loading, dumping, and distribution of resources including sound and music. However, the actual playing of them is done by the Sound and MusicTrack classes themselves. So, if for example, i wanted to use FMOD, i just change the load/dump code in resource maanger (only a few lines) and the mechanics of Sound and MusicTrack classes and that's it. The interfaces would not change.

Now, i plugged in you Init() code. It seemed to work a little better, but not really. I'm still getting weird problems. Switching windows or virtual desktops or windows/fullscreen mode freaks it out. Using other sound apps like my media player or the web browser (and whatever it uses) will mess it up too. I don't mean while it's running, i mean it won't start again with sound (and gives me some kind of "SDL audio timed out. Buggy drivers?". Sometimes it freezes and i have to kill it manually with the system monitor. Grrrr....

I'm also having problems with looping sounds. They seem to overlap. Like, instead of

[ TIME ---------------> ]

-----
-----
-----
-----

it'll be like

-----
-----
-----
-----


So i've been looking into FMOD. It seems pretty easy to link in but it's much more complicated and the docs blow. I wish there was a newbie step-by-step tutorial.

[Edited by - leiavoia on January 17, 2005 12:20:52 AM]

Share this post


Link to post
Share on other sites
That's really odd. I have no idea why it would do that, but it seems to be a problem with either your sound drivers or the library itself. You might want to test out the latest CVS version and see if that helps. Also I've heard that Dell puts sound cards akin to the "winmodems". That is, they modify cards like the SB Live! so that a lot of the processing is actually done in software (by Windows). My friend who runs Gentoo couldn't get sound to work on his machine for a really long time, and finally figured out that's why.


Well I hope FMOD does it for you. You might want to write a really simple demo just to make sure that it works instead of re-writting all of your audio code only to find out it's still working strangely.


Another last resort might be to play around with the chunk size and audio format in the audio initializer. I don't know a whole lot about audio programming though, so I can't really provide much more advice than that. [sad] Good luck

Share this post


Link to post
Share on other sites

This topic is 4718 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this