I put the script in a little package with the sample sounds at z-sampler
UPDATE 10/25/2004 Added a text menu.
#!/usr/bin/perl use SDL; use SDL::Mixer; use SDL::Music; use SDL::App; use SDL::Event; use SDL::Rect; use SDL::Color; use SDL::Tool::Font; # See # http://aspn.activestate.com/ASPN/CodeDoc/SDL-sdlpl/SDL/Mixer.html $|++; $width = 400; $height = 300; my $app = new SDL::App( -title => "Sampler", -width => 400, -height => 300, -depth => 8 ); my $rect = SDL::Rect->new( -height => 250, -width => 360, -x => 20, -y => 20, ); my $color = SDL::Color->new( -r => 0x00, -g => 0xff, -b => 0xff, ); $app->fill( $rect, $color ); $app->update($rect); my $fontobj = new SDL::Tool::Font( -italic => 1, #-normal -bold -italic -underline + -ttfont => 'arial.ttf', -size => 20, -fg => $SDL::Color::black, -bg => $SDL::Color::black, ); #SDL::Tool::Font::print( $app, 30,30,"hello World"); $fontobj->print( $app, 30, 30, "m ->music" ); $fontobj->print( $app, 30, 50, "c ->cannon" ); $fontobj->print( $app, 30, 70, "e ->explosion" ); $fontobj->print( $app, 30, 120, "esc ->quit" ); $app->update($rect); $mixer = SDL::Mixer->new( -frequency => MIX_DEFAULT_FREQUENCY, -format => MIX_DEFAULT_FORMAT, -channels => MIX_DEFAULT_CHANNELS, -size => 4096 ); # provides 8 channels of # 16 bit audio at 22050 Hz. and a single channel of music. my $music = new SDL::Music('1bb.mp3'); #background can be mp3,o +gg or wav my $sound0 = new SDL::Sound('cannon.wav'); #effects must be wav $sound0->volume(128); #max my $sound1 = new SDL::Sound('explosion.wav'); $sound1->volume(128); #max $mixer->music_volume(MIX_MAX_VOLUME); my $event = new SDL::Event; my %events = ( SDL_KEYUP() => sub { my ($e) = @_; my $key = SDL::GetKeyName( $e->key_sym() ); print "$key up\n"; if ( $key eq 'm' ) { $mixer->play_music( $music, 10 ) } if ( $key eq 'c' ) { $mixer->play_channel( 0, $sound0, 0 ) } if ( $key eq 'e' ) { $mixer->play_channel( 1, $sound1, 0 ) } }, SDL_KEYDOWN() => sub { my ($e) = @_; if ( $e->key_sym() == SDLK_ESCAPE ) { exit } my $key = SDL::GetKeyName( $e->key_sym() ); print "$key down\n"; }, SDL_QUIT() => sub { exit }, ); $app->loop( \%events );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SDL sound sampler-mixer
by Discipulus (Canon) on Jan 04, 2005 at 15:24 UTC | |
by zentara (Cardinal) on Jan 04, 2005 at 20:34 UTC |