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

1.5     ! jmc         1: .\"    $OpenBSD: sndiod.8,v 1.4 2019/09/21 05:03:34 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.4       ratchov    17: .Dd $Mdocdate: September 21 2019 $
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.1       ratchov   199: .It Fl f Ar device
                    200: Add this
                    201: .Xr sndio 7
                    202: audio device to devices used for playing and/or recording.
                    203: Preceding per-device options
                    204: .Pq Fl aberwz
                    205: apply to this device.
                    206: Sub-devices
                    207: .Pq Fl s
                    208: that are applied after will be attached to this device.
                    209: Device mode and parameters are determined from sub-devices
                    210: attached to it.
                    211: .It Fl j Ar flag
                    212: Control whether program channels are joined or expanded if
                    213: the number of channels requested by a program is not equal
                    214: to the device number of channels.
                    215: If the flag is
                    216: .Va off
                    217: then client channels are routed to the corresponding
                    218: device channel, possibly discarding channels not present in the device.
                    219: If the flag is
                    220: .Va on ,
                    221: then a single client channel may be sent on multiple device channels,
                    222: or multiple client channels may be sent to a single device channel.
                    223: For instance, this feature could be used for mono to stereo conversions.
                    224: The default is
                    225: .Ar on .
                    226: .It Fl L Ar addr
                    227: Specify a local network address
                    228: .Nm
                    229: should listen on;
                    230: .Nm
                    231: will listen on TCP port 11025+n, where n is the unit number
                    232: specified with
                    233: .Fl U .
                    234: Without this option,
                    235: .Nm
                    236: listens on the
                    237: .Ux Ns -domain
                    238: socket only, and is not reachable from any network.
                    239: If the option argument is
                    240: .Sq -
                    241: then
                    242: .Nm
                    243: will accept connections from any address.
                    244: As the communication is not secure, this
                    245: option is only suitable for local networks where all hosts
                    246: and users are trusted.
                    247: .It Fl m Ar mode
                    248: Set the sub-device mode.
                    249: Valid modes are
                    250: .Ar play ,
                    251: .Ar rec ,
                    252: and
                    253: .Ar mon ,
                    254: corresponding to playback, recording and monitoring.
                    255: A monitoring stream is a fake recording stream corresponding to
                    256: the mix of all playback streams.
                    257: Multiple modes can be specified, separated by commas,
                    258: but the same sub-device cannot be used for both recording and monitoring.
                    259: The default is
                    260: .Ar play , Ns Ar rec
                    261: (i.e. full-duplex).
1.3       ratchov   262: .It Fl Q Ar port
                    263: Specify an alternate MIDI port to use.
1.4       ratchov   264: If it doesn't work, the one given with the last
1.3       ratchov   265: .Fl Q
                    266: or
                    267: .Fl q
                    268: options will be used.
