Module: SDL2::Mixer
- Defined in:
- mixer.c,
mixer.c
Overview
Sound mixing module.
With this module, you can play many kinds of sound files such as:
-
WAVE/RIFF (.wav)
-
AIFF (.aiff)
-
VOC (.voc)
-
MOD (.mod .xm .s3m .669 .it .med etc.)
-
MIDI (.mid)
-
OggVorbis (.ogg)
-
MP3 (.mp3)
-
FLAC (.flac)
Before playing sounds, you need to initialize this module by Mixer.init and open a sound device by Mixer.open.
This module mixes multiple sound sources in parallel. To play a sound source, you assign the source to a “channel” and this module mixes all sound sources assigned to the channels.
In this module, there are two types of sound sources: Chunk and Music. And there are two corresponding types of channels: Channels and MusicChannel.
Channels module plays Chunk objects, through multiple (default eight) channels. This module is suitable for the sound effects. The number of channels is variable with Channels.allocate.
MusicChannel module plays Music objects. This module has only one playing channel, and you cannot play multiple music in parallel. However an Music object is more efficient for memory, and this module supports more file formats than Channels. This module is suitable for playing “BGMs” of your application.
Defined Under Namespace
Modules: Channels, MusicChannel Classes: Chunk, Music
Constant Summary
- DEFAULT_FREQUENCY =
UINT2NUM(MIX_DEFAULT_FREQUENCY)
- DEFAULT_FORMAT =
UINT2NUM(MIX_DEFAULT_FORMAT)
- DEFAULT_CHANNELS =
INT2FIX(MIX_DEFAULT_CHANNELS)
- MAX_VOLUME =
INT2FIX(MIX_MAX_VOLUME)
- NO_FADING =
INT2FIX(MIX_NO_FADING)
- FADING_OUT =
INT2FIX(MIX_FADING_OUT)
- FADING_IN =
INT2FIX(MIX_FADING_IN)
Class Method Summary (collapse)
-
+ (nil) close
Close the audio device.
-
+ (nil) init(flags)
Initialize the mixer library.
-
+ (nil) open(freq = 22050, format = SDL2::Mixer::DEFAULT_FORMAT, channels = 2, chunksize = 1024)
Open a sound device.
-
+ ([Integer, Integer, Integer, Integer]) query
Query a sound device spec.
Class Method Details
+ (nil) close
Close the audio device.
183 184 185 186 187 |
# File 'mixer.c', line 183
static VALUE Mixer_s_close(VALUE self)
{
Mix_CloseAudio();
return Qnil;
}
|
+ (nil) init(flags)
123 124 125 126 127 128 129 130 |
# File 'mixer.c', line 123
static VALUE Mixer_s_init(VALUE self, VALUE f)
{
int flags = NUM2INT(f);
if (Mix_Init(flags) & flags != flags)
rb_raise(eSDL2Error, "Couldn't initialize SDL_mixer");
return Qnil;
}
|
+ (nil) open(freq = 22050, format = SDL2::Mixer::DEFAULT_FORMAT, channels = 2, chunksize = 1024)
166 167 168 169 170 171 172 173 174 175 176 |
# File 'mixer.c', line 166
static VALUE Mixer_s_open(int argc, VALUE* argv, VALUE self)
{
VALUE freq, format, channels, chunksize;
rb_scan_args(argc, argv, "04", &freq, &format, &channels, &chunksize);
HANDLE_MIX_ERROR(Mix_OpenAudio((freq == Qnil) ? MIX_DEFAULT_FREQUENCY : NUM2INT(freq),
(format == Qnil) ? MIX_DEFAULT_FORMAT : NUM2UINT(format),
(channels == Qnil) ? 2 : NUM2INT(channels),
(chunksize == Qnil) ? 1024 : NUM2INT(chunksize)));
playing_chunks = rb_ary_new();
return Qnil;
}
|
+ ([Integer, Integer, Integer, Integer]) query
Query a sound device spec.
This method returns the most suitable setting for open the device.
201 202 203 204 205 206 207 208 209 |
# File 'mixer.c', line 201
static VALUE Mixer_s_query(VALUE self)
{
int frequency = 0, channels = 0, num_opened;
Uint16 format = 0;
num_opened = Mix_QuerySpec(&frequency, &format, &channels);
return rb_ary_new3(4, INT2NUM(frequency), UINT2NUM(format),
INT2NUM(channels), INT2NUM(num_opened));
}
|