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

Annotation of src/usr.bin/sndiod/sndiod.8, Revision 1.8

1.8     ! ratchov     1: .\"    $OpenBSD: sndiod.8,v 1.7 2020/04/25 05:35:52 ratchov Exp $
1.1       ratchov     2: .\"
                      3: .\" Copyright (c) 2006-2012 Alexandre Ratchov <alex@caoua.org>
                      4: .\"
                      5: .\" Permission to use, copy, modify, and distribute this software for any
                      6: .\" purpose with or without fee is hereby granted, provided that the above
                      7: .\" copyright notice and this permission notice appear in all copies.
                      8: .\"
                      9: .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10: .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11: .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12: .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13: .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14: .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15: .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     16: .\"
1.8     ! ratchov    17: .Dd $Mdocdate: April 25 2020 $
1.1       ratchov    18: .Dt SNDIOD 8
                     19: .Os
                     20: .Sh NAME
                     21: .Nm sndiod
                     22: .Nd audio/MIDI server
                     23: .Sh SYNOPSIS
                     24: .Nm sndiod
                     25: .Bk -words
                     26: .Op Fl d
                     27: .Op Fl a Ar flag
                     28: .Op Fl b Ar nframes
                     29: .Op Fl C Ar min : Ns Ar max
                     30: .Op Fl c Ar min : Ns Ar max
                     31: .Op Fl e Ar enc
1.3       ratchov    32: .Op Fl F Ar device
1.1       ratchov    33: .Op Fl f Ar device
                     34: .Op Fl j Ar flag
                     35: .Op Fl L Ar addr
                     36: .Op Fl m Ar mode
1.3       ratchov    37: .Op Fl Q Ar port
1.1       ratchov    38: .Op Fl q Ar port
                     39: .Op Fl r Ar rate
                     40: .Op Fl s Ar name
                     41: .Op Fl t Ar mode
                     42: .Op Fl U Ar unit
                     43: .Op Fl v Ar volume
                     44: .Op Fl w Ar flag
                     45: .Op Fl z Ar nframes
                     46: .Ek
                     47: .Sh DESCRIPTION
                     48: The
                     49: .Nm
                     50: daemon is an intermediate layer between
                     51: audio or MIDI programs and the hardware.
                     52: It performs the necessary audio processing to
                     53: allow any program to work on any supported hardware.
                     54: By default,
                     55: .Nm
                     56: accepts connections from programs
                     57: running on the same system only;
                     58: it initializes only when programs are using its services,
                     59: allowing
                     60: .Nm
                     61: to consume a negligible amount of system resources the rest of the time.
                     62: Systems with no audio hardware can use
                     63: .Nm
                     64: to keep hot-pluggable devices usable by default at
                     65: virtually no cost.
                     66: .Pp
                     67: .Nm
                     68: operates as follows: it exposes at least one
                     69: .Em sub-device
                     70: that any number of audio programs can connect to and use as if it was
                     71: audio hardware.
                     72: During playback,
                     73: .Nm
                     74: receives audio data concurrently from all programs, mixes it and sends
                     75: the result to the hardware device.
                     76: Similarly, during recording it duplicates audio data recorded
                     77: from the device and sends it to all programs.
                     78: Since audio data flows through the
                     79: .Nm
                     80: process, it has the opportunity to process audio data on the fly:
                     81: .Pp
                     82: .Bl -bullet -offset indent -compact
                     83: .It
                     84: Change the sound encoding to overcome incompatibilities between
                     85: software and hardware.
                     86: .It
                     87: Route the sound from one channel to another,
                     88: join stereo or split mono.
                     89: .It
                     90: Control the per-application playback volume as well as the
                     91: master volume.
                     92: .It
                     93: Monitor the sound being played, allowing one program to record
                     94: what other programs play.
                     95: .El
                     96: .Pp
                     97: Processing is configured on a per sub-device basis, meaning that
                     98: the sound of all programs connected to the same sub-device will be
                     99: processed according to the same configuration.
                    100: Multiple sub-devices can be defined, allowing multiple configurations
                    101: to coexist.
                    102: The user selects the configuration a given program will use
                    103: by selecting the sub-device the program uses.
                    104: .Pp
                    105: .Nm
                    106: exposes MIDI thru boxes (hubs),
                    107: allowing programs to send MIDI messages to each other
                    108: or to hardware MIDI ports in a uniform way.
                    109: .Pp
                    110: Finally,
                    111: .Nm
                    112: exposes a control MIDI port usable for:
                    113: .Pp
                    114: .Bl -bullet -offset indent -compact
                    115: .It
                    116: Volume control.
                    117: .It
                    118: Common clock source for audio and MIDI programs.
                    119: .It
                    120: Start, stop and relocate groups of audio programs.
                    121: .El
                    122: .Pp
                    123: The options are as follows:
                    124: .Bl -tag -width Ds
                    125: .It Fl a Ar flag
                    126: Control whether
                    127: .Nm
                    128: opens the audio device or the MIDI port only when needed or keeps
                    129: it open all the time.
                    130: If the flag is
                    131: .Va on
                    132: then the audio device or MIDI port is kept open all the time, ensuring
                    133: no other program can steal it.
                    134: If the flag is
                    135: .Va off ,
                    136: then it's automatically closed, allowing other programs to have direct
                    137: access to the audio device, or the device to be disconnected.
                    138: The default is
                    139: .Va off .
                    140: .It Fl b Ar nframes
                    141: The buffer size of the audio device in frames.
                    142: A frame consists of one sample for each channel in the stream.
                    143: This is the number of frames that will be buffered before being played
                    144: and thus controls the playback latency.
                    145: The default is 7680 or twice the block size
                    146: .Pq Fl z ,
                    147: if the block size is set.
                    148: .It Xo
                    149: .Fl C Ar min : Ns Ar max ,
                    150: .Fl c Ar min : Ns Ar max
                    151: .Xc
                    152: The range of channel numbers for recording and playback directions,
                    153: respectively any client is allowed to use.
                    154: This is a subset of the audio device channels.
                    155: The default is 0:1, i.e. stereo.
                    156: .It Fl d
