pods::SDL::Mixer(3pm)
π SDL::Mixer β Sound and music functions π
okay bestie, so this is a page from the User Contributed Perl Documentation and honestly? it's giving "i just want my game to make noise" energy. it's SDL::Mixer, and it's literally the whole sound-and-music department. let's get into it π
β¨ CATEGORY β¨
Mixer β that's it, that's the category, slay.
π§ CONSTANTS π§
k so the constants are exported by default (iconic of them tbh). but if you're a "no surprise imports" kind of girl, you can dodge that by doing:
use SDL::Mixer ();
and then reach for them directly like:
SDL::Mixer::MIX_DEFAULT_FREQUENCY;
or, if you're feeling organized, pick an export tag below π
π©· Export tag: ':init'
MIX_INIT_FLAC
MIX_INIT_MOD
MIX_INIT_MP3
MIX_INIT_OGG
π©· Export tag: ':defaults'
MIX_CHANNELS
MIX_DEFAULT_FORMAT
MIX_DEFAULT_FREQUENCY
MIX_DEFAULT_CHANNELS
MIX_MAX_VOLUME
MIX_CHANNEL_POST
π©· Export tag: ':fading'
MIX_NO_FADING
MIX_FADING_OUT
MIX_FADING_IN
π©· Export tag: ':type'
MUS_NONE
MUS_CMD
MUS_WAV
MUS_MOD
MUS_MID
MUS_OGG
MUS_MP3
MUS_MP3_MAD
MUS_MP3_FLAC
π©· Export tag: ':format'
AUDIO_U8
AUDIO_S8
AUDIO_U16LSB
AUDIO_S16LSB
AUDIO_U16MSB
AUDIO_S16MSB
AUDIO_U16
AUDIO_S16
AUDIO_U16SYS
AUDIO_S16SYS
π©· Export tag: ':status'
SDL_AUDIO_STOPPED
SDL_AUDIO_PLAYING
SDL_AUDIO_PAUSED
π DESCRIPTION π
SDL::Mixer lets you turn sound on, mess with the music volume settings, and play / pause / resume stuff β plus fade the sound and the music in and out. it's the whole audio vibe check in one module, fr fr β¨
π¦ Supported Formats π¦
the SDL Mixer library is a multi-channel audio mixer, no cap. it supports 8 channels of 16 bit stereo audio, plus a single channel for music.
you use the channels to load samples (aka sound effects) in these formats:
- Microsoft WAVE files (WAV)
- Creative Labs VOC files (VOC)
- MIDI files (if compiled with Timidity)
if you're doing MIDI, heads up: mixing MIDI files to wave output is very CPU-intensive π so if regular WAVE files sound great but your MIDI files sound choppy, try 8-bit audio, mono audio, or lower frequencies.
the music channel can play these:
- AIFF
- MOD (
.mod.xm.s3m.669.it.medand more β if compiled with libmikmod) - OggVorbis (
.oggβ if compiled with ogg/vorbis libraries) - MP3 (if compiled with SMPEG or MAD libraries)
- FLAC (if compiled with FLAC library)
π METHODS π
β init
my $init_flags = SDL::Mixer::init( $flags );
loads the dynamic libraries and gets them ready to go. $flags should be one or more init flags OR'd together. it returns the flags that got successfully initialized, or 0 on failure. bestie, check your return value, i'm begging π
Example:
use SDL::Mixer;
my $init_flags = SDL::Mixer::init( MIX_INIT_MP3 | MIX_INIT_MOD | MIX_INIT_FLAC | MIX_INIT_OGG );
print("We have MP3 support!\n") if $init_flags & MIX_INIT_MP3;
print("We have MOD support!\n") if $init_flags & MIX_INIT_MOD;
print("We have FLAC support!\n") if $init_flags & MIX_INIT_FLAC;
print("We have OGG support!\n") if $init_flags & MIX_INIT_OGG;
Flags:
MIX_INIT_MP3MIX_INIT_MODMIX_INIT_FLACMIX_INIT_OGG
Note: only available for SDL_mixer >= 1.2.10 π
β quit
SDL::Mixer::quit();
unloads the libraries you previously loaded with init(). clean up after yourself, queen π«Ά
Note: only available for SDL_mixer >= 1.2.10
β linked_version
$version = SDL::Mixer::linked_version();
linked_version gives you the major-, minor-, and patchlevel for SDL_mixer. this way you can check if e.g. init() and quit() are available. it's literally the vibe check for "do i have the cool features" π¦
Example:
use SDL::Mixer;
use SDL::Version;
my $version = SDL::Mixer::linked_version();
printf("%d.%d.%d\n", $version->major, $version->minor, $version->patch); # prints "1.2.8" for me
β open_audio
my $audio_opened = SDL::Mixer::open_audio( $frequency, $format, $channels, $chunksize );
open_audio will initialize SDL_mixer if it's not yet initialized (see the note, bestie). SDL_mixer may not be able to provide the exact specifications you provided, however it will automatically translate between the expected format and the real one. you can retrieve the real format using query_spec.
returns 0 on success, -1 on error.
Note: you must not useAUDIO_S16,AUDIO_U16,AUDIO_S16LSB, orAUDIO_U16LSB.They are not portable, and SDL will not return an error code when they fail. the result will be a horrible staticy noise ππ you can usually useAUDIO_S16SYS, though not always. future versions of SDL should take this parameter only as a hint, then read back the value that the OS (for example, OSS or ALSA) has chosen to use in case the desired audio type is not supported.
Note: when already initialized, this function will not re-initialize SDL_mixer, nor fail. it will merely increment the number of times SDL::Mixer::close_audio must be called to actually get it to uninitialize. this serves as a very simplistic method for multiple application components to use SDL_mixer without necessitating a great deal of inter-component awareness. be warned however that in such a situation, the latest components to initialize SDL_mixer will probably not get the SDL_mixer settings they're expecting. π
Example:
use SDL;
use SDL::Mixer;
printf("Error initializing SDL_mixer: %s\n", SDL::get_error()) unless SDL::Mixer::open_audio(44100, AUDIO_S16, 2, 1024) == 0;
β close_audio
SDL::Mixer::close_audio();
closes the mixer and halts all playing audio. this function does not return anything. it's giving "abrupt but necessary" π
β query_spec
my @query_spec = @{ SDL::Mixer::query_spec() };
find out what the actual audio device parameters are. this function returns 1 as first array element (status) if the audio has been opened, 0 otherwise.
Example:
use SDL::Mixer;
my ($status, $freq, $format, $channels) = @{ SDL::Mixer::query_spec() };
printf("%s, %s, %s, %s\n", $status, $freq, $format, $channels);
π SEE ALSO π
perl, SDL::Mixer::Channels, SDL::Mixer::Effects, SDL::Mixer::Groups, SDL::Mixer::Music β go read the whole friend group, they're all icons π₯
π«Ά AUTHORS π«Ά
see "AUTHORS" in SDL. (yes, that's the whole section, they said "go look" and honestly? respect.)
and that's the page, bestie π this was pods::SDL::Mixer(3pm) from perl v5.42.3, dated 2026-08-19 β now go make some noise, you main character πβ¨πΈ
π¦ where this page comes from
- ubuntu stonking: libsdl-perl 2.548-6build1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms