22 Aug 2000 19:25:17 UTC
- Distribution: SDL-sdlpl
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (1)
- Testers (0 / 11 / 0)
- KwaliteeBus factor: 3
- % Coverage
- License: unknown
- Activity24 month
- Download (175.13KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version
SDL::Mixer - a SDL perl extension
$mixer = new SDL::Mixer -frequency => MIX_DEFAULT_FREQUENCY, -format => MIX_DEFAULT_FORMAT, -channels => MIX_DEFAULT_CHANNELS, -size => 4096;
This module provides a pseudo object ( it contains no data ), that handles all of the digital audio for the system. It is simply an interface for SDL_mixer. In general, there is no need to pass any flags to the constructor. The default, shown above, provides 8 channels of 16 bit audio at 22050 Hz. and a single channel of music. The flags passable are -frequency ( or for the impatient -rate ), -format, -channels, -size, which specify the sample frequency, byte format, number of channels, and sample size respectively. Frequency can range from 11025 to 44100. Format is one of the following: AUDIO_U8, AUDIO_S8, AUDIO_U16, AUDIO_S16. For those with big endian machines use AUDIO_U16MSB and AUDIO_S16MSB. Channels default to 8, while size goes to 4096, and can range from 512 to 8096. Given you are using perl, a higher latency is probably more realistic. There are two subordinate modules, Sound.pm and Music.pm which handle the actual file access and memory cleanup. Sound objects also have a per file volume control above and beyond the channel's volume setting. It can be set to half volume as follows: my $wavfile = new SDL::Sound "funk.wav"; $wavfile.volume(64); Sound objects can only load .wav files. Music files, however, can load MIDI files such as .mod .s3m .it .xm. Music files, more importantly, through use of Lokisoft's smpeg library, can play MP3 files. This is, of course, the music format of choice. If you need normal CD audio, please use the Cdrom.pm module.
$hashref = $mixer->query_spec();
Query_spec returns a has containing the keys -status, -frequency, -format, and -channels. These are the values that are being used by the mixer. If you are adventurous, the SDL::sdlpl::sdl_*_audio_* functions provide low level access the the SDL Audio features. Without C level callback functions these routines are useless though.
This calls Mix_ReserveChannels and saves n channels for the app.
If given a number greater than the current number of channels, it will grow the collection of channels to n. If n is lower, then it will free those channels, and remove them.
This will add channel to group, which channel and group are both integers. Similarly,
will add channels from 'from' to 'to' to group 'group'.
will return the next available channel in a group.
will return the number of channels in a group, and if group = -1 will return the total number of channels.
will return the longest playing sample in the group.
will return the most recently played sample of a playing group.
$mixer->play_channel(channel,Sound,loops,[ticks]); $mixer->fade_in_channel(channel,Sound,loops,ms,[ticks]); $mixer->fade_out_channel(channel,ms); $mixer->fade_out_group(group,ms); $mixer->channel_expire(channel,ms); $mixer->halt(channel); $mixer->halt_group(group); $mixer->pause(channel); $mixer->resume(channel); $mixer->fading_channel(channel); $mixer->playing(channel); $mixer->paused(channel);
Play_channel will play a Sound object 'Sound', on channel 'channel', and loop 'loops' times, for optionally at most 'ticks' ticks. Fade_in_channel works the same, but fades the sample in over ms milliseconds. Fade_out_channel will fade a channel out for ms milliseconds, where as channel_expire will kill it after ms milliseconds. Halt will kill a channel immediately, and halt_group works on an entire group. Pause and resume works as a pair to pause and resume playback of a channel. Fadding_channel, playing, and paused, all return a value if the channel is in that state.
There are a number of similar methods for music. They work basically the same way, but as there is only a single music channel, do not require as many args. They are as follows:
$mixer->play_music(Music,loops); $mixer->fade_in_music(Music,loops,ms); $mixer->fade_out_music(ms); $mixer->halt_music(); $mixer->pause_music(); $mixer->resume_music(); $mixer->music_paused(); $mixer->playing_music(); $mixer->fading_music();
In addition to those, music also has two additional commands:
The MIX_MAX_VOLUME is 128. To set the volume of the music use the method: $mixer->music_volume(vol);
Similarly the volume of each channel can be set using:
For .wav files, the volume of the sample itself can be adjusted as mentioned above using the 'volume' method of the Sound object. The mixer will automagically handle all of the mixing for you.
David J. Goehrig