1.2       ratchov   157: Enable debugging to standard error, and do not disassociate from the
                    158: controlling terminal.
                    159: Can be specified multiple times to further increase log verbosity.
1.1       ratchov   160: .It Fl e Ar enc
                    161: Attempt to configure the device to use this encoding.
                    162: The default is
                    163: .Va s16 .
                    164: Encoding names use the following scheme: signedness
                    165: .Po
                    166: .Va s
                    167: or
                    168: .Va u
                    169: .Pc
                    170: followed
                    171: by the precision in bits, the byte-order
                    172: .Po
                    173: .Va le
                    174: or
                    175: .Va be
                    176: .Pc ,
                    177: the number of
                    178: bytes per sample, and the alignment
                    179: .Po
                    180: .Va msb
                    181: or
                    182: .Va lsb
                    183: .Pc .
                    184: Only the signedness and the precision are mandatory.
                    185: Examples:
                    186: .Va u8 , s16le , s24le3 , s24le4lsb .
1.3       ratchov   187: .It Fl F Ar device
                    188: Specify an alternate device to use.
1.4       ratchov   189: If it doesn't work, the one given with the last
1.3       ratchov   190: .Fl f
                    191: or
                    192: .Fl F
                    193: options will be used.
                    194: For instance, specifying a USB device following a
                    195: PCI device allows
                    196: .Nm
                    197: to use the USB one preferably when it's connected
                    198: and to fall back to the PCI one when it's disconnected.
1.8     ! ratchov   199: Alternate devices may be switched with the
        !           200: .Va server.device
        !           201: control of the
        !           202: .Xr sndioctl 1
        !           203: utility.
1.1       ratchov   204: .It Fl f Ar device
                    205: Add this
                    206: .Xr sndio 7
                    207: audio device to devices used for playing and/or recording.
                    208: Preceding per-device options
                    209: .Pq Fl aberwz
                    210: apply to this device.
                    211: Sub-devices
                    212: .Pq Fl s
                    213: that are applied after will be attached to this device.
                    214: Device mode and parameters are determined from sub-devices
                    215: attached to it.
1.7       ratchov   216: If no
                    217: .Fl f
                    218: option is used,
                    219: .Nm
                    220: will use
                    221: .Pa rsnd/0 , rsnd/1 ,
                    222: .No ... ,
                    223: .Pa rsnd/3 .
