/* call-seq: * open_audio( frequency=nil, format=nil, channels=nil, buffer=nil) * * Initializes the audio device. You must call this before using the other * mixer functions. See also #close_audio(). * * Returns nil. May raise an SDLError if initialization fails. * * This method takes these arguments: * * frequency:: output sample rate in audio samples per second (Hz). * Affects the quality of the sound output, at the expense of * CPU usage. If nil, the default (22050) is used. 22050 is * recommended for most games. For reference, 44100 is CD quality. * The larger the value, the more processing required. * * format:: output sample format. If nil, the default recommended system * format is used. It's _highly_ recommended you leave this nil! * * But if you're feeling reckless, you can use one of these * constants located in the Rubygame::Mixer module: * * AUDIO_U16SYS:: unsigned 16-bit samples. * AUDIO_S16SYS:: signed 16-bit samples. * AUDIO_U8:: unsigned 8-bit samples. * AUDIO_S8:: signed 8-bit samples. * * channels:: output sound channels. Use 2 for stereo, 1 for mono. * If nil, the default (2) is used. * This option is not related to mixing channels. * * buffer:: size of the sound buffer, in bytes. If nil, the default (1024) * is used. Larger values have more delay before playing a * sound, but require less CPU usage (and have less skipping * on slow systems). * */ VALUE rbgm_mixer_openaudio(int argc, VALUE *argv, VALUE module) { VALUE vfreq, vformat, vchannels, vbuffer; int freq = MIX_DEFAULT_FREQUENCY; Uint16 format = MIX_DEFAULT_FORMAT; int channels = 2; int buffer = 1024; rb_scan_args(argc, argv, "04", &vfreq, &vformat, &vchannels, &vbuffer); if( RTEST(vfreq) ) { freq = NUM2INT(vfreq); } if( RTEST(vformat) ) { format = NUM2UINT(vformat); } if( RTEST(vchannels) ) { channels = NUM2INT(vchannels); } if( RTEST(vbuffer) ) { buffer = NUM2INT(vbuffer); } if ( Mix_OpenAudio(freq, format, channels, buffer) < 0 ) { rb_raise(eSDLError, "Error initializing SDL_mixer: %s", Mix_GetError()); } return Qnil; }