[BACK]Return to aucat.1 CVS log [TXT][DIR] Up to [local] / src / usr.bin / aucat

File: [local] / src / usr.bin / aucat / aucat.1 (download)

Revision 1.66, Tue Apr 6 20:07:01 2010 UTC (14 years, 2 months ago) by ratchov
Branch: MAIN
Changes since 1.65: +70 -11 lines

aucat (server):

  - make the ``-m mode'' option per subdevice, allowing
    subdevices to be play-only or rec-only even if the
    server is full-duplex

  - add ``monitoring'' mode (with ``-m mon''). This is a
    record-only stream from which played streams can be
    recorded (kind of ``record what you hear'').

  - allow MIDI devices to be subscribed to the controlling
    MIDI port of the server, ie what midicat does (with -f
    option), but using the -q option.

  - add flow control to the protocol, and serialize clock
    ticks (sio_onmove() calls) and data chunks.  This should
    fix certain full-duplex programs, broken with ``magic''
    block/buffer size combinations.

  - enable 3 block latency which is the minimum theoretical.
    Make -z and -b options correspond to device parameters.

  - make sio_getcap(3) the same for aucat and sun backends,
    ie return whatever is supported (``everything'' in the
    aucat case, since everything is actulally supported).

aucat (player):

  - enable ``-m mode'' option  to select between monitoring
    and recording when ``-o file'' is used.

  - plug MIDI code to non-server codepath. The MIDI control
    device is specified with the ``-q device'' option, as in
    server mode.

  - impliment lseek()'ing within files (controlled
    through MIDI). Necessary to use aucat with a MIDI
    sequencer.

midicat (thrubox):

  - rename ``-f'' flag to ``-q'', so it has the
    same name as in aucat (-f is still working)

ok jakemsr@, tweaks from jmc@