1.5     ! jmc       269: For instance, this allows a USB MIDI controller to be replaced without
1.3       ratchov   270: the need to restart programs using it.
1.1       ratchov   271: .It Fl q Ar port
                    272: Expose the given MIDI port.
                    273: This allows multiple programs to share the port.
                    274: .It Fl r Ar rate
                    275: Attempt to force the device to use this sample rate in Hertz.
                    276: The default is 48000.
                    277: .It Fl s Ar name
                    278: Add
                    279: .Ar name
                    280: to the list of sub-devices to expose.
                    281: This allows clients to use
                    282: .Nm
                    283: instead of the physical audio device for audio input and output
                    284: in order to share the physical device with other clients.
                    285: Defining multiple sub-devices allows splitting a physical audio device
                    286: into sub-devices having different properties (e.g. channel ranges).
                    287: The given
                    288: .Ar name
                    289: corresponds to the
                    290: .Dq option
                    291: part of the
                    292: .Xr sndio 7
                    293: device name string.
                    294: .It Fl t Ar mode
                    295: Select the way clients are controlled by MIDI Machine Control (MMC)
                    296: messages received by
                    297: .Nm .
                    298: If the mode is
                    299: .Va off
                    300: (the default), then programs are not affected by MMC messages.
                    301: If the mode is
                    302: .Va slave ,
                    303: then programs are started synchronously by MMC start messages;
                    304: additionally, the server clock is exposed as MIDI Time Code (MTC)
                    305: messages allowing MTC-capable software or hardware to be synchronized
                    306: to audio programs.
                    307: .It Fl U Ar unit
                    308: Unit number.
                    309: Each
                    310: .Nm
                    311: server instance has an unique unit number,
                    312: used in
                    313: .Xr sndio 7
                    314: device names.
                    315: The default is 0.
                    316: .It Fl v Ar volume
                    317: Software volume attenuation of playback.
                    318: The value must be between 1 and 127,
                    319: corresponding to \-42dB and \-0dB attenuation in 1/3dB steps.
                    320: Clients inherit this parameter.
                    321: Reducing the volume in advance allows a client's volume to stay independent
                    322: from the number of clients as long as their number is small enough.
                    323: 18 volume units (i.e. \-6dB attenuation) allows the number
                    324: of playback programs to be doubled.
                    325: The default is 118 i.e. \-3dB.
                    326: .It Fl w Ar flag
                    327: Control
                    328: .Nm
                    329: behaviour when the maximum volume of the hardware is reached
                    330: and a new program starts playing.
                    331: This happens only when volumes are not properly set using the
                    332: .Fl v
                    333: option.
                    334: If the flag is
                    335: .Va on ,
                    336: then the master volume is automatically adjusted to avoid clipping.
                    337: Using
                    338: .Va off
                    339: makes sense in the rare situation where all programs lower their volumes.
                    340: The default is
                    341: .Va on .
                    342: .It Fl z Ar nframes
                    343: The audio device block size in frames.
                    344: This is the number of frames between audio clock ticks,
                    345: i.e. the clock resolution.
                    346: If a sub-device is created with the
                    347: .Fl t
                    348: option, and MTC is used for synchronization, the clock
                    349: resolution must be 96, 100 or 120 ticks per second for maximum
                    350: accuracy.
                    351: For instance, 100 ticks per second at 48000Hz corresponds
                    352: to a 480 frame block size.
                    353: The default is 960 or half of the buffer size
                    354: .Pq Fl b ,
                    355: if the buffer size is set.
                    356: .El
                    357: .Pp
                    358: On the command line,
                    359: per-device parameters
                    360: .Pq Fl aberwz
                    361: must precede the device definition
                    362: .Pq Fl f ,
                    363: and per-sub-device parameters
                    364: .Pq Fl Ccjmtvx
                    365: must precede the sub-device definition
                    366: .Pq Fl s .
                    367: Sub-device definitions
                    368: .Pq Fl s
                    369: must follow the definition of the device
                    370: .Pq Fl f
                    371: to which they are attached.
                    372: .Pp
                    373: If no audio devices
                    374: .Pq Fl f
                    375: are specified,
                    376: settings are applied as if
                    377: the default device is specified.
                    378: If no sub-devices
                    379: .Pq Fl s
                    380: are specified for a device, a default sub-device is
                    381: created attached to it.
                    382: If a device
                    383: .Pq Fl f
                    384: is defined twice, both definitions are merged:
                    385: parameters of the first one are used but sub-devices
                    386: .Pq Fl s
                    387: of both definitions are created.
                    388: The default
                    389: .Xr sndio 7
                    390: device used by
                    391: .Nm
                    392: is
                    393: .Pa rsnd/0 ,
                    394: and the default sub-device exposed by
                    395: .Nm
                    396: is
                    397: .Pa snd/0 .
                    398: .Pp
                    399: If
                    400: .Nm
                    401: is sent
                    402: .Dv SIGINT
                    403: or
                    404: .Dv SIGTERM ,
                    405: it terminates.
1.3       ratchov   406: If
                    407: .Nm
                    408: is sent
                    409: .Dv SIGHUP ,
                    410: it reopens all audio devices and MIDI ports.
