use Audio::Data;
use Audio::Play;
$audio = Audio::Data->new(...)
$svr = Audio::Play->new;
$svr->play($audio);
Audio::DSP or Audio::OSS may be good options on Linux.
The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon
| [reply] [d/l] |
Audio::Play and SDL can both play sample files in a fairly portable way. Audio::Play can also take a buffer of generated samples. I'm currently working on a module that can generate all kinds of audio streams, but it doesn't really have as simple an interface as Audio::Beep.
If you want to experiment, you can also try my very new Audio::PortAudio module (should be on CPAN soon - i uploaded it 2 hours ago). It does more or less the same thing Audio::Play does, but also does input and multiple channels.
| [reply] |
The Audio::DSP module allows you to write generated tones to the soundcard. The PDL::Audio module generates realistic bird calls from data. :-) The script below, generates a series of numbers, that is fed to the soundcard, play with it for different tones.
#!/usr/bin/perl
use warnings;
use strict;
use Audio::DSP;
$| = 1;
my $sample_rate = 22050; #44100 gives best sound, but highest cpu
#8000 works
my $channels = 1;
my $format = AFMT_S16_LE; #8 bit won't work on SBLive
my $buffer = 4096;
my $dsp = new Audio::DSP(buffer => $buffer,
channels => $channels,
format => $format,
rate => $sample_rate);
$dsp->init() || die $dsp->errstr();
############################################################
my $freq_adj = .1;
my $vol = .5;
my $toggle = 1;
while(1){
make_tone($freq_adj, $vol);
if(($freq_adj > 4) or ($freq_adj < .1)){ $toggle *= -1;}
$freq_adj += ($toggle * .001); #higher increment numbers are slower
#0 is pure tone
}
sub make_tone {
my $rad = 0;
my ($freq_adj, $vol) = @_;
while ( $rad < 6.283 ){
$rad += $freq_adj;
my $raw = ($vol*32768) * sin($rad); #max times
my $num = pack( 'V', $raw );
$dsp->dwrite($num);
}
}
| [reply] [d/l] |
Strange for both Audio::DSP and Audio::port I get a vast number of the same errors when trying to install either....
| [reply] |
Well I got the Audio::DSP to install on a different linux box, so I am playing with it now. Would it be too much to ask what the code would be to play a tone of 300 Hz? Thanks :-)
I figured out what the frequency control is. I appears that Audio::DSP doe not lend itself to playing a tune. Am I mistaken?
| [reply] |