.\"	$OpenBSD: aucat.1,v 1.66 2010/04/06 20:07:01 ratchov Exp $
.\"
.\" Copyright (c) 2006 Alexandre Ratchov <alex@caoua.org>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: April 6 2010 $
.Dt AUCAT 1
.Os
.Sh NAME
.Nm aucat
.Nd audio server and stream manipulation tool
.Sh SYNOPSIS
.Nm aucat
.Bk -words
.Op Fl dlnu
.Op Fl b Ar nframes
.Op Fl C Ar min : Ns Ar max
.Op Fl c Ar min : Ns Ar max
.Op Fl e Ar enc
.Op Fl f Ar device
.Op Fl h Ar fmt
.Op Fl i Ar file
.Op Fl m Ar mode
.Op Fl o Ar file
.Op Fl q Ar device
.Op Fl r Ar rate
.Op Fl s Ar name
.Op Fl t Ar mode
.Op Fl U Ar unit
.Op Fl v Ar volume
.Op Fl x Ar policy
.Op Fl z Ar nframes
.Ek
.Sh DESCRIPTION
The
.Nm
utility can record one input stream
and store it on multiple destination files,
doing the necessary conversions on the fly.
It can play, convert, and mix multiple input files simultaneously,
and can also act as an audio server.
.Nm
also has a legacy mode that works like previous versions of
.Nm ,
which does not convert on the fly and supports playback of .au files.
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl b Ar nframes
The buffer size of the audio device in frames.
A frame consists of one sample for each channel in the stream.
This is the number of frames that will be buffered before being played
and thus controls the playback latency.
.It Xo
.Fl C Ar min : Ns Ar max ,
.Fl c Ar min : Ns Ar max
.Xc
The range of channel numbers on the record or playback stream, respectively.
The default is 0:1, i.e. stereo.
.It Fl d
Do not daemonize.
If this option is specified,
.Nm
will run in the foreground and log to
.Em stderr .
.It Fl e Ar enc
Encoding of the playback or recording stream (see below).
The default is signed, 16-bit, native byte order.
.It Fl f Ar device
The
.Xr sndio 7
audio device to use for playing and/or recording.
.It Fl h Ar fmt
File format of the playback or record stream (see below).
The default is auto.
.It Fl i Ar file
Add this file to the list of files to play.
If the option argument is
.Sq -
then standard input will be used.
.It Fl l
Listen for incoming connections on a
.Ux Ns -domain
socket.
This allows clients to use
.Nm
instead of the physical audio device for audio input and output
in order to share the physical device with other clients.
The default
.Xr sndio 7
device exposed is
.Pa aucat:0
.Pq "also known as" Pa aucat:0.default
but other names can be used with the
.Fl s
option.
.It Fl m Ar mode
Set the stream mode.
Valid modes are
.Ar play ,
.Ar rec ,
and
.Ar mon ,
corresponding to playback, recording and monitoring.
A monitoring stream is a fake recording stream corresponding to
the mix of all playback streams.
Multiple modes can be specified, separated by commas,
but the same stream cannot be used for both recording and monitoring.
The default is
.Ar play , rec
(i.e. full-duplex).
.It Fl n
Loopback mode.
Instead of using an audio device, send input streams
to the output, processing them on the fly.
This mode is useful to mix, demultiplex, resample or reencode
audio files offline.
.It Fl o Ar file
Add this file to the list of files in which to store recorded samples.
If the option argument is
.Sq -
then standard output will be used.
.It Fl q Ar device
The
.Xr sndio 7
MIDI device to use for controlling stream volumes or
to start multiple streams synchronously.
.It Fl r Ar rate
Sample rate in Hertz of the playback or record stream.
The default is 44100Hz.
.It Fl s Ar name
Add
.Ar name
to the list of sub-devices to expose in server mode.
Defining multiple sub-devices allows splitting a physical audio device
into logical devices having different properties (e.g. channel ranges).
The given
.Ar name
corresponds to the
.Dq option
part of the
.Xr sndio 7
device name string.
.It Fl t Ar mode
Select the way sub-devices are controlled by MMC (MIDI Machine Control) messages.
If the mode is
.Va off
(the default), then streams are not affected by MMC messages.
If the mode is
.Va slave ,
then streams are started synchronously by MMC start messages;
additionally, the server clock is exposed as MTC (MIDI Time Code)
messages allowing MTC-capable software or hardware to be synchronized
to audio streams.
.It Fl U Ar unit
Unit number to use when running in server mode.
Each
.Nm
server instance has an unique unit number,
used in
.Xr sndio 7
device names.
The default is 0.
.It Fl u
Normally
.Nm
tries to automatically determine the optimal parameters for the audio device;
if this option is specified,
it will instead use the parameters specified by the
.Fl Ccer
options.
.It Fl v Ar volume
Software volume attenuation of the playback stream.
The value must be between 1 and 127,
corresponding to \-42dB and \-0dB attenuation.
In server mode, clients inherit this parameter.
Reducing the volume in advance reduces a client's dynamic range,
but allows client volume to stay independent from the number
of clients as long as their number is small enough.
A good compromise is to use \-4dB attenuation (12 volume units)
for each additional client expected
(115 if 2 clients are expected, 103 for 3 clients, and so on).
.It Fl x Ar policy
Action when the output stream cannot accept
recorded data fast enough or the input stream
cannot provide data to play fast enough.
If the policy
is
.Dq ignore
(the default) then samples that cannot be written are discarded
and samples that cannot be read are replaced by silence.
If the policy is
.Dq sync
then recorded samples are discarded, but the same amount of silence will be written
once the stream is unblocked, in order to reach the right position in time.
Similarly silence is played, but the same amount of samples will be discarded
once the stream is unblocked.
If the policy is
.Dq error
then the stream is closed permanently.
.Pp
If a sub-device is created with
.Fl t ,
the
.Dq ignore
action is disabled for any stream connected to it
to ensure proper synchronization.
.It Fl z Ar nframes
The audio block size in frames.
This is the number of frames between audio clock ticks,
i.e. the clock resolution.
If a sub-device is created with
.Fl t ,
and MTC (Midi Time Code) is used for synchronization, the clock
resolution must be 96, 100 or 120 ticks per second for maximum
accuracy.
For instance, 120 ticks per second at 48000Hz corresponds
to a 400 frame block size.
.El
.Pp
If
.Nm
is sent
.Dv SIGHUP ,
.Dv SIGINT
or
.Dv SIGTERM ,
it terminates recording to files.
.Pp
Settings for input files
.Pq Fl i ,
output files
.Pq Fl o ,
and sub-devices
.Pq Fl s
can be changed using the
.Fl Ccehrvx
options.
The last
.Fl Ccehrvx
options specified before an
.Fl i ,
.Fl o ,
or
.Fl s
are applied to the corresponding file.
.Pp
Settings for the audio device
can be changed using the
.Fl Ccer
options.
They apply to the audio device only if the
.Fl u
option is given as well.
The last
.Fl Ccer
option specified before an
.Fl f
is applied to
.Ar device .
.Pp
If no audio device
.Pq Fl f
is specified,
settings are applied as if
the default device is specified as the last argument.
If no sub-devices
.Pq Fl s
are specified
settings are applied as if
.Ar default
is specified as the last argument.
.Pp
File formats are specified using the
.Fl h
option.
The following file formats are supported:
.Bl -tag -width s32lexxx -offset indent
.It raw
Headerless file.
This format is recommended since it has no limitations.
.It wav
Microsoft WAVE file format.
There are limitations inherent to the file format itself:
not all encodings are supported,
file sizes are limited to 2GB,
and the file must support the
.Xr lseek 2
operation (e.g. pipes do not support it).
.It auto
Try to guess, depending on the file name.
.El
.Pp
Encodings are specified using the
.Fl e
option.
The following encodings are supported:
.Pp
.Bl -tag -width s32lexxx -offset indent -compact
.It s8
signed 8-bit
.It u8
unsigned 8-bit
.It s16le
signed 16-bit, little endian
.It u16le
unsigned 16-bit, little endian
.It s16be
signed 16-bit, big endian
.It u16be
unsigned 16-bit, big endian
.It s24le
signed 24-bit, stored in 4 bytes, little endian
.It u24le
unsigned 24-bit, stored in 4 bytes, little endian
.It s24be
signed 24-bit, stored in 4 bytes, big endian
.It u24be
unsigned 24-bit, stored in 4 bytes, big endian
.It s32le
signed 32-bit, little endian
.It u32le
unsigned 32-bit, little endian
.It s32be
signed 32-bit, big endian
.It u32be
unsigned 32-bit, big endian
.It s24le3
signed 24-bit, packed in 3 bytes, little endian
.It u24le3
unsigned 24-bit, packed in 3 bytes, big endian
.It s24be3
signed 24-bit, packed in 3 bytes, little endian
.It u24be3
unsigned 24-bit, packed in 3 bytes, big endian
.It s20le3
signed 20-bit, packed in 3 bytes, little endian
.It u20le3
unsigned 20-bit, packed in 3 bytes, big endian
.It s20be3
signed 20-bit, packed in 3 bytes, little endian
.It u20be3
unsigned 20-bit, packed in 3 bytes, big endian
.It s18le3
signed 18-bit, packed in 3 bytes, little endian
.It u18le3
unsigned 18-bit, packed in 3 bytes, big endian
.It s18be3
signed 18-bit, packed in 3 bytes, little endian
.It u18be3
unsigned 18-bit, packed in 3 bytes, big endian
.El
.Sh SERVER MODE
.Nm
can be used in server mode
.Pq Fl l
to overcome hardware limitations and allow applications
to run on fixed sample rate devices or on devices
supporting only unusual encodings.
It is generally not desirable to have multiple
instances of
.Nm
running in server mode,
so it is good practice to start it thus:
.Bd -literal -offset indent
$ pgrep -x aucat || aucat -l
.Ed
.Pp
This also ensures privacy by preventing
other users from accessing the audio system.
On multi-user machines
.Nm
should be killed when no longer in use to make audio resources
available again to others:
.Bd -literal -offset indent
$ pkill -x aucat
.Ed
.Pp
Certain applications, such as synthesis software,
require a low latency audio setup.
To reduce the probability of buffer underruns or overruns,
the
.Xr renice 8
command can be used to give a higher priority to the
.Nm
process.
Superuser privileges are required.
For example:
.Bd -literal -offset indent
$ aucat -b 3500 -l
$ sudo renice -n -20 -p `pgrep -x aucat`
.Ed
.Sh MIDI CONTROL
While running in server mode
.Pq Fl l
.Nm
exposes a MIDI device with the same name as the default audio
device.
It allows MIDI hardware or software to control programs
using
.Nm
or to synchronize to them.
.Pp
A MIDI channel is assigned to each stream, and the volume
is changed using the standard volume controller (number 7).
Similarly, when the audio application changes its volume,
the same MIDI controller message is sent out; it can be used
for instance for monitoring or as feedback for motorized
faders.
.Pp
Clients connected to sub-devices created with
.Fl t
are controlled by the following MMC (MIDI Machine Control) messages:
.Bl -tag -width relocateXXX -offset indent
.It stop
Put the sub-device in stopped mode (the default).
In this mode, any stream attempting to start playback or recording
is paused.
Streams that are already started are not affected until they stop
and try to start again.
.It relocate
Gives
.Nm
the time, relative to the beginning of the stream, at which playback
and recording must start.
It is not interpreted by
.Nm
itself.
The given time position is sent to MIDI clients as an MTC
.Dq "full frame"
message forcing all MTC-slaves to relocate to the given
position (see below).
.It start
Put the sub-device in starting mode.
In this mode, the sub-device waits for all streams to become ready
to start, and then starts them synchronously.
Once started, new streams can be created, but they will be blocked
until the next stop-to-start transition.
.El
.Pp
Sub-devices created with
.Fl t
will export the server clock using MTC (MIDI Time Code), allowing non-audio
software or hardware to be synchronized to the audio stream.
The following sample rates
.Pq Fl r
and block sizes
.Pq Fl z
are recommended for maximum accuracy:
.Pp
.Bl -bullet -offset indent -compact
.It
44100Hz, 441 frames
.It
48000Hz, 400 frames
.It
48000Hz, 480 frames
.It
48000Hz, 500 frames
.El
.Pp
For instance, the following command will create two devices:
the default
.Va aucat:0
and a MIDI-controlled
.Va aucat:0.mmc :
.Bd -literal -offset indent
$ aucat -l -r 48000 -z 400 -s default -t slave -s mmc
.Ed
.Pp
Streams connected to
.Va aucat:0
behave normally, while streams connected to
.Va aucat:0.mmc
wait for the MMC start signal and start synchronously.
Regardless of which device a stream is connected to,
its playback volume knob is exposed.
.Pp
If
.Nm
is used to play and record audio files, it offers
similar MIDI control.
.Nm
can open a
.Xr sndio 7
MIDI device allowing MIDI hardware or software
to control playback and recording in real time.
.Pp
A MIDI channel is assigned to each stream, and the volume
is changed using the standard volume controller (number 7).
Streams created with
.Fl t
option are controlled by the following MIDI Machine Control (MMC) messages:
.Bl -tag -width relocateXXX -offset indent
.It start
Start all streams synchronously.
By default, streams are created in a stopped state.
.It stop
Playback or recording is stopped, and
the stream is rewound back to the starting position.
.It relocate
Streams are relocated to the requested time postion
relative to the beginning of the stream, at which playback
and recording must start.
If the requested position is beyond the end of file,
the stream is temporarly disabled until a valid postion is requested.
.El
.Pp
For instance, the following command will play a file on the
.Va aucat:0.mmc
audio device, and give full control to MIDI software or hardware
connected to the
.Va midithru:0
MIDI device:
.Bd -literal -offset indent
$ aucat -f aucat:0.mmc -t slave -q midithru:0 -i file.wav
.Ed
.Pp
At this stage,
.Nm
will start, stop and relocate automatically following all user
actions in the MIDI sequencer.
Note that the sequencer must use
.Va aucat:0
as the MTC source, i.e. the audio server, not the audio player.
.Sh LEGACY MODE
If neither
.Fl i
nor
.Fl o
are specified,
.Nm
will run in legacy mode, and won't convert sample formats or sampling rates.
In legacy mode, all options except
.Fl f
are ignored, and all other arguments are assumed to be names of files.
In legacy mode
.Nm
reads files sequentially, and writes them to the specified device.
If a Sun .au header is detected it is skipped over and not copied to
the audio device.
.Nm
will attempt to parse the format, number of channels and sample rate
from Sun .au file headers.
However, only alaw and ulaw formats are supported for .au files.
Other formats will be interpreted as ulaw.
If a Microsoft .wav header (RIFF) is detected it is interpreted
to select the right audio encoding for playback and the data chunk of the
file is copied to the audio device.
If the device does not support the encoding,
.Nm
will exit with an error.
.Sh ENVIRONMENT
.Bl -tag -width "AUDIODEVICE" -compact
.It Ev AUDIODEVICE
.Xr sndio 7
audio device to use if the
.Fl f
option is not specified.
.El
.Sh EXAMPLES
The following will mix and play two stereo streams,
the first at 48kHz and the second at 44.1kHz:
.Bd -literal -offset indent
$ aucat -r 48000 -i file1.raw -r 44100 -i file2.raw
.Ed
.Pp
The following will record channels 2 and 3 into one stereo file and
channels 6 and 7 into another stereo file using a 96kHz sampling rate for
both:
.Bd -literal -offset indent
$ aucat -r 96000 -C 2:3 -o file1.raw -C 6:7 -o file2.raw
.Ed
.Pp
The following will split a stereo file into two mono files:
.Bd -literal -offset indent
$ aucat -n -i stereo.wav -C 0:0 -o left.wav -C 1:1 -o right.wav
.Ed
.Pp
The following will start
.Nm
in server mode using default parameters, but will create an
additional sub-device for output to channels 2:3 only (rear speakers
on most cards), exposing the
.Pa aucat:0
and
.Pa aucat:0.rear
devices:
.Bd -literal -offset indent
$ aucat -l -s default -c 2:3 -s rear
.Ed
.Pp
The following will start
.Nm
in server mode creating the default sub-device with low volume and
an additional sub-device for high volume output, exposing the
.Pa aucat:0
and
.Pa aucat:0.max
devices:
.Bd -literal -offset indent
$ aucat -l -v 65 -s default -v 127 -s max
.Ed
.Sh SEE ALSO
.Xr audioctl 1 ,
.Xr cdio 1 ,
.Xr mixerctl 1 ,
.Xr audio 4 ,
.Xr sndio 7
.Sh BUGS
The
.Nm
utility assumes non-blocking I/O for input and output streams.
It will not work reliably on files that may block
(ordinary files block, pipes don't).
.Pp
Resampling is low quality; down-sampling especially should be avoided
when recording.
.Pp
Processing is done using 16-bit arithmetic,
thus samples with more than 16 bits are rounded.
16 bits (i.e. 97dB dynamic) are largely enough for most applications though.