[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.12

1.12    ! jmc         1: .\"    $OpenBSD: sndiod.8,v 1.11 2021/07/16 15:05:58 sthen 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.12    ! jmc        17: .Dd $Mdocdate: July 16 2021 $
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.12    ! jmc       189: If it doesn't work, the one given with the previous
1.3       ratchov   190: .Fl f
                    191: or
                    192: .Fl F
1.12    ! jmc       193: option will be used.
1.3       ratchov   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
1.9       jmc       332: server instance has a unique unit number,
1.1       ratchov   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.
1.10      jcs       346: The default is 127.
1.1       ratchov   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: The default is
1.10      jcs       359: .Va off .
1.1       ratchov   360: .It Fl z Ar nframes
                    361: The audio device block size in frames.
                    362: This is the number of frames between audio clock ticks,
                    363: i.e. the clock resolution.
                    364: If a sub-device is created with the
                    365: .Fl t
                    366: option, and MTC is used for synchronization, the clock
                    367: resolution must be 96, 100 or 120 ticks per second for maximum
                    368: accuracy.
                    369: For instance, 100 ticks per second at 48000Hz corresponds
                    370: to a 480 frame block size.
1.11      sthen     371: The default is 480 or half of the buffer size
1.1       ratchov   372: .Pq Fl b ,
                    373: if the buffer size is set.
                    374: .El
                    375: .Pp
                    376: On the command line,
                    377: per-device parameters
                    378: .Pq Fl aberwz
                    379: must precede the device definition
                    380: .Pq Fl f ,
                    381: and per-sub-device parameters
                    382: .Pq Fl Ccjmtvx
                    383: must precede the sub-device definition
                    384: .Pq Fl s .
                    385: Sub-device definitions
                    386: .Pq Fl s
                    387: must follow the definition of the device
                    388: .Pq Fl f
                    389: to which they are attached.
                    390: .Pp
                    391: If no audio devices
                    392: .Pq Fl f
                    393: are specified,
                    394: settings are applied as if
                    395: the default device is specified.
                    396: If no sub-devices
                    397: .Pq Fl s
                    398: are specified for a device, a default sub-device is
                    399: created attached to it.
                    400: If a device
                    401: .Pq Fl f
                    402: is defined twice, both definitions are merged:
                    403: parameters of the first one are used but sub-devices
                    404: .Pq Fl s
                    405: of both definitions are created.
                    406: The default
                    407: .Xr sndio 7
                    408: device used by
                    409: .Nm
                    410: is
                    411: .Pa rsnd/0 ,
                    412: and the default sub-device exposed by
                    413: .Nm
                    414: is
                    415: .Pa snd/0 .
                    416: .Pp
                    417: If
                    418: .Nm
                    419: is sent
                    420: .Dv SIGINT
                    421: or
                    422: .Dv SIGTERM ,
                    423: it terminates.
1.3       ratchov   424: If
                    425: .Nm
                    426: is sent
                    427: .Dv SIGHUP ,
                    428: it reopens all audio devices and MIDI ports.
1.1       ratchov   429: .Pp
                    430: By default, when the program cannot accept
                    431: recorded data fast enough or cannot provide data to play fast enough,
                    432: the program is paused, i.e. samples that cannot be written are discarded
                    433: and samples that cannot be read are replaced by silence.
                    434: If a sub-device is created with the
                    435: .Fl t
                    436: option, then recorded samples are discarded,
                    437: but the same amount of silence will be written
                    438: once the program is unblocked, in order to reach the right position in time.
                    439: Similarly silence is played, but the same amount of samples will be discarded
                    440: once the program is unblocked.
                    441: This ensures proper synchronization between programs.
                    442: .Sh MIDI CONTROL
                    443: .Nm
                    444: creates a MIDI port with the same name as the exposed audio
                    445: sub-device to which MIDI programs can connect.
                    446: .Nm
                    447: exposes the audio device clock
                    448: and allows audio device properties to be controlled
                    449: through MIDI.
                    450: .Pp
                    451: A MIDI channel is assigned to each stream, and the volume
                    452: is changed using the standard volume controller (number 7).
                    453: Similarly, when the audio client changes its volume,
                    454: the same MIDI controller message is sent out; it can be used
                    455: for instance for monitoring or as feedback for motorized
                    456: faders.
                    457: .Pp
                    458: The master volume can be changed using the standard master volume
                    459: system exclusive message.
                    460: .Pp
                    461: Streams created with the
                    462: .Fl t
                    463: option are controlled by the following MMC messages:
                    464: .Bl -tag -width relocateXXX -offset indent
                    465: .It relocate
                    466: This message is ignored by audio
                    467: .Nm
                    468: clients, but the given time position is sent to MIDI ports as an MTC
                    469: .Dq "full frame"
                    470: message forcing all MTC-slaves to relocate to the given
                    471: position (see below).
                    472: .It start
                    473: Put all streams in starting mode.
                    474: In this mode,
                    475: .Nm
                    476: waits for all streams to become ready
                    477: to start, and then starts them synchronously.
                    478: Once started, new streams can be created
                    479: .Pq Nm sndiod
                    480: but they will be blocked
                    481: until the next stop-to-start transition.
                    482: .It stop
                    483: Put all streams in stopped mode (the default).
                    484: In this mode, any stream attempting to start playback or recording
                    485: is paused.
                    486: Client streams that are already
                    487: started are not affected until they stop and try to start again.
                    488: .El
                    489: .Pp
                    490: Streams created with the
                    491: .Fl t
                    492: option export the
                    493: .Nm
                    494: device clock using MTC, allowing non-audio
                    495: software or hardware to be synchronized to the audio stream.
                    496: Maximum accuracy is achieved when the number of blocks per
                    497: second is equal to one of the standard MTC clock rates (96, 100 and 120Hz).
                    498: The following sample rates
                    499: .Pq Fl r
                    500: and block sizes
                    501: .Pq Fl z
                    502: are recommended:
                    503: .Pp
                    504: .Bl -bullet -offset indent -compact
                    505: .It
                    506: 44100Hz, 441 frames (MTC rate is 100Hz)
                    507: .It
                    508: 48000Hz, 400 frames (MTC rate is 120Hz)
                    509: .It
                    510: 48000Hz, 480 frames (MTC rate is 100Hz)
                    511: .It
                    512: 48000Hz, 500 frames (MTC rate is 96Hz)
                    513: .El
                    514: .Pp
                    515: For instance, the following command will create two devices:
                    516: the default
                    517: .Va snd/0
                    518: and a MIDI-controlled
                    519: .Va snd/0.mmc :
                    520: .Bd -literal -offset indent
                    521: $ sndiod -r 48000 -z 400 -s default -t slave -s mmc
                    522: .Ed
                    523: .Pp
                    524: Streams connected to
                    525: .Va snd/0
                    526: behave normally, while streams connected to
                    527: .Va snd/0.mmc
                    528: wait for the MMC start signal and start synchronously.
                    529: Regardless of which device a stream is connected to,
                    530: its playback volume knob is exposed.
                    531: .Sh EXAMPLES
                    532: Start server using default parameters, creating an
                    533: additional sub-device for output to channels 2:3 only (rear speakers
                    534: on most cards), exposing the
                    535: .Pa snd/0
                    536: and
                    537: .Pa snd/0.rear
                    538: devices:
                    539: .Bd -literal -offset indent
                    540: $ sndiod -s default -c 2:3 -s rear
                    541: .Ed
                    542: .Pp
                    543: Start server creating the default sub-device with low volume and
                    544: an additional sub-device for high volume output, exposing the
                    545: .Pa snd/0
                    546: and
                    547: .Pa snd/0.max
                    548: devices:
                    549: .Bd -literal -offset indent
                    550: $ sndiod -v 65 -s default -v 127 -s max
                    551: .Ed
                    552: .Pp
                    553: Start server configuring the audio device to use
                    554: a 48kHz sample frequency, 240-frame block size,
                    555: and 2-block buffers.
                    556: The corresponding latency is 10ms, which is
                    557: the time it takes the sound to propagate 3.5 meters.
                    558: .Bd -literal -offset indent
                    559: $ sndiod -r 48000 -b 480 -z 240
                    560: .Ed
                    561: .Sh SEE ALSO
                    562: .Xr sndio 7
                    563: .Sh BUGS
                    564: Resampling is low quality; down-sampling especially should be avoided
                    565: when recording.
                    566: .Pp
                    567: Processing is done using 16-bit arithmetic,
                    568: thus samples with more than 16 bits are rounded.
                    569: 16 bits (i.e. 97dB dynamic) are largely enough for most applications though.
                    570: Processing precision can be increased to 24-bit at compilation time though.
                    571: .Pp
                    572: If
                    573: .Fl a Ar off
                    574: is used,
                    575: .Nm
                    576: creates sub-devices to expose first
                    577: and then opens the audio hardware on demand.
                    578: Technically, this allows
                    579: .Nm
                    580: to attempt to use one of the sub-devices it exposes as an audio device,
                    581: creating a deadlock.
                    582: There's nothing to prevent the user
                    583: from shooting himself in the foot by creating such a deadlock.