Audio-OSS
view release on metacpan or search on metacpan
}
# Don't bother getting this from the header file
@DevNames = qw(
vol bass treble synth pcm speaker line
mic cd mix pcm2 rec igain ogain line1 line2
line3 dig1 dig2 dig3 phin phout video radio monitor
);
# Use push, because BEGIN blocks may frob these
push @EXPORT_OK, qw(dsp_sync dsp_reset set_fragment get_fmt
get_outbuf_ptr get_inbuf_ptr
get_outbuf_info get_inbuf_info
mixer_read mixer_write @DevNames);
push @{$EXPORT_TAGS{funcs}},
qw[
dsp_sync
dsp_reset
set_fragment
get_fmt
get_outbuf_ptr
get_inbuf_ptr
get_outbuf_info
get_inbuf_info
mixer_read
mixer_write
];
$VERSION=0.05_01;
ioctl $dsp, SNDCTL_DSP_SYNC, 0;
}
sub get_fmt {
my $dsp = shift;
my $sfmt = pack "L", AFMT_QUERY;
ioctl $dsp, SNDCTL_DSP_SETFMT, $sfmt or return undef;
return unpack "L", $sfmt;
}
sub set_fragment {
my ($dsp, $shift, $max) = @_;
# This is not really documented, but the code of the sound drivers
# says that this is two halfwords packed together in host byte
# order, the MSW being the shift (assuming this means size log 2),
# the lower being the maximum number. In general it seems that
# shift must be 4 <= shift < 16, maxfrags must be >= 4.
my $sfrag = pack "L", (($max << 16) | $shift);
ioctl $dsp, SNDCTL_DSP_SETFRAGMENT, $sfrag;
}
sub get_outbuf_ptr {
my $dsp = shift;
my $cinfo = pack CINFO_TMPL;
ioctl($dsp, SNDCTL_DSP_GETOPTR, $cinfo) or return undef;
return unpack CINFO_TMPL, $cinfo;
}
sub get_inbuf_ptr {
dsp_reset($dsp) or die "reset failed: $!";
my $mask = get_supported_formats($dsp);
if ($mask & AFMT_S16_LE) {
set_fmt($dsp, AFMT_S16_LE) or die set format failed: $!";
}
my $current_format = set_fmt($dsp, AFMT_QUERY);
my $sps_actual = set_sps($dsp, 16000);
set_fragment($dsp, $fragshift, $nfrags);
my ($frags_avail, $frags_total, $fragsize, $bytes_avail)
= get_outbuf_info($dsp);
my ($bytes, $blocks, $dma_ptr) = get_outbuf_ptr($dsp);
my $mixer = IO::Handle->new("</dev/mixer") or die "open failed: $!";
my $miclevel = mixer_read($mixer, SOUND_MIXER_MIC);
=head1 DESCRIPTION
C<Audio::OSS> is a pure Perl interface to the Open Sound System, as
used on Linux, FreeBSD, and other Unix systems.
This tag imports the following functions, which perform various
operations on the PCM audio device:
dsp_sync
dsp_reset
dsp_get_caps
set_sps
set_fmt
set_stereo
get_supported_fmts
set_fragment
get_outbuf_ptr
get_inbuf_ptr
get_outbuf_info
get_inbuf_info
mixer_read_devmask
mixer_read_recmask
mixer_read_stereodevs
mixer_read_caps
mixer_read
mixer_write
( run in 1.012 second using v1.01-cache-2.11-cpan-364913b4093 )