1package Audio::Mixer; 2 3# 4# Library to query / set various sound mixer parameters. 5# See POD documentation below for more info. 6# 7# Copyright (c) 2000 Sergey Gribov <sergey@sergey.com> 8# This is free software with ABSOLUTELY NO WARRANTY. 9# You can redistribute and modify it freely, but please leave 10# this message attached to this file. 11# 12# Subject to terms of GNU General Public License (www.gnu.org) 13# 14# Last update: $Date: 2002/04/30 00:48:21 $ by $Author: sergey $ 15# Revision: $Revision: 1.4 $ 16 17use strict; 18use Carp; 19use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD); 20 21require Exporter; 22require DynaLoader; 23require AutoLoader; 24 25@ISA = qw(Exporter DynaLoader); 26# Items to export into callers namespace by default. Note: do not export 27# names by default without a very good reason. Use EXPORT_OK instead. 28# Do not simply export all your public functions/methods/constants. 29@EXPORT = qw(); 30@EXPORT_OK = qw( 31 MIXER 32); 33$VERSION = '0.7'; 34 35sub AUTOLOAD { 36 # This AUTOLOAD is used to 'autoload' constants from the constant() 37 # XS function. If a constant is not found then control is passed 38 # to the AUTOLOAD in AutoLoader. 39 40 my $constname; 41 ($constname = $AUTOLOAD) =~ s/.*:://; 42 croak "& not defined" if $constname eq 'constant'; 43 my $val = constant($constname, @_ ? $_[0] : 0); 44 if ($! != 0) { 45 if ($! =~ /Invalid/) { 46 $AutoLoader::AUTOLOAD = $AUTOLOAD; 47 goto &AutoLoader::AUTOLOAD; 48 } 49 else { 50 croak "Your vendor has not defined Audio::Mixer macro $constname"; 51 } 52 } 53 no strict 'refs'; 54 *$AUTOLOAD = sub () { $val }; 55 goto &$AUTOLOAD; 56} 57 58bootstrap Audio::Mixer $VERSION; 59 60# Preloaded methods go here. 61 62# Autoload methods go after =cut, and are processed by the autosplit program. 63 64 65sub get_cval { 66 my $channel = shift; 67 my ($val, $lcval, $rcval); 68 $val = get_param_val($channel); 69 $lcval = $val & 0xff; 70 $rcval = $val & 0x10000 ? ($val & 0xff00) >> 8 : $lcval; 71 return wantarray ? ($lcval, $rcval) : $val; 72} 73 74sub set_cval { 75 my ($channel, $lcval, $rcval) = @_; 76 $lcval = 0 unless $lcval; 77 $rcval = $lcval unless $rcval; 78 return set_param_val($channel, $lcval, $rcval); 79} 80 81sub get_mixer_params { 82 return(split(/ /, get_params_list())); 83} 84 851; 86__END__ 87# Below is the stub of documentation for your module. You better edit it! 88 89=head1 NAME 90 91Audio::Mixer - Perl extension for Sound Mixer control 92 93=head1 SYNOPSIS 94 95 use Audio::Mixer; 96 $volume = Audio::Mixer::get_cval('vol'); 97 if (Audio::Mixer::set_cval('vol', 50, 40)) { 98 die("Can't set volume..."); 99 } 100 101=head1 DESCRIPTION 102 103Library to query / set various sound mixer parameters. 104 105This is just a very simple Perl interface which allows to 106set various sound mixer parameters. The most important 107probably 'vol' (volume). The list of all mixer parameters 108can be obtained using get_mixer_params() function. 109 110All values (lcval, rcval) are numbers in 0-100 range. 111 112=head1 FUNCTIONS 113 114get_cval(cntrl) - Get parameter value 115Parameters: 116 cntrl - name of parameter 117Returns: 118 in array context: (lcval, rcval), where: 119 lcval - left channel value 120 rcval - right channel value 121 in scalar context returns value of get_param_val() (see below) 122 123set_cval(cntrl, lcval, rcval) - Set parameter value 124Parameters: 125 cntrl - name of parameter 126 lcval - left channel value 127 rcval - right channel value (optional, if not supplied 128 will be equal to lcval) 129Returns: 0 if Ok, -1 if failed 130 131set_source(cntrl) - set record source 132Parameters: 133 cntrl - name of channel to record from 134Returns: 0 if Ok, -1 if failed 135 136get_source(cntrl) - get record source 137Returns: 138 name of channel to record from 139 140set_mixer_dev(fname) - Set mixer device name (optional), 141 /dev/mixer is used by default 142 fname - device name 143Returns: 0 if Ok 144 145init_mixer() - Initialize mixer (open it) 146 set_cval() / get_cval() opens / closes the mixer each 147 time they called unless init_mixer() called before. 148 In case if init_mixer() called before all other 149 functions will use already opened device instead of 150 opening it each time. 151 152close_mixer() - Close device. 153 Should be called only if init_mixer() was used. 154 155get_mixer_params() - Get list of mixer parameters 156Returns: list of parameters names. 157 158LOW LEVEL FUNCTIONS: 159 160get_param_val(cntrl) - Get parameter value 161Parameter: 162 cntrl - name of parameter 163Returns: 164 integer value, which will be constructed as follows: 165 lower byte (x & 0xff) - value of the left channel 166 (or whole value) 167 next byte (x & 0xff00) - value of the right channel 168 third byte (x & 0xff0000) - flags (if x & 0x10000 then 169 2 channels exist) 170 or -1 in case of failure. 171 172set_param_val(cntrl, lcval, rcval) - Set parameter value. 173 Here all parameters are mandatory (in contrast to set_cval()). 174Parameters: 175 cntrl - name of parameter 176 lcval - left channel value 177 rcval - right channel value 178Returns: 0 if Ok, -1 if failed 179 180=head1 AUTHOR 181 182Sergey Gribov, sergey@sergey.com 183 184=head1 LICENSE 185 186Copyright (c) 2001 Sergey Gribov. All rights 187reserved. This program is free software; you can 188redistribute it and/or modify it under the same terms as 189Perl itself. 190 191=head1 SEE ALSO 192 193perl(1). 194 195=cut 196