#!/usr/bin/perl use SDL; use SDL::Mixer; use SDL::Music; use SDL::App; use SDL::Event; $|++; $width=400; $height=300; my $app = new SDL::App( -title => "Sampler", -width => 400, -height =>300, -depth => 8); $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,ogg 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);