Module | Rubygame::Mixer
In: | lib/rubygame/deprecated_mixer.rb

**NOTE:** This module is DEPRECATED and will be removed in Rubygame 3.0. Please use Rubygame.open_audio, Rubygame.close_audio, Rubygame::Sound, and Rubygame::Music instead.

The Mixer module provides access to the SDL_mixer library for audio playback and mixing. This module is still very basic, but it is good enough to load and play WAV files on multiple mix channels.

See the Sample class for loading audio files. See the Music class for streaming music from a file.

### Methods

close_audio driver_name mix_channels mix_channels= open_audio pause play resume stop

### Classes and Modules

Class Rubygame::Mixer::Music
Class Rubygame::Mixer::Sample

### Constants

AUDIO_U8 | = | SDL::AUDIO_U8
AUDIO_S8 | = | SDL::AUDIO_S8
AUDIO_U16SYS | = | SDL::AUDIO_U16SYS
AUDIO_S16SYS | = | SDL::AUDIO_S16SYS

### Public Class methods

close_audio()

**NOTE:** This method is DEPRECATED and will be removed in Rubygame 3.0. Please use the Rubygame.close_audio instead.

Close the audio device being used by the mixer. You should not use any mixer functions after this function, unless you use open_audio() to re-open the audio device. See also open_audio().

Returns nil.

driver_name()

**NOTE:** This method is DEPRECATED and will be removed in Rubygame 3.0. Please use the Rubygame.audio_driver instead.

Returns the name of the audio driver that SDL is using.

May raise SDLError if initialization fails.

mix_channels()

**NOTE:** This method is DEPRECATED and will be removed in Rubygame 3.0. Please use the Rubygame::Sound class instead.

Returns the number of mixing channels currently allocated. See also mix_channels=

mix_channels=( num_channels )

**NOTE:** This method is DEPRECATED and will be removed in Rubygame 3.0. Please use the Rubygame::Sound class instead.

Set the number of mixer channels, allocating or deallocating channels as needed. This can be called many times, even during audio playback. If this call reduces the number of channels allocated, the excess channels will be stopped automatically. See also mix_channels

Returns the number of mixing channels allocated.

Note that 8 mixing channels are allocated when open_audio is called. This method only needs to be called if you want a different number (either greater or fewer) of mixing channels.

This method takes this argument:

num_channels: | desired number of mixing channels, an integer. Negative values will cause this method to behave as mix_channels, returning the number of channels currently allocated, without changing it.

open_audio( frequency=nil, format=nil, channels=nil, buffer=nil )

**NOTE:** This method is DEPRECATED and will be removed in Rubygame 3.0. Please use the Rubygame.open_audio instead.

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).

pause( channel_num )

Pause playback of a currently-playing mixing channel. Playback can be resumed from the current point with resume. See also stop.

play( sample, channel_num, repeats )

**NOTE:** This method is DEPRECATED and will be removed in Rubygame 3.0. Please use the Rubygame::Sound class instead.

Play an audio Sample on a mixing channel, repeating a certain number of extra times. Returns the number of the channel that the sample is being played on.

Raises SDLError if something goes wrong.

This method takes these arguments:

sample: | what Sample to play
channel_num: | which mixing channel to play the sample on. Use -1 to play on the first unreserved channel.
repeats: | how many extra times to repeat the sample. Can be -1 to repeat forever until it is stopped.

resume( channel_num )

Resume playback of a paused mixing channel. The channel must have been paused (via the pause method) for this to have any effect. Playback will resume from the point where the channel was paused.

stop( channel_num )

Stop playback of a playing or paused mixing channel. Unlike pause, playback cannot be resumed from the current point. See also play.

[Validate]