Audio::ESD - Perl extension for talking to the Enlightened Sound Daemon
use Audio::ESD; my $stream = Audio::ESD->play_stream({ # these are the defaults sample_rate => 16000, channels => 1, fallback => 0, bits_sample => 16, encoding => 'linear' }) or die "Failed to open ESD stream: $!\n"; print $stream $data; # etcetera
This module provides a Perl wrapper around the Enlightened Sound Daemon's client library. Input, output, and monitoring streams are supported, as well as some (but not all) of the control functions. Samples are supported but untested.
Audio streams can be opened for playback, recording, monitoring, or filtering. There are separate `constructor' class methods for doing all of these things. All of these methods accept a single optional argument, which is a reference to a hash possibly containing the following stream parameters (defaults are supplied if the parameters are not present):
The sampling rate for audio written to and/or read from the stream, expressed in samples per second. Defaults to 16000
The sample size in bits. Currently acceptable values are 8 and 16. Defaults to 16.
The number of channels (interleaved). Currently acceptable values are 1 and 2. Defaults to 1.
The audio encoding format used. The only currently acceptable value is 'linear' (which means linear PCM). Maybe someday Esound will support others.
To open a stream for playback, use play_stream:
my $stream = Audio::ESD->play_stream(\%opts);
This method also supports an extra option, 'fallback'. If this is true, the Esound library will "fall back" to the local audio device if a connection to the ESD server could not be made (or so the documentation says, at least).
To open a stream for recording, use record_stream:
my $stream = Audio::ESD->record_stream(\%opts);
This method also supports the 'fallback' option.
To open a stream for monitoring (i.e. capturing the mixed output stream from the server), use monitor_stream:
my $stream = Audio::ESD->monitor_stream(\%opts);
To open a stream for filtering, use filter_stream:
my $stream = Audio::ESD->filter_stream(\%opts);
Apparently, this allows you read blocks of data from the output stream, do some transformations on them, then write them back, and have ESD play them.
To open a general-purpose control connection to the ESD server, use the open_sound class method:
my $esd = Audio::ESD->open_sound($hostname);
If $hostname is undefined, a local ESD will be contacted via a Unix domain socket.
$hostname
As with the audio streams, you can read and write to this connection as if it were a normal filehandle (since, in fact, that is what it is...) and thus, if you want to take your chances with the "over-the-wire" protocol you are free to do so.
However, you most likely just want to use this connection to access various parameters in the server, and don't worry, there are some methods for that:
$esd->send_auth();
$esd->lock();
$esd->unlock();
$esd->standby();
$esd->resume();
$esd->sample_cache($format, $rate, $length, $name);
$esd->confirm_sample_cache();
my $sample_id = $esd->sample_getid($name);
$esd->sample_play($sample_id);
$esd->sample_loop($sample_id);
$esd->sample_stop($sample_id);
$esd->sample_free($sample_id);
$esd->set_stream_pan($stream_id, $left_scale, $right_scale);
$esd->set_default_sample($stream_id, $left_scale, $right_scale);
my $latency = $esd->get_latency();
my $standby = $esd->get_standby_mode();
my $server_info = $esd->get_server_info();
my $info = $esd->get_all_info();
$server_info->print_server_info();
$info->print_all_info();
The following constants can be imported from Audio::ESD. They are mostly useful for the format argument to some functions. You can import all of them with the :standard tag.
Audio::ESD
ESD_ADPCM ESD_BITS16 ESD_BITS8 ESD_BUF_SIZE ESD_DEFAULT_PORT ESD_DEFAULT_RATE ESD_ENDIAN_KEY ESD_KEY_LEN ESD_LOOP ESD_MASK_BITS ESD_MASK_CHAN ESD_MASK_FUNC ESD_MASK_MODE ESD_MONITOR ESD_MONO ESD_NAME_MAX ESD_PLAY ESD_RECORD ESD_SAMPLE ESD_STEREO ESD_STOP ESD_STREAM ESD_VOLUME_BASE
It probably leaks file descriptors or worse. Lots of stuff is untested and undocumented, and since the Esound API is full of happy surprises it's likely not to work.
David Huggins-Daines <dhd@cepstral.com>
perl(1), esd(1).
To install Audio::ESD, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Audio::ESD
CPAN shell
perl -MCPAN -e shell install Audio::ESD
For more information on module installation, please visit the detailed CPAN module installation guide.