Module: SDL2::Mixer

Extended by:
FFI::Library, Library
Defined in:
lib/sdl2/mixer.rb,
lib/sdl2/mixer/chunk.rb,
lib/sdl2/mixer/lib_paths.rb

Overview

Interface for “SDL_mixer.h”

Defined Under Namespace

Modules: FADING, INIT Classes: Chunk, Music

Constant Summary collapse

DEFAULT_FREQUENCY =

Good default values for a PC soundcard

22050
DEFAULT_FORMAT =
Audio::S16LSB
DEFAULT_CHANNELS =
2
MAX_VOLUME =
128
CHANNELS =

The default mixer has 8 simultaneous mixing channels

8
CHANNEL_POST =

Special Effects API by ryan c. gordon.….

-2
EFFECTSMAXSPEED =
"MIX_EFFECTSMAXSPEED"
LibPaths =
['libSDL2_mixer', '/usr/local/lib/libSDL2_mixer.so']

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Library

api, boolean?, metaclass, raise_error, raise_error_if, raise_error_unless, returns_error

Class Method Details

.load_wav(filename) ⇒ Object

Load a wave file or a music (.mod .s3m .it .xm) file



151
152
153
# File 'lib/sdl2/mixer.rb', line 151

def self.load_wav(filename)
  Mixer::load_wav_rw(RWops.from_file(filename, "rb"), 1)
end

.play_channel(channel, chunk, loops = -1)) ⇒ Object

Play an audio chunk on a specific channel. If the specified channel is -1, play on the first free channel. If ‘loops’ is greater than zero, loop the sound that many times. If ‘loops’ is -1, loop inifinitely (~65000 times). Returns which channel was used to play the sound.



536
537
538
# File 'lib/sdl2/mixer.rb', line 536

def self.play_channel(channel,chunk,loops=-1)
  Mixer::play_channel_timed(channel,chunk,loops,-1)
end

Instance Method Details

#effect_doneObject

This is a callback that signifies that a channel has finished all its

loops and has completed playback. This gets called if the buffer
plays out normally, or if you call Mix_HaltChannel(), implicitly stop
a channel via Mix_AllocateChannels(), or unregister a callback while
it's still playing.

DO NOT EVER call SDL_LockAudio() from your callback function!



290
# File 'lib/sdl2/mixer.rb', line 290

callback :effect_done, [:int, :pointer], :void

#effect_funcObject

This is the format of a special effect callback:

myeffect(int chan, void *stream, int len, void *udata);

(chan) is the channel number that your effect is affecting. (stream) is

the buffer of data to work upon. (len) is the size of (stream), and
(udata) is a user-defined bit of data, which you pass as the last arg of
Mix_RegisterEffect(), and is passed back unmolested to your callback.
Your effect changes the contents of (stream) based on whatever parameters
are significant, or just leaves it be, if you prefer. You can do whatever
you like to the buffer, though, and it will continue in its changed state
down the mixing pipeline, through any other effect functions, then finally
to be mixed with the rest of the channels and music for the final output
stream.

DO NOT EVER call SDL_LockAudio() from your callback function!



280
# File 'lib/sdl2/mixer.rb', line 280

callback :effect_func, [:int, :pointer, :int, :pointer], :void

#music_finishedObject

Callback: music_finished



237
# File 'lib/sdl2/mixer.rb', line 237

callback :music_finished, [], :void