1.1       ratchov   224: .It Fl j Ar flag
                    225: Control whether program channels are joined or expanded if
                    226: the number of channels requested by a program is not equal
                    227: to the device number of channels.
                    228: If the flag is
                    229: .Va off
                    230: then client channels are routed to the corresponding
                    231: device channel, possibly discarding channels not present in the device.
                    232: If the flag is
                    233: .Va on ,
                    234: then a single client channel may be sent on multiple device channels,
                    235: or multiple client channels may be sent to a single device channel.
                    236: For instance, this feature could be used for mono to stereo conversions.
                    237: The default is
                    238: .Ar on .
                    239: .It Fl L Ar addr
                    240: Specify a local network address
                    241: .Nm
                    242: should listen on;
                    243: .Nm
                    244: will listen on TCP port 11025+n, where n is the unit number
                    245: specified with
                    246: .Fl U .
                    247: Without this option,
                    248: .Nm
                    249: listens on the
                    250: .Ux Ns -domain
                    251: socket only, and is not reachable from any network.
                    252: If the option argument is
                    253: .Sq -
                    254: then
                    255: .Nm
                    256: will accept connections from any address.
                    257: As the communication is not secure, this
                    258: option is only suitable for local networks where all hosts
                    259: and users are trusted.
                    260: .It Fl m Ar mode
                    261: Set the sub-device mode.
                    262: Valid modes are
                    263: .Ar play ,
                    264: .Ar rec ,
                    265: and
                    266: .Ar mon ,
                    267: corresponding to playback, recording and monitoring.
                    268: A monitoring stream is a fake recording stream corresponding to
                    269: the mix of all playback streams.
                    270: Multiple modes can be specified, separated by commas,
                    271: but the same sub-device cannot be used for both recording and monitoring.
                    272: The default is
                    273: .Ar play , Ns Ar rec
                    274: (i.e. full-duplex).
1.3       ratchov   275: .It Fl Q Ar port
                    276: Specify an alternate MIDI port to use.
1.4       ratchov   277: If it doesn't work, the one given with the last
1.3       ratchov   278: .Fl Q
                    279: or
                    280: .Fl q
                    281: options will be used.
1.5       jmc       282: For instance, this allows a USB MIDI controller to be replaced without
1.3       ratchov   283: the need to restart programs using it.
1.1       ratchov   284: .It Fl q Ar port
                    285: Expose the given MIDI port.
                    286: This allows multiple programs to share the port.
1.6       ratchov   287: If no
                    288: .Fl q
                    289: option is used,
                    290: .Nm
                    291: will use
                    292: .Pa rmidi/0 , rmidi/1 ,
                    293: .No ... ,
                    294: .Pa rmidi/7 .
