PageRenderTime 13ms CodeModel.GetById 8ms app.highlight 1ms RepoModel.GetById 2ms app.codeStats 0ms

/lib/pods/SDLx/Sound.pod

http://github.com/PerlGameDev/SDL
Unknown | 125 lines | 78 code | 47 blank | 0 comment | 0 complexity | 476f1045acb87aed3f172cf9eb70be81 MD5 | raw file
  1
  2=head1 NAME
  3
  4SDLx::Sound
  5
  6=head1 CATEGORY
  7
  8Extension
  9
 10=head1 SYNOPSIS
 11
 12    use SDLx::Sound;
 13
 14    my $snd = SDLx::Sound->new();
 15    
 16    # loads and plays a single sound now
 17    $snd->play('myfile.wav');
 18
 19    # load a single file
 20    $snd->load('theSound.aif');
 21
 22    # plays it or all loaded files
 23    $snd->play();
 24
 25    # more sounds
 26    my %files = (
 27        channel_01 => "/my_sound1.wav",
 28        channel_02 => "/my_sound2.ogg"
 29    );
 30
 31    # times sounds bangs
 32    my %times = (
 33        channel_01 => 0,      # start
 34        channel_01 => 1256,   # milliseconds
 35        channel_02 => 2345
 36    );
 37    
 38    # Load files in channels for realtime play
 39    $snd->load(%files);
 40
 41    # sets sound channel_01 loudness
 42    $snd->loud('channel_01', 80);       # loud at 80%
 43    $snd->play(%times);                 # play loaded files at times
 44    $snd->play;                         # play again
 45
 46    # plays sound channel_01 at 578 milliseconds from now
 47    $snd->play('channel_01', 578);
 48
 49    # fades sound 
 50    $snd->fade('channel_02', 2345, 3456, -20);
 51
 52    # in a single act do the whole Sound
 53    my $snd = SDLx::Sound->new(
 54        files => (
 55            channel_01 => "/my_sound1.wav",
 56            channel_02 => "/my_sound2.ogg"
 57 
 58        ), 
 59        loud  => (
 60            channel_01 => 80,
 61            channel_02 => 75
 62        ),
 63        times => (
 64            channel_01 => 0,      # start
 65            channel_01 => 1256,   # milliseconds
 66            channel_02 => 2345
 67        ),
 68        fade  => (
 69            channel_02 => [2345, 3456, -20]
 70        )
 71    )->play();
 72
 73=head1 DESCRIPTION
 74
 75
 76You can think about the SDLx::Sound at 2 approaches. 
 77
 78=over 4
 79
 80=item * A simple sound or 
 81
 82=item * The sound of your game or app. 
 83
 84=back
 85
 86Your application will say what the best approach.
 87
 88In a taste that resembles to perl and to SDL, our SDLx:Sound hooks at SDL::Audio and SDL::Mixer with a graceful and simple interface that can offer to monks a modern perlish way to manage sounds.
 89
 90An SDLx::Sound object can load sounds from filesystem, play it, adjust this loudness level or stops the sound. 
 91
 92Each sound will play in the next available channel, so it can be handled isolately.
 93
 94=head1 METHODS
 95
 96=head2 new
 97
 98Returns a new instance of SDLx::Sound
 99
100=head2 load
101
102
103=head2 play
104
105 $sdlx_sound->play('file.wav');
106
107Play a file
108
109=head2 pause
110
111=head2 resume
112
113=head2 stop
114
115
116=head1 AUTHORS
117
118See L<SDL/AUTHORS>.
119
120=head1 COPYRIGHT & LICENSE
121
122This program is free software; you can redistribute it and/or modify it
123under the same terms as Perl itself.
124
125