1.1       ratchov   411: .Pp
                    412: By default, when the program cannot accept
                    413: recorded data fast enough or cannot provide data to play fast enough,
                    414: the program is paused, i.e. samples that cannot be written are discarded
                    415: and samples that cannot be read are replaced by silence.
                    416: If a sub-device is created with the
                    417: .Fl t
                    418: option, then recorded samples are discarded,
                    419: but the same amount of silence will be written
                    420: once the program is unblocked, in order to reach the right position in time.
                    421: Similarly silence is played, but the same amount of samples will be discarded
                    422: once the program is unblocked.
                    423: This ensures proper synchronization between programs.
                    424: .Sh MIDI CONTROL
                    425: .Nm
                    426: creates a MIDI port with the same name as the exposed audio
                    427: sub-device to which MIDI programs can connect.
                    428: .Nm
                    429: exposes the audio device clock
                    430: and allows audio device properties to be controlled
                    431: through MIDI.
                    432: .Pp
                    433: A MIDI channel is assigned to each stream, and the volume
                    434: is changed using the standard volume controller (number 7).
                    435: Similarly, when the audio client changes its volume,
                    436: the same MIDI controller message is sent out; it can be used
                    437: for instance for monitoring or as feedback for motorized
                    438: faders.
                    439: .Pp
                    440: The master volume can be changed using the standard master volume
                    441: system exclusive message.
                    442: .Pp
                    443: Streams created with the
                    444: .Fl t
                    445: option are controlled by the following MMC messages:
                    446: .Bl -tag -width relocateXXX -offset indent
                    447: .It relocate
                    448: This message is ignored by audio
                    449: .Nm
                    450: clients, but the given time position is sent to MIDI ports as an MTC
                    451: .Dq "full frame"
                    452: message forcing all MTC-slaves to relocate to the given
                    453: position (see below).
                    454: .It start
                    455: Put all streams in starting mode.
                    456: In this mode,
                    457: .Nm
                    458: waits for all streams to become ready
                    459: to start, and then starts them synchronously.
                    460: Once started, new streams can be created
                    461: .Pq Nm sndiod
                    462: but they will be blocked
                    463: until the next stop-to-start transition.
                    464: .It stop
                    465: Put all streams in stopped mode (the default).
                    466: In this mode, any stream attempting to start playback or recording
                    467: is paused.
                    468: Client streams that are already
                    469: started are not affected until they stop and try to start again.
                    470: .El
                    471: .Pp
                    472: Streams created with the
                    473: .Fl t
                    474: option export the
                    475: .Nm
                    476: device clock using MTC, allowing non-audio
                    477: software or hardware to be synchronized to the audio stream.
                    478: Maximum accuracy is achieved when the number of blocks per
                    479: second is equal to one of the standard MTC clock rates (96, 100 and 120Hz).
                    480: The following sample rates
                    481: .Pq Fl r
                    482: and block sizes
                    483: .Pq Fl z
                    484: are recommended:
                    485: .Pp
                    486: .Bl -bullet -offset indent -compact
                    487: .It
                    488: 44100Hz, 441 frames (MTC rate is 100Hz)
                    489: .It
                    490: 48000Hz, 400 frames (MTC rate is 120Hz)
                    491: .It
                    492: 48000Hz, 480 frames (MTC rate is 100Hz)
                    493: .It
                    494: 48000Hz, 500 frames (MTC rate is 96Hz)
                    495: .El
                    496: .Pp
                    497: For instance, the following command will create two devices:
                    498: the default
                    499: .Va snd/0
                    500: and a MIDI-controlled
                    501: .Va snd/0.mmc :
                    502: .Bd -literal -offset indent
                    503: $ sndiod -r 48000 -z 400 -s default -t slave -s mmc
                    504: .Ed
                    505: .Pp
                    506: Streams connected to
                    507: .Va snd/0
                    508: behave normally, while streams connected to
                    509: .Va snd/0.mmc
                    510: wait for the MMC start signal and start synchronously.
                    511: Regardless of which device a stream is connected to,
                    512: its playback volume knob is exposed.
                    513: .Sh EXAMPLES
                    514: Start server using default parameters, creating an
                    515: additional sub-device for output to channels 2:3 only (rear speakers
                    516: on most cards), exposing the
                    517: .Pa snd/0
                    518: and
                    519: .Pa snd/0.rear
                    520: devices:
                    521: .Bd -literal -offset indent
                    522: $ sndiod -s default -c 2:3 -s rear
                    523: .Ed
                    524: .Pp
                    525: Start server creating the default sub-device with low volume and
                    526: an additional sub-device for high volume output, exposing the
                    527: .Pa snd/0
                    528: and
                    529: .Pa snd/0.max
                    530: devices:
                    531: .Bd -literal -offset indent
                    532: $ sndiod -v 65 -s default -v 127 -s max
                    533: .Ed
                    534: .Pp
                    535: Start server configuring the audio device to use
                    536: a 48kHz sample frequency, 240-frame block size,
                    537: and 2-block buffers.
                    538: The corresponding latency is 10ms, which is
                    539: the time it takes the sound to propagate 3.5 meters.
                    540: .Bd -literal -offset indent
                    541: $ sndiod -r 48000 -b 480 -z 240
                    542: .Ed
                    543: .Sh SEE ALSO
                    544: .Xr sndio 7
                    545: .Sh BUGS
                    546: Resampling is low quality; down-sampling especially should be avoided
                    547: when recording.
                    548: .Pp
                    549: Processing is done using 16-bit arithmetic,
                    550: thus samples with more than 16 bits are rounded.
                    551: 16 bits (i.e. 97dB dynamic) are largely enough for most applications though.
                    552: Processing precision can be increased to 24-bit at compilation time though.
                    553: .Pp
                    554: If
                    555: .Fl a Ar off
                    556: is used,
                    557: .Nm
                    558: creates sub-devices to expose first
                    559: and then opens the audio hardware on demand.
                    560: Technically, this allows
                    561: .Nm
                    562: to attempt to use one of the sub-devices it exposes as an audio device,
                    563: creating a deadlock.
                    564: There's nothing to prevent the user
                    565: from shooting himself in the foot by creating such a deadlock.