1.1       ratchov   295: .It Fl r Ar rate
                    296: Attempt to force the device to use this sample rate in Hertz.
                    297: The default is 48000.
                    298: .It Fl s Ar name
                    299: Add
                    300: .Ar name
                    301: to the list of sub-devices to expose.
                    302: This allows clients to use
                    303: .Nm
                    304: instead of the physical audio device for audio input and output
                    305: in order to share the physical device with other clients.
                    306: Defining multiple sub-devices allows splitting a physical audio device
                    307: into sub-devices having different properties (e.g. channel ranges).
                    308: The given
                    309: .Ar name
                    310: corresponds to the
                    311: .Dq option
                    312: part of the
                    313: .Xr sndio 7
                    314: device name string.
                    315: .It Fl t Ar mode
                    316: Select the way clients are controlled by MIDI Machine Control (MMC)
                    317: messages received by
                    318: .Nm .
                    319: If the mode is
                    320: .Va off
                    321: (the default), then programs are not affected by MMC messages.
                    322: If the mode is
                    323: .Va slave ,
                    324: then programs are started synchronously by MMC start messages;
                    325: additionally, the server clock is exposed as MIDI Time Code (MTC)
                    326: messages allowing MTC-capable software or hardware to be synchronized
                    327: to audio programs.
                    328: .It Fl U Ar unit
                    329: Unit number.
                    330: Each
                    331: .Nm
                    332: server instance has an unique unit number,
                    333: used in
                    334: .Xr sndio 7
                    335: device names.
                    336: The default is 0.
                    337: .It Fl v Ar volume
                    338: Software volume attenuation of playback.
                    339: The value must be between 1 and 127,
                    340: corresponding to \-42dB and \-0dB attenuation in 1/3dB steps.
                    341: Clients inherit this parameter.
                    342: Reducing the volume in advance allows a client's volume to stay independent
                    343: from the number of clients as long as their number is small enough.
                    344: 18 volume units (i.e. \-6dB attenuation) allows the number
                    345: of playback programs to be doubled.
                    346: The default is 118 i.e. \-3dB.
                    347: .It Fl w Ar flag
                    348: Control
                    349: .Nm
                    350: behaviour when the maximum volume of the hardware is reached
                    351: and a new program starts playing.
                    352: This happens only when volumes are not properly set using the
                    353: .Fl v
                    354: option.
                    355: If the flag is
                    356: .Va on ,
                    357: then the master volume is automatically adjusted to avoid clipping.
                    358: Using
                    359: .Va off
                    360: makes sense in the rare situation where all programs lower their volumes.
                    361: The default is
                    362: .Va on .
                    363: .It Fl z Ar nframes
                    364: The audio device block size in frames.
                    365: This is the number of frames between audio clock ticks,
                    366: i.e. the clock resolution.
                    367: If a sub-device is created with the
                    368: .Fl t
                    369: option, and MTC is used for synchronization, the clock
                    370: resolution must be 96, 100 or 120 ticks per second for maximum
                    371: accuracy.
                    372: For instance, 100 ticks per second at 48000Hz corresponds
                    373: to a 480 frame block size.
                    374: The default is 960 or half of the buffer size
                    375: .Pq Fl b ,
                    376: if the buffer size is set.
                    377: .El
                    378: .Pp
                    379: On the command line,
                    380: per-device parameters
                    381: .Pq Fl aberwz
                    382: must precede the device definition
                    383: .Pq Fl f ,
                    384: and per-sub-device parameters
                    385: .Pq Fl Ccjmtvx
                    386: must precede the sub-device definition
                    387: .Pq Fl s .
                    388: Sub-device definitions
                    389: .Pq Fl s
                    390: must follow the definition of the device
                    391: .Pq Fl f
                    392: to which they are attached.
                    393: .Pp
                    394: If no audio devices
                    395: .Pq Fl f
                    396: are specified,
                    397: settings are applied as if
                    398: the default device is specified.
                    399: If no sub-devices
                    400: .Pq Fl s
                    401: are specified for a device, a default sub-device is
                    402: created attached to it.
                    403: If a device
                    404: .Pq Fl f
                    405: is defined twice, both definitions are merged:
                    406: parameters of the first one are used but sub-devices
                    407: .Pq Fl s
                    408: of both definitions are created.
                    409: The default
                    410: .Xr sndio 7
                    411: device used by
                    412: .Nm
                    413: is
                    414: .Pa rsnd/0 ,
                    415: and the default sub-device exposed by
                    416: .Nm
                    417: is
                    418: .Pa snd/0 .
                    419: .Pp
                    420: If
                    421: .Nm
                    422: is sent
                    423: .Dv SIGINT
                    424: or
                    425: .Dv SIGTERM ,
                    426: it terminates.
1.3       ratchov   427: If
                    428: .Nm
                    429: is sent
                    430: .Dv SIGHUP ,
                    431: it reopens all audio devices and MIDI ports.
