xref: /openbsd/lib/libsndio/sndio.7 (revision 09467b48)
1.\" $OpenBSD: sndio.7,v 1.24 2020/07/18 05:01:14 ratchov Exp $
2.\"
3.\" Copyright (c) 2007 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.\"
17.Dd $Mdocdate: July 18 2020 $
18.Dt SNDIO 7
19.Os
20.Sh NAME
21.Nm sndio
22.Nd interface to audio and MIDI
23.Sh DESCRIPTION
24Programs access audio and MIDI hardware using the
25.Nm sndio
26library.
27It allows both access through the
28.Xr sndiod 8
29server and raw access to the hardware.
30The audio device or MIDI port, as well as the access method,
31are designated by the sndio descriptor.
32It is provided by the user with the program device selection method,
33or with the
34.Ev AUDIODEVICE
35and
36.Ev MIDIDEVICE
37environment variables if there's no device selection method.
38.Pp
39Usually, programs access the hardware via the
40.Xr sndiod 8
41server, because raw access to the hardware is exclusive and
42requires additional privileges.
43The
44.Xr sndiod 8
45server supports multiple connections at a time, allowing multiple programs to
46use the hardware concurrently.
47It performs the necessary audio processing on the fly to
48overcome any incompatibility between software and hardware.
49Connections to
50.Xr sndiod 8
51may also be established through the network, including from virtual machines.
52.Pp
53The
54.Xr sndiod 8
55server exposes
56.Em MIDI thru
57ports, allowing one program to send MIDI data to other programs,
58for instance to allow a sequencer to send events to a synthesizer.
59.Pp
60Additionally,
61.Xr sndiod 8
62exposes a MIDI port used to control audio programs using
63standard MIDI Machine Control (MMC), MIDI Time Code (MTC),
64and master volume messages.
65.Sh AUDIO AND MIDI DESCRIPTORS
66From the user's perspective every audio device or MIDI port
67has a descriptor of the form:
68.Bd -literal -offset center
69type[@hostname][,servnum]/devnum[.option]
70.Ed
71.Pp
72This information is used by programs to determine
73how to access the audio device or MIDI port.
74.Bl -tag -width "hostname"
75.It Ar type
76The type of the audio device or MIDI port.
77Possible values are:
78.Pp
79.Bl -tag -width "midithru" -offset 3n -compact
80.It Cm rsnd
81Raw
82.Xr audio 4
83device.
84.It Cm rmidi
85Raw
86.Xr midi 4
87port.
88.It Cm snd
89Audio device exposed by
90.Xr sndiod 8 .
91.It Cm midithru
92MIDI thru port created with
93.Xr sndiod 8 .
94.It Cm midi
95MIDI port exposed by
96.Xr sndiod 8 .
97.It Cm default
98Default audio device or MIDI port (see below).
99.El
100.It Ar hostname
101The hostname or address where the remote
102.Xr sndiod 8
103server to connect to is running.
104.It Ar servnum
105The number of the
106.Xr sndiod 8
107server to connect to, corresponding to the integer specified using the
108.Fl U
109option of
110.Xr sndiod 8 .
111Useful only if multiple
112.Xr sndiod 8
113servers are running on the same system.
114.It Ar devnum
115Device number.
116For hardware audio or MIDI ports, this corresponds to
117the character device minor number.
118For audio devices or MIDI ports created with
119.Xr sndiod 8
120it corresponds to the number of the corresponding
121.Fl fq
122option on the command line.
123.It Ar option
124Corresponds to the sub-device string registered using the
125.Fl s
126option of
127.Xr sndiod 8 .
128.El
129.Pp
130For example:
131.Pp
132.Bl -tag -width "snd/0.rear" -offset 3n -compact
133.It Li rsnd/0
134Raw access to first audio device.
135.It Li rmidi/5
136Raw access to MIDI port number 5.
137.It Li snd/0
138Audio device referred by first
139.Fl f
140option of
141.Xr sndiod 8 .
142.It Li snd/0.rear
143Sub-device registered with
144.Fl s Fa rear .
145.It Li midithru/0
146First MIDI thru port created with
147.Xr sndiod 8 .
148.El
149.Sh DEFAULTS
150If
151.Cm default
152is used as the audio device, the program will use the
153one specified in the
154.Ev AUDIODEVICE
155environment variable.
156If it is not set, the program first tries to connect to
157.Li snd/0 .
158If that fails, it then tries to use
159.Li rsnd/0 .
160.Pp
161Similarly, if no MIDI descriptor is provided to a program
162or when the reserved word
163.Cm default
164is passed as the device descriptor,
165the program uses the one specified in the
166.Ev MIDIDEVICE
167environment variable.
168If it is not set, the program first tries to connect to
169.Li midithru/0 .
170If that fails, it then tries to use
171.Li rmidi/0 .
172As long as
173.Xr sndiod 8
174is running, this allows programs to exchange MIDI data on
175machines with no MIDI hardware by default, e.g. a MIDI player
176could use a software synthesizer with no manual configuration
177required.
178.Sh AUTHENTICATION
179For privacy reasons only one user may have connections to
180.Xr sndiod 8
181at a given time.
182Users are identified by their
183.Em session cookie ,
184which is automatically generated by audio or MIDI programs
185upon the first connection to the server.
186The cookie is stored in
187.Pa "$HOME/.sndio/cookie"
188and contains 128 bits of raw random data.
189.Pp
190If a session needs to be shared between multiple users, they
191can connect to the server using the same cookie.
192.Sh ENVIRONMENT
193.Bl -tag -width "AUDIODEVICEXXX" -compact
194.It Ev AUDIODEVICE
195Audio device descriptor to use
196when no descriptor is explicitly specified to a program.
197.It Ev MIDIDEVICE
198MIDI port descriptor to use
199when no descriptor is explicitly specified to a program.
200.El
201.Pp
202These environment variables are ignored by
203.Nm
204if the program has the set-user-ID or set-group-ID bits set.
205.Sh FILES
206.Bl -tag -width "~/.sndio/cookie" -compact
207.It Pa ~/.sndio/cookie
208User's session authentication cookie.
209.It Pa /dev/audioN
210Audio devices.
211.It Pa /dev/rmidiN
212MIDI ports.
213.El
214.Sh SEE ALSO
215.Xr aucat 1 ,
216.Xr midicat 1 ,
217.Xr sndioctl 1 ,
218.Xr mio_open 3 ,
219.Xr sio_open 3 ,
220.Xr sioctl_open 3 ,
221.Xr audio 4 ,
222.Xr midi 4 ,
223.Xr sndiod 8
224