.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "pods::SDL::Mixer::Effects 3pm" .TH pods::SDL::Mixer::Effects 3pm 2024-01-10 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME SDL::Mixer::Effects \- sound effect functions .SH CATEGORY .IX Header "CATEGORY" Mixer .SH METHODS .IX Header "METHODS" .SS register .IX Subsection "register" .Vb 1 \& SDL::Mixer::Effects::register( $channel, $effect_callback, $done_callback, $arg ); .Ve .PP Hook a processor function into a channel for post processing effects. You may just be reading the data and displaying it, or you may be altering the stream to add an echo. Most processors also have state data that they allocate as they are in use, this would be stored in the \f(CW$arg\fR data space. When a processor is finished being used, any function passed into \f(CW$done_callback\fR will be called. .PP The effects are put into a linked list, and always appended to the end, meaning they always work on previously registered effects output. .PP Returns: Zero on errors, such as a nonexisting channel. .PP \&\fBNote\fR: Passing MIX_CHANNEL_POST will register the \f(CW$effect_callback\fR as an postmix effect. .PP \&\fBNote\fR: Do not use this on a threaded perl. This will crash. .PP Example: .PP .Vb 5 \& use SDL; \& use SDL::Mixer; \& use SDL::Mixer::Channels; \& use SDL::Mixer::Effects; \& use SDL::Mixer::Samples; \& \& my @last_stream = (); \& my $echo_effect_func = sub \& { \& my $channel = shift; \& my $samples = shift; \& my $position = shift; \& my @stream = @_; \& \& my @stream2 = @stream; \& my $offset = $samples / 2; \& for(my $i = 0; $i < $samples; $i+=2) \& { \& if($i < $offset) \& { \& if(scalar(@last_stream) == $samples) \& { \& $stream2[$i] = $stream[$i] * 0.6 + $last_stream[$samples + $i \- $offset] * 0.4; # left \& $stream2[$i + 1] = $stream[$i + 1] * 0.6 + $last_stream[$samples + $i \- $offset + 1] * 0.4; # right \& } \& } \& else \& { \& $stream2[$i] = $stream[$i] * 0.6 + $stream[$i \- $offset] * 0.4; # left \& $stream2[$i + 1] = $stream[$i + 1] * 0.6 + $stream[$i \- $offset + 1] * 0.4; # right \& } \& } \& \& @last_stream = @stream; \& return @stream2; \& }; \& \& my $effect_done = sub \& { \& # you may do something here \& }; \& \& SDL::Mixer::open_audio( 44100, SDL::Constants::AUDIO_S16, 2, 1024 ); \& \& my $playing_channel = SDL::Mixer::Channels::play_channel( \-1, SDL::Mixer::Samples::load_WAV(\*(Aqtest/data/sample.wav\*(Aq), \-1 ); \& SDL::Mixer::Effects::register($playing_channel, $echo_effect_func, $effect_done, 0); \& SDL::delay(2000); \& SDL::Mixer::Effects::unregister($playing_channel, $echo_effect_func); \& \& SDL::Mixer::close_audio(); \& SDL::quit(); .Ve .SS unregister .IX Subsection "unregister" .Vb 1 \& SDL::Mixer::Effects::unregister( $channel, $effect_callback ); .Ve .PP Remove the registered effect function from the effect list for channel. If the channel is active the registered effect will have its \f(CW$done_callback\fR function called, if it was specified in SDL::Mixer::Effects::register. .PP Returns: Zero on errors, such as invalid channel, or effect function not registered on channel. .PP \&\fBNote\fR: Do not use this on a threaded perl. This will crash. .SS unregister_all .IX Subsection "unregister_all" .Vb 1 \& SDL::Mixer::Effects::unregister_all( $channel ); .Ve .PP This removes all effects registered to \f(CW$channel\fR. If the channel is active all the registered effects will have their \f(CW$done_callback\fR functions called, if they were specified in SDL::Mixer::Effects::register. .PP Returns: Zero on errors, such as channel not existing. .PP \&\fBNote\fR: Do not use this on a threaded perl. This will crash. .SS set_post_mix .IX Subsection "set_post_mix" .Vb 1 \& SDL::Mixer::Effects::set_post_mix( $effect_callback, $arg ); .Ve .PP Hook a processor function to the postmix stream for post processing effects. You may just be reading the data and displaying it, or you may be altering the stream to add an echo. This processor is never really finished, until you call it without arguments. There can only be one postmix function used at a time through this method. Use SDL::Mixer::Effects::register with MIX_CHANNEL_POST to use multiple postmix processors. This postmix processor is run AFTER all the registered postmixers set up by SDL::Mixer::Effects::register. .PP \&\fBNote\fR: Do not use this on a threaded perl. This will crash. .SS set_distance .IX Subsection "set_distance" .Vb 1 \& SDL::Mixer::Effects::set_distance( $channel, $distance ); .Ve .PP This effect simulates a simple attenuation of volume due to distance. The volume never quite reaches silence, even at max distance (\f(CW255\fR). .PP NOTE: Using a distance of \f(CW0\fR will cause the effect to unregister itself from channel. You cannot unregister it any other way, unless you use SDL::Mixer::Effects::unregister_all on the channel. .PP Returns: Zero on errors, such as an invalid channel, or if Mix_RegisterEffect failed. .SS set_panning .IX Subsection "set_panning" .Vb 1 \& SDL::Mixer::Effects::set_panning( $channel, $left, $right ); .Ve .PP This effect will only work on stereo audio. Meaning you called SDL::Mixer::open_audio with 2 channels. .PP \&\fBNote\fR: Setting both left and right to 255 will unregister the effect from channel. You cannot unregister it any other way, unless you use SDL::Mixer::Effects::unregister_all on the channel. .PP \&\fBNote\fR: Using this function on a mono audio device will not register the effect, nor will it return an error status. .PP Returns: Zero on errors, such as bad channel, or if SDL::Mixer::Effects::register failed. .SS set_position .IX Subsection "set_position" .Vb 1 \& SDL::Mixer::Effects::set_position( $channel, $angle, $distance ); .Ve .PP This effect emulates a simple 3D audio effect. It's not all that realistic, but it can help improve some level of realism. By giving it the angle and distance from the camera's point of view, the effect pans and attenuates volumes. .PP \&\f(CW$angle\fR is the direction in relation to forward from 0 to 360 degrees. Larger angles will be reduced to this range using angles % 360. .IP \(bu 4 0 = directly in front. .IP \(bu 4 90 = directly to the right. .IP \(bu 4 180 = directly behind. .IP \(bu 4 270 = directly to the left. .PP So you can see it goes clockwise starting at directly in front. .PP \&\f(CW$distance\fR is \f(CW0\fR(close/loud) to \f(CW255\fR(far/quiet). .PP \&\fBNote\fR: Using angle and distance of \f(CW0\fR, will cause the effect to unregister itself from channel. You cannot unregister it any other way, unless you use SDL::Mixer::Effects::unregister_all on the channel. .PP Returns: Zero on errors, such as an invalid channel, or if SDL::Mixer::Effects::register failed. .SS set_reverse_stereo .IX Subsection "set_reverse_stereo" .Vb 1 \& SDL::Mixer::Effects::set_reverse_stereo( $channel, $flip ); .Ve .PP If you pass \f(CW1\fR to \f(CW$flip\fR it simple reverse stereo, swaps left and right channel sound. .PP \&\fBNote\fR: Using a flip of \f(CW0\fR, will cause the effect to unregister itself from channel. You cannot unregister it any other way, unless you use SDL::Mixer::Effects::register on the channel. .SH AUTHORS .IX Header "AUTHORS" See "AUTHORS" in SDL.