1.1       ratchov   432: .Pp
                    433: By default, when the program cannot accept
                    434: recorded data fast enough or cannot provide data to play fast enough,
                    435: the program is paused, i.e. samples that cannot be written are discarded
                    436: and samples that cannot be read are replaced by silence.
                    437: If a sub-device is created with the
                    438: .Fl t
                    439: option, then recorded samples are discarded,
                    440: but the same amount of silence will be written
                    441: once the program is unblocked, in order to reach the right position in time.
                    442: Similarly silence is played, but the same amount of samples will be discarded
                    443: once the program is unblocked.
                    444: This ensures proper synchronization between programs.
                    445: .Sh MIDI CONTROL
                    446: .Nm
                    447: creates a MIDI port with the same name as the exposed audio
                    448: sub-device to which MIDI programs can connect.
                    449: .Nm
                    450: exposes the audio device clock
                    451: and allows audio device properties to be controlled
                    452: through MIDI.
                    453: .Pp
                    454: A MIDI channel is assigned to each stream, and the volume
                    455: is changed using the standard volume controller (number 7).
                    456: Similarly, when the audio client changes its volume,
                    457: the same MIDI controller message is sent out; it can be used
                    458: for instance for monitoring or as feedback for motorized
                    459: faders.
                    460: .Pp
                    461: The master volume can be changed using the standard master volume
                    462: system exclusive message.
                    463: .Pp
                    464: Streams created with the
                    465: .Fl t
                    466: option are controlled by the following MMC messages:
                    467: .Bl -tag -width relocateXXX -offset indent
                    468: .It relocate
                    469: This message is ignored by audio
                    470: .Nm
                    471: clients, but the given time position is sent to MIDI ports as an MTC
                    472: .Dq "full frame"
                    473: message forcing all MTC-slaves to relocate to the given
                    474: position (see below).
                    475: .It start
                    476: Put all streams in starting mode.
                    477: In this mode,
                    478: .Nm
                    479: waits for all streams to become ready
                    480: to start, and then starts them synchronously.
                    481: Once started, new streams can be created
                    482: .Pq Nm sndiod
                    483: but they will be blocked
                    484: until the next stop-to-start transition.
                    485: .It stop
                    486: Put all streams in stopped mode (the default).
                    487: In this mode, any stream attempting to start playback or recording
                    488: is paused.
                    489: Client streams that are already
                    490: started are not affected until they stop and try to start again.
                    491: .El
                    492: .Pp
                    493: Streams created with the
                    494: .Fl t
                    495: option export the
                    496: .Nm
                    497: device clock using MTC, allowing non-audio
                    498: software or hardware to be synchronized to the audio stream.
                    499: Maximum accuracy is achieved when the number of blocks per
                    500: second is equal to one of the standard MTC clock rates (96, 100 and 120Hz).
                    501: The following sample rates
                    502: .Pq Fl r
                    503: and block sizes
                    504: .Pq Fl z
                    505: are recommended:
                    506: .Pp
                    507: .Bl -bullet -offset indent -compact
                    508: .It
                    509: 44100Hz, 441 frames (MTC rate is 100Hz)
                    510: .It
                    511: 48000Hz, 400 frames (MTC rate is 120Hz)
                    512: .It
                    513: 48000Hz, 480 frames (MTC rate is 100Hz)
                    514: .It
                    515: 48000Hz, 500 frames (MTC rate is 96Hz)
                    516: .El
                    517: .Pp
                    518: For instance, the following command will create two devices:
                    519: the default
                    520: .Va snd/0
                    521: and a MIDI-controlled
                    522: .Va snd/0.mmc :
                    523: .Bd -literal -offset indent
                    524: $ sndiod -r 48000 -z 400 -s default -t slave -s mmc
                    525: .Ed
                    526: .Pp
                    527: Streams connected to
                    528: .Va snd/0
                    529: behave normally, while streams connected to
                    530: .Va snd/0.mmc
                    531: wait for the MMC start signal and start synchronously.
                    532: Regardless of which device a stream is connected to,
                    533: its playback volume knob is exposed.
                    534: .Sh EXAMPLES
                    535: Start server using default parameters, creating an
                    536: additional sub-device for output to channels 2:3 only (rear speakers
                    537: on most cards), exposing the
                    538: .Pa snd/0
                    539: and
                    540: .Pa snd/0.rear
                    541: devices:
                    542: .Bd -literal -offset indent
                    543: $ sndiod -s default -c 2:3 -s rear
                    544: .Ed
                    545: .Pp
                    546: Start server creating the default sub-device with low volume and
                    547: an additional sub-device for high volume output, exposing the
                    548: .Pa snd/0
                    549: and
                    550: .Pa snd/0.max
                    551: devices:
                    552: .Bd -literal -offset indent
                    553: $ sndiod -v 65 -s default -v 127 -s max
                    554: .Ed
                    555: .Pp
                    556: Start server configuring the audio device to use
                    557: a 48kHz sample frequency, 240-frame block size,
                    558: and 2-block buffers.
                    559: The corresponding latency is 10ms, which is
                    560: the time it takes the sound to propagate 3.5 meters.
                    561: .Bd -literal -offset indent
                    562: $ sndiod -r 48000 -b 480 -z 240
                    563: .Ed
                    564: .Sh SEE ALSO
                    565: .Xr sndio 7
                    566: .Sh BUGS
                    567: Resampling is low quality; down-sampling especially should be avoided
                    568: when recording.
                    569: .Pp
                    570: Processing is done using 16-bit arithmetic,
                    571: thus samples with more than 16 bits are rounded.
                    572: 16 bits (i.e. 97dB dynamic) are largely enough for most applications though.
                    573: Processing precision can be increased to 24-bit at compilation time though.
                    574: .Pp
                    575: If
                    576: .Fl a Ar off
                    577: is used,
                    578: .Nm
                    579: creates sub-devices to expose first
                    580: and then opens the audio hardware on demand.
                    581: Technically, this allows
                    582: .Nm
                    583: to attempt to use one of the sub-devices it exposes as an audio device,
                    584: creating a deadlock.
                    585: There's nothing to prevent the user
                    586: from shooting himself in the foot by creating such a deadlock.