NAME

Audio::Alsa::Mixer -- control alsa audio devices

SYNOPSIS

After some problems contoling the Volume of Alsa Devices (amixer is not easy to handle) i created this Package In this state it's more or less an hack around "amixer"

The Hirachy is:

Audio::Alsa::Mixer contains the Devices

Audio::Alsa::Mixer::Device contains the Controls

Audio::Alsa::Mixer::Device::Control contains the Channels

Example1

 #!/usr/bin/perl
 use strict;
 use warnings;
 use Audio::Alsa::Mixer;

 for(Audio::Alsa::Mixer->device_list())
 {
   print $_->name()."\n";
   print "  ID         : ".($_->id()//'')."\n"; # id() is special because the default Mixer has no ID.
   print "  Name       : ".$_->name()."\n";
   print "  ID-Name    : ".$_->id_name()."\n";
   print "  Mixer-Name : ".$_->mixer_name()."\n";
   print "  Full-Name  : ".$_->full_name()."\n";
   print "  Components : ".$_->components()."\n";
   print "  Description: ".$_->description()."\n";

   for($_->control_list())
   {
     print "   ".$_->name()."\n";
     for($_->channel_list())
     {
       print "     ".$_->name()."\n";
       print "       GET OUT:".$_->volume_out('%')."%\n";
       print "       GET IN :".$_->volume_in('%')."%\n";
       print "       MUTE   :".($_->mute()?"yes":"no")."\n";
     }
   }
   print "#####################################################\n";
 }

Example2

 #!/usr/bin/perl
 use strict;
 use warnings;
 use Audio::Alsa::Mixer;

 print "Volume: ",
       Alsa::Mixer->device('USB-Audio')->control('Speaker')->channel('Front Left')->volume_out('%'),
       "%\n";

 print "Volume: ",
       Alsa::Mixer->device()->control('Master')->channel('Front Left')->volume_out('%'),
       "%\n";

DESCRIPTION

Controll Alsa Audiodevices

AUTHOR

ToPeG

USING

alsa tool "amixer"

METHODS

Audio::Alsa::Mixer

Audio::Alsa::Mixer->device_list()

Get a list of all Devices controlled by Alsa

Special is the first Element. it's the primary controlled Device, and can be an virtual Device (when, as Example, PulseAudio is running) otherwise it's a copy on a device in the list.

Return:

List of Audio::Alsa::Mixer::Device Objects

Example:

 my @list=Audio::Alsa::Mixer->device_list();
Audio::Alsa::Mixer->device(<id>)

Get one Device by Name or Id If no Value is is set the Alsa-Default will returned

Return:

one Audio::Alsa::Mixer::Device Object or undef

Example:

 # get device with ID 0
 my $device=Audio::Alsa::Mixer->device(0);

Audio::Alsa::Mixer::Device

$device->id()
$device->id_name()
$device->components()
$device->mixer_name()
$device->name()
$device->full_name()
$device->description()
$device->control_list()

get a list of the controls

A Control is a group of output/input Channel or any other single element, that controls the audio in/output Actualy only input ot output Channels are visible. Switces and other Elements are ignored

Return:

a list of Audio::Alsa::Mixer::Device::Control Objects

Example:

 my @controls=$device->control_list();
$device->control(<name>)

get a one control by name

Return:

returns an Audio::Alsa::Mixer::Device::Control Object or undef

Example:

 my $control=$device->control('Master');

Audio::Alsa::Mixer::Device::Control

$control->name()
$control->volume_in_min()

the volume of one input Channel can't be smaler than this value

$control->volume_in_max()

the volume of one input Channel can't be bigger than this value

$control->volume_in_max()

the volume of one output Channel can't be smaler than this value

$control->volume_in_max()

the volume of one output Channel can't be bigger than this value

$control->channel_list()

get a list of the channels of this Control

A Channel is a singe input or output Emement

Return:

a list of Audio::Alsa::Mixer::Device::Control::Channel Objects

Example:

 my @channels=$control->channel_list();
$control->channel(<name>)

get one channel of this Control by name

Return:

returns an Audio::Alsa::Mixer::Device::Control::Channel Object or undef

Example:

 my $channel=$control->channel('Left Front');
$control->volume_out(<value>)

get/set the ouput Volumes a Control

The value can be an integer value or an percent value as string.

Return:

returns a list of the volumes of every otput Channel in the Control. If an percent value or an singe "%" as value is set the returnd values are aso in percent

Example:

 # set volume in percent
 my @volumes_percent=$control->volume_out('100%');
 # get volume in percent
 my @volumes_percent=$control->volume_out('%');
 #set volume
 my @volumes=$control->volume_out(0);
 my @volumes=$control->volume_in($control->volume_out_max);
 my @volumes=$control->volume_in($control->volume_out_min);
 #get volume
 my @volumes=$control->volume_out();
$control->volume_in(<value>)

get/set the input Volumes a Control

works equal to volume_out

Return:

returns a list of the volumes of every input Channel in the Control

Example:

 my @volumes=$control->volume_in('100%');
 my @volumes=$control->volume_in($control->volume_in_max);
$control->mute(<value>)

get/set mute Control

If the value is the string 'toggle' the actual state will be switched. If the value is 'mute' the Control will muted. If the value is 'unmute' the Control will unmuted. Else everey true value will mute the Control unmute otherwise.

Return:

return true/fasle (1/0) if the Control is muted

Example:

 my @volumes=$control->volume_in('100%');
 my @volumes=$control->volume_in($control->volume_in_max);

Audio::Alsa::Mixer::Device::Control::Channel

$channel->mute()

return tue if Channes is muted

Return:

return true/fasle (1/0) if the Channel is muted

Example:

 print 'Channel ',$channel->name(),' is ',$channel->mute()?'':'not ',"muted \n";
$channel->mute()

Channel Name

$channel->volume_out()

get/set volume for output

works like volume_out in Alsa::Mixer::Controler

$channel->volume_in()

get/set volume for input

works like volume_in in Alsa::Mixer::Controler

$channel->volume_in_min()
$channel->volume_in_max()
$channel->volume_out_min()
$channel->volume_out_max()

AUTHOR

Tobias Grönhagen <osm@topeg.de>

VERSION

Version 0.1 2 Feb 2011

COPYRIGHT

Copyright (c) Tobias Grönhagen. All rights reserved.

LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms and conditions as Perl itself.

This means that you can, at your option, redistribute it and/or modify it under either the terms the GNU Public License (GPL) version 2 or later, or under the Perl Artistic License.

See http://dev.perl.org/licenses/

DISCLAIMER

THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

Use of this software in any way or in any form, source or binary, is not allowed in any country which prohibits disclaimers of any implied warranties of merchantability or fitness for a particular purpose or any disclaimers of a similar nature.

IN NO EVENT SHALL I BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION (INCLUDING, BUT NOT LIMITED TO, LOST PROFITS) EVEN IF I HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE