Advertisement

SDL_mixer initialization parameters.....should the user have a choice?

Started by January 20, 2005 11:55 PM
6 comments, last by Drew_Benton 19 years, 7 months ago
So yeah, basically in my audio engine I have this line:

	// 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)
It works fine on my machine. It works fine on the machines of the rest of my team. But shoud I give the user the option to change those values? Is it possible that that combination of parameters may not work well for every machine, and that I should grant the user the option of changing those parameters in that case? Thanks in advance for any insight. [smile]

Hero of Allacrost - A free, open-source 2D RPG in development.
Latest release June, 2015 - GameDev annoucement

Absolutly! Just think for one second if by some chance those default settings don't work with another's computer - your entire audio engine would be useless then and all your hard work would be for nothing. I think that part of a good engine design is allowing full flexibility. What do you have to lose? You can even make it so it initializes to the defaults if nothing custom is specified. I feel that is always good to think ahead, so by making this change is well worth the time and effort.

- Drew
Advertisement
Your best option is to use an advance audio API that could analyze the user's audio card and create a list of enumerated settings. And from that list your audio engine would choose the best setting for the game.
---http://www.michaelbolton.comI constantly dream about Michael Bolton.
an xml file to store your configuration, and a small GUI configuration editor that also tests the settings to see if they work or not. if you don't have an xml parser, and don't wish to write one, use eXpat.

Get off my lawn!

Quote: Original post by TANSTAAFL
an xml file to store your configuration, and a small GUI configuration editor that also tests the settings to see if they work or not. if you don't have an xml parser, and don't wish to write one, use eXpat.


Couldn't agree more [smile]. I think XML is the way of the future for configuration files. I have also heard of TinyXML, but I have not used it. Good luck with your engine!
TinyXML is *perfect* for config files, since it compiles directly into your program. I would highly recommend it.

Another option is simply to include some simple command line arguments and pass those to your init functions.

int main( int argc, char* argv[] ) {		//get args:	bool fullscreen = false;	bool use_sound = true;	int colorDepth = 16;	for (int x = 1; x < argc; x++) {		if ( strcmp(argv[x],"--fullscreen") == 0 ) {fullscreen = true; continue;}		if ( strcmp(argv[x],"--no_sound") == 0 ) {use_sound = false; continue;}		if (strcmp(argv[x], "--color_depth") == 0) { colorDepth = atoi(argv[x+1]); continue; }		if (strcmp(argv[x], "--help") == 0) {                        // print help			return 0;			}		}        // do other stuph        }
Advertisement
Yeah I thought as much, thanks everyone. [smile] Creating a configuration file would be no problem for me at all, but how could I

Quote: create an advance audio API that could analyze the user's audio card and create a list of enumerated settings


The only way I can think of doing this right now is when the user starts the game for the first time, I try all the possible combinations of byte order, chunk size, etc. until I find one in which Mix_OpenAudio() does not return -1, then save that to the config file so next time it will just load the config file. I'm not very experienced with audio programming, so any advice or code examples, *hint hint* would be nice. [grin]

Hero of Allacrost - A free, open-source 2D RPG in development.
Latest release June, 2015 - GameDev annoucement

Quote: Original post by Roots
Yeah I thought as much, thanks everyone. [smile] Creating a configuration file would be no problem for me at all, but how could I

Quote: create an advance audio API that could analyze the user's audio card and create a list of enumerated settings




Here is the SDL_Mixer documentation. I do not think it would be necessary for you to enum through the avaliable mixer modes to find the best one because SDL_Mixer should use the best one. I say this based on this from the docs:

 4.1.6 Mix_QuerySpecint Mix_QuerySpec(int *frequency, Uint16 *format, int *channels)frequency    A pointer to an int where the frequency actually used by the opened audio device will be stored. format    A pointer to a Uint16 where the output format actually being used by the audio device will be stored. channels    A pointer to an int where the number of audio channels will be stored.    2 will mean stereo, 1 will mean mono. Get the actual audio format in use by the opened audio device. This may or may not match the parameters you passed to Mix_OpenAudio.Returns: 0 on error. If the device was open the number of times it was opened will be returned. The values of the arguments variables are not set on an error. 	// get and print the audio format in useint numtimesopened, frequency, channels;Uint16 format;numtimesopened=Mix_QuerySpec(&frequency, &format, &channels);if(!numtimesopened) {    printf("Mix_QuerySpec: %s\n",Mix_GetError());}else {    char *format_str="Unknown";    switch(format) {        case AUDIO_U8: format_str="U8"; break;        case AUDIO_S8: format_str="S8"; break;        case AUDIO_U16LSB: format_str="U16LSB"; break;        case AUDIO_S16LSB: format_str="S16LSB"; break;        case AUDIO_U16MSB: format_str="U16MSB"; break;        case AUDIO_S16MSB: format_str="S16MSB"; break;    }    printf("opened=%d times  frequency=%dHz  format=%s  channels=%d",            numtimesopened, frequency, format, channels);}


As you can see, setting the mode is not gaurnteed! Because of this, I would not worry about trying to loop through and save them. As long as you have the option to change, I think you should be great.

- Drew

This topic is closed to new replies.

Advertisement