#!/usr/bin/perl use warnings; use strict; use Audio::DSP; #alsamixer must be setup right, just turn everything up :-) my ($buf, $chan, $fmt, $rate) = (4096, 1, 16, 44100); #use the formats from soundcard.h, plain 16 for $fmt might not work with sblive #($buf, $chan, $fmt, $rate) = (4096, 1, 8, 8192); #crummy minimum sound my $dsp = new Audio::DSP( buffer => $buf, channels => $chan, format => $fmt, rate => $rate); my $seconds = 5; my $length = ($chan * $fmt * $rate * $seconds) / 8; $dsp->init() || die $dsp->errstr(); # Record 5 seconds of sound for (my $i = 0; $i < $length; $i += $buf) { $dsp->read() || die $dsp->errstr(); } print "Play Back\n"; # Play it back for (;;) { $dsp->write() || last; } $dsp->close(); #### require 'sys/ioctl.ph'; #### #!/usr/bin/perl my $file = shift || 'testout.wav'; open FH, "< $file" or warn "$!\n"; open(DSP,">/dev/dsp") or warn "$!\n"; while ( 4096 == read( FH, my $buffer, 4096 ) ) { print DSP $buffer; } #1liner #perl -e 'local $/;$w=<>;open(F,">","/dev/dsp") && print F $w;' dtmf.wav #### #!/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);