xref: /freebsd/share/man/man4/pcm.4 (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
1.\"
2.\" Copyright (c) 2009-2011 Joel Dahl <joel@FreeBSD.org>
3.\" All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24.\" SUCH DAMAGE.
25.\"
26.Dd January 10, 2024
27.Dt SOUND 4
28.Os
29.Sh NAME
30.Nm sound ,
31.Nm pcm ,
32.Nm snd
33.Nd
34.Fx
35PCM audio device infrastructure
36.Sh SYNOPSIS
37To compile this driver into the kernel, place the following line in your
38kernel configuration file:
39.Bd -ragged -offset indent
40.Cd "device sound"
41.Ed
42.Sh DESCRIPTION
43The
44.Nm
45driver is the main component of the
46.Fx
47sound system.
48It works in conjunction with a bridge device driver on supported devices
49and provides PCM audio record and playback once it attaches.
50Each bridge device driver supports a specific set of audio chipsets and
51needs to be enabled together with the
52.Nm
53driver.
54PCI and ISA PnP audio devices identify themselves so users are usually not
55required to add anything to
56.Pa /boot/device.hints .
57.Pp
58Some of the main features of the
59.Nm
60driver are: multichannel audio, per-application
61volume control, dynamic mixing through virtual sound channels, true full
62duplex operation, bit perfect audio, rate conversion and low latency
63modes.
64.Pp
65The
66.Nm
67driver is enabled by default, along with several bridge device drivers.
68Those not enabled by default can be loaded during runtime with
69.Xr kldload 8
70or during boot via
71.Xr loader.conf 5 .
72The following bridge device drivers are available:
73.Pp
74.Bl -bullet -compact
75.It
76.Xr snd_ai2s 4 (enabled by default on powerpc)
77.It
78.Xr snd_als4000 4
79.It
80.Xr snd_atiixp 4
81.It
82.Xr snd_cmi 4 (enabled by default on amd64, i386)
83.It
84.Xr snd_cs4281 4
85.It
86.Xr snd_csa 4 (enabled by default on amd64, i386)
87.It
88.Xr snd_davbus 4 (enabled by default on powerpc)
89.It
90.Xr snd_emu10k1 4
91.It
92.Xr snd_emu10kx 4 (enabled by default on amd64, i386)
93.It
94.Xr snd_envy24 4
95.It
96.Xr snd_envy24ht 4
97.It
98.Xr snd_es137x 4 (enabled by default on amd64, i386)
99.It
100.Xr snd_fm801 4
101.It
102.Xr snd_hda 4 (enabled by default on amd64, i386)
103.It
104.Xr snd_hdspe 4
105.It
106.Xr snd_ich 4 (enabled by default on amd64, i386)
107.It
108.Xr snd_maestro3 4
109.It
110.Xr snd_neomagic 4
111.It
112.Xr snd_solo 4
113.It
114.Xr snd_spicds 4
115.It
116.Xr snd_uaudio 4 (auto-loaded on device plug)
117.It
118.Xr snd_via8233 4 (enabled by default on amd64, i386)
119.It
120.Xr snd_via82c686 4
121.It
122.Xr snd_vibes 4
123.El
124.Pp
125Refer to the manual page for each bridge device driver for driver specific
126settings and information.
127.Ss Boot Variables
128In general, the module
129.Pa snd_foo
130corresponds to
131.Cd "device snd_foo"
132and can be
133loaded by the boot
134.Xr loader 8
135via
136.Xr loader.conf 5
137or from the command line using the
138.Xr kldload 8
139utility.
140Options which can be specified in
141.Pa /boot/loader.conf
142include:
143.Bl -tag -width ".Va snd_driver_load" -offset indent
144.It Va snd_driver_load
145.Pq Dq Li NO
146If set to
147.Dq Li YES ,
148this option loads all available drivers.
149.It Va snd_hda_load
150.Pq Dq Li NO
151If set to
152.Dq Li YES ,
153only the Intel High Definition Audio bridge device driver and dependent
154modules will be loaded.
155.It Va snd_foo_load
156.Pq Dq Li NO
157If set to
158.Dq Li YES ,
159load driver for card/chipset foo.
160.El
161.Pp
162To define default values for the different mixer channels,
163set the channel to the preferred value using hints, e.g.:
164.Va hint.pcm.0.line Ns = Ns Qq Li 0 .
165This will mute the input channel per default.
166.Ss Multichannel Audio
167Multichannel audio, popularly referred to as
168.Dq surround sound
169is supported and enabled by default.
170The
171.Fx
172multichannel matrix processor supports up to 18 interleaved channels, but the
173limit is currently set to 8 channels (as commonly used for 7.1 surround sound).
174The internal matrix mapping can handle reduction, expansion or
175re-routing of channels.
176This provides a base interface for related multichannel
177.Fn ioctl
178support.
179Multichannel audio works both with and without VCHANs.
180.Pp
181Most bridge device drivers are still missing multichannel matrixing
182support, but in most cases this should be trivial to implement.
183Use the
184.Va dev.pcm.%d.[play|rec].vchanformat
185.Xr sysctl 8
186to adjust the number of channels used.
187The current multichannel interleaved structure and arrangement was
188implemented by inspecting various popular UNIX applications.
189There were no single standard, so much care has been taken to try
190to satisfy each possible scenario, despite the fact that each
191application has its own conflicting standard.
192.Ss EQ
193The Parametric Software Equalizer (EQ) enables the use of
194.Dq tone
195controls (bass and treble).
196Commonly used for ear-candy or frequency compensation due to the vast
197difference in hardware quality.
198EQ is disabled by default, but can be enabled with the
199.Va hint.pcm.%d.eq
200tunable.
201.Ss VCHANs
202Each device can optionally support more playback and recording channels
203than physical hardware provides by using
204.Dq virtual channels
205or VCHANs.
206VCHAN options can be configured via the
207.Xr sysctl 8
208interface but can only be manipulated while the device is inactive.
209.Ss VPC
210.Fx
211supports independent and individual volume controls for each active
212application, without touching the master
213.Nm
214volume.
215This is sometimes referred to as Volume Per Channel (VPC).
216The VPC feature is enabled by default.
217.Ss Loader Tunables
218The following loader tunables are used to set driver configuration at the
219.Xr loader 8
220prompt before booting the kernel, or they can be stored in
221.Pa /boot/loader.conf
222in order to automatically set them before booting the kernel.
223It is also possible to use
224.Xr kenv 1
225to change these tunables before loading the
226.Nm
227driver.
228The following tunables can not be changed during runtime using
229.Xr sysctl 8 .
230.Bl -tag -width indent
231.It Va hint.pcm.%d.eq
232Set to 1 or 0 to explicitly enable (1) or disable (0) the equalizer.
233Requires a driver reload if changed.
234Enabling this will make bass and treble controls appear in mixer applications.
235This tunable is undefined by default.
236Equalizing is disabled by default.
237.It Va hint.pcm.%d.vpc
238Set to 1 or 0 to explicitly enable (1) or disable (0) the VPC feature.
239This tunable is undefined by default.
240VPC is however enabled by default.
241.El
242.Ss Runtime Configuration
243There are a number of
244.Xr sysctl 8
245variables available which can be modified during runtime.
246These values can also be stored in
247.Pa /etc/sysctl.conf
248in order to automatically set them during the boot process.
249.Va hw.snd.*
250are global settings and
251.Va dev.pcm.*
252are device specific.
253.Bl -tag -width indent
254.It Va hw.snd.compat_linux_mmap
255Linux
256.Xr mmap 2
257compatibility.
258The following values are supported (default is 0):
259.Bl -tag -width 2n
260.It -1
261Force disabling/denying PROT_EXEC
262.Xr mmap 2
263requests.
264.It 0
265Auto detect proc/ABI type, allow
266.Xr mmap 2
267for Linux applications, and deny for everything else.
268.It 1
269Always allow PROT_EXEC page mappings.
270.El
271.It Va hw.snd.default_auto
272Automatically assign the default sound unit.
273The following values are supported (default is 1):
274.Bl -tag -width 2n
275.It 0
276Do not assign the default sound unit automatically.
277.It 1
278Use the best available sound device based on playing and recording
279capabilities of the device.
280.It 2
281Use the most recently attached device.
282.El
283.It Va hw.snd.default_unit
284Default sound card for systems with multiple sound cards.
285When using
286.Xr devfs 5 ,
287the default device for
288.Pa /dev/dsp .
289Equivalent to a symlink from
290.Pa /dev/dsp
291to
292.Pa /dev/dsp Ns Va ${hw.snd.default_unit} .
293.It Va hw.snd.feeder_eq_exact_rate
294Only certain rates are allowed for precise processing.
295The default behavior is however to allow sloppy processing for all rates,
296even the unsupported ones.
297Enable to toggle this requirement and only allow processing for supported
298rates.
299.It Va hw.snd.feeder_rate_max
300Maximum allowable sample rate.
301.It Va hw.snd.feeder_rate_min
302Minimum allowable sample rate.
303.It Va hw.snd.feeder_rate_polyphase_max
304Adjust to set the maximum number of allowed polyphase entries during the
305process of building resampling filters.
306Disabling polyphase resampling has the benefit of reducing memory usage, at
307the expense of slower and lower quality conversion.
308Only applicable when the SINC interpolator is used.
309Default value is 183040.
310Set to 0 to disable polyphase resampling.
311.It Va hw.snd.feeder_rate_quality
312Sample rate converter quality.
313Default value is 1, linear interpolation.
314Available options include:
315.Bl -tag -width 2n
316.It 0
317Zero Order Hold, ZOH.
318Very fast, but with poor quality.
319.It 1
320Linear interpolation.
321Fast, quality is subject to personal preference.
322Technically the quality is poor however, due to the lack of anti-aliasing
323filtering.
324.It 2
325Bandlimited SINC interpolator.
326Implements polyphase banking to boost the conversion speed, at the cost of
327memory usage, with multiple high quality polynomial interpolators to improve
328the conversion accuracy.
329100% fixed point, 64bit accumulator with 32bit coefficients and high precision
330sample buffering.
331Quality values are 100dB stopband, 8 taps and 85% bandwidth.
332.It 3
333Continuation of the bandlimited SINC interpolator, with 100dB stopband, 36
334taps and 90% bandwidth as quality values.
335.It 4
336Continuation of the bandlimited SINC interprolator, with 100dB stopband, 164
337taps and 97% bandwidth as quality values.
338.El
339.It Va hw.snd.feeder_rate_round
340Sample rate rounding threshold, to avoid large prime division at the
341cost of accuracy.
342All requested sample rates will be rounded to the nearest threshold value.
343Possible values range between 0 (disabled) and 500.
344Default is 25.
345.It Va hw.snd.latency
346Configure the buffering latency.
347Only affects applications that do not explicitly request
348blocksize / fragments.
349This tunable provides finer granularity than the
350.Va hw.snd.latency_profile
351tunable.
352Possible values range between 0 (lowest latency) and 10 (highest latency).
353.It Va hw.snd.latency_profile
354Define sets of buffering latency conversion tables for the
355.Va hw.snd.latency
356tunable.
357A value of 0 will use a low and aggressive latency profile which can result
358in possible underruns if the application cannot keep up with a rapid irq
359rate, especially during high workload.
360The default value is 1, which is considered a moderate/safe latency profile.
361.It Va hw.snd.maxautovchans
362Global VCHAN setting that only affects devices with at least one playback or
363recording channel available.
364The sound system will dynamically create up to this many VCHANs.
365Set to
366.Dq 0
367if no VCHANs are desired.
368Maximum value is 256.
369.It Va hw.snd.report_soft_formats
370Controls the internal format conversion if it is
371available transparently to the application software.
372When disabled or not available, the application will
373only be able to select formats the device natively supports.
374.It Va hw.snd.report_soft_matrix
375Enable seamless channel matrixing even if the hardware does not support it.
376Makes it possible to play multichannel streams even with a simple stereo
377sound card.
378.It Va hw.snd.verbose
379Level of verbosity for the
380.Pa /dev/sndstat
381device.
382Higher values include more output and the highest level,
383four, should be used when reporting problems.
384Other options include:
385.Bl -tag -width 2n
386.It 0
387Installed devices and their allocated bus resources.
388.It 1
389The number of playback, record, virtual channels, and
390flags per device.
391.It 2
392Channel information per device including the channel's
393current format, speed, and pseudo device statistics such as
394buffer overruns and buffer underruns.
395.It 3
396File names and versions of the currently loaded sound modules.
397.It 4
398Various messages intended for debugging.
399.El
400.It Va hw.snd.vpc_0db
401Default value for
402.Nm
403volume.
404Increase to give more room for attenuation control.
405Decrease for more amplification, with the possible cost of sound clipping.
406.It Va hw.snd.vpc_autoreset
407When a channel is closed the channel volume will be reset to 0db.
408This means that any changes to the volume will be lost.
409Enabling this will preserve the volume, at the cost of possible confusion
410when applications tries to re-open the same device.
411.It Va hw.snd.vpc_mixer_bypass
412The recommended way to use the VPC feature is to teach applications to use the
413correct
414.Fn ioctl :
415.Dv SNDCTL_DSP_GETPLAYVOL , SNDCTL_DSP_SETPLAYVOL ,
416.Dv SNDCTL_DSP_SETRECVOL , SNDCTL_DSP_SETRECVOL .
417This is however not always possible.
418Enable this to allow applications to use their own existing mixer logic
419to control their own channel volume.
420.It Va hw.snd.vpc_reset
421Enable to restore all channel volumes back to the default value of 0db.
422.It Va dev.pcm.%d.bitperfect
423Enable or disable bitperfect mode.
424When enabled, channels will skip all dsp processing, such as channel
425matrixing, rate converting and equalizing.
426The pure
427.Nm
428stream will be fed directly to the hardware.
429If VCHANs are enabled, the bitperfect mode will use the VCHAN format/rate as
430the definitive format/rate target.
431The recommended way to use bitperfect mode is to disable VCHANs and enable this
432sysctl.
433Default is disabled.
434.It Va dev.pcm.%d.[play|rec].vchans
435The current number of VCHANs allocated per device.
436This can be set to preallocate a certain number of VCHANs.
437Setting this value to
438.Dq 0
439will disable VCHANs for this device.
440.It Va dev.pcm.%d.[play|rec].vchanformat
441Format for VCHAN mixing.
442All playback paths will be converted to this format before the mixing
443process begins.
444By default only 2 channels are enabled.
445Available options include:
446.Bl -tag -width 2n
447.It s16le:1.0
448Mono.
449.It s16le:2.0
450Stereo, 2 channels (left, right).
451.It s16le:2.1
4523 channels (left, right, LFE).
453.It s16le:3.0
4543 channels (left, right, rear center).
455.It s16le:4.0
456Quadraphonic, 4 channels (front/rear left and right).
457.It s16le:4.1
4585 channels (4.0 + LFE).
459.It s16le:5.0
4605 channels (4.0 + center).
461.It s16le:5.1
4626 channels (4.0 + center + LFE).
463.It s16le:6.0
4646 channels (4.0 + front/rear center).
465.It s16le:6.1
4667 channels (6.0 + LFE).
467.It s16le:7.1
4688 channels (4.0 + center + LFE + left and right side).
469.El
470.It Va dev.pcm.%d.[play|rec].vchanmode
471VCHAN format/rate selection.
472Available options include:
473.Bl -tag -width 2n
474.It fixed
475Channel mixing is done using fixed format/rate.
476Advanced operations such as digital passthrough will not work.
477Can be considered as a
478.Dq legacy
479mode.
480This is the default mode for hardware channels which lack support for digital
481formats.
482.It passthrough
483Channel mixing is done using fixed format/rate, but advanced operations such
484as digital passthrough also work.
485All channels will produce sound as usual until a digital format playback is
486requested.
487When this happens all other channels will be muted and the latest incoming
488digital format will be allowed to pass through undisturbed.
489Multiple concurrent digital streams are supported, but the latest stream will
490take precedence and mute all other streams.
491.It adaptive
492Works like the
493.Dq passthrough
494mode, but is a bit smarter, especially for
495multiple
496.Nm
497channels with different format/rate.
498When a new channel is about to start, the entire list of virtual channels will
499be scanned, and the channel with the best format/rate (usually the
500highest/biggest) will be selected.
501This ensures that mixing quality depends on the best channel.
502The downside is that the hardware DMA mode needs to be restarted, which may
503cause annoying pops or clicks.
504.El
505.It Va dev.pcm.%d.[play|rec].vchanrate
506Sample rate speed for VCHAN mixing.
507All playback paths will be converted to this sample rate before the mixing
508process begins.
509.It Va dev.pcm.%d.polling
510Experimental polling mode support where the driver operates by querying the
511device state on each tick using a
512.Xr callout 9
513mechanism.
514Disabled by default and currently only available for a few device drivers.
515.El
516.Ss Recording Channels
517On devices that have more than one recording source (ie: mic and line),
518there is a corresponding
519.Pa /dev/dsp%d.r%d
520device.
521The
522.Xr mixer 8
523utility can be used to start and stop recording from an specific device.
524.Ss Statistics
525Channel statistics are only kept while the device is open.
526So with situations involving overruns and underruns, consider the output
527while the errant application is open and running.
528.Ss IOCTL Support
529The driver supports most of the OSS
530.Fn ioctl
531functions, and most applications work unmodified.
532A few differences exist, while memory mapped playback is
533supported natively and in Linux emulation, memory mapped recording is not due
534to VM system design.
535As a consequence, some applications may need to be recompiled
536with a slightly modified audio module.
537See
538.In sys/soundcard.h
539for a complete list of the supported
540.Fn ioctl
541functions.
542.Sh FILES
543The
544.Nm
545drivers may create the following
546device nodes:
547.Pp
548.Bl -tag -width ".Pa /dev/audio%d.%d" -compact
549.It Pa /dev/audio%d.%d
550Sparc-compatible audio device.
551.It Pa /dev/dsp%d.%d
552Digitized voice device.
553.It Pa /dev/dspW%d.%d
554Like
555.Pa /dev/dsp ,
556but 16 bits per sample.
557.It Pa /dev/dsp%d.p%d
558Playback channel.
559.It Pa /dev/dsp%d.r%d
560Record channel.
561.It Pa /dev/dsp%d.vp%d
562Virtual playback channel.
563.It Pa /dev/dsp%d.vr%d
564Virtual recording channel.
565.It Pa /dev/sndstat
566Current
567.Nm
568status, including all channels and drivers.
569.El
570.Pp
571The first number in the device node
572represents the unit number of the
573.Nm
574device.
575All
576.Nm
577devices are listed
578in
579.Pa /dev/sndstat .
580Additional messages are sometimes recorded when the
581device is probed and attached, these messages can be viewed with the
582.Xr dmesg 8
583utility.
584.Pp
585The above device nodes are only created on demand through the dynamic
586.Xr devfs 5
587clone handler.
588Users are strongly discouraged to access them directly.
589For specific sound card access, please instead use
590.Pa /dev/dsp
591or
592.Pa /dev/dsp%d .
593.Sh EXAMPLES
594Use the sound metadriver to load all
595.Nm
596bridge device drivers at once
597(for example if it is unclear which the correct driver to use is):
598.Pp
599.Dl kldload snd_driver
600.Pp
601Load a specific bridge device driver, in this case the Intel
602High Definition Audio driver:
603.Pp
604.Dl kldload snd_hda
605.Pp
606Check the status of all detected
607.Nm
608devices:
609.Pp
610.Dl cat /dev/sndstat
611.Pp
612Change the default sound device, in this case to the second device.
613This is handy if there are multiple
614.Nm
615devices available:
616.Pp
617.Dl sysctl hw.snd.default_unit=1
618.Sh DIAGNOSTICS
619.Bl -diag
620.It pcm%d:play:%d:dsp%d.p%d: play interrupt timeout, channel dead
621The hardware does not generate interrupts to serve incoming (play)
622or outgoing (record) data.
623.It unsupported subdevice XX
624A device node is not created properly.
625.El
626.Sh SEE ALSO
627.Xr snd_ai2s 4 ,
628.Xr snd_als4000 4 ,
629.Xr snd_atiixp 4 ,
630.Xr snd_cmi 4 ,
631.Xr snd_cs4281 4 ,
632.Xr snd_csa 4 ,
633.Xr snd_davbus 4 ,
634.Xr snd_emu10k1 4 ,
635.Xr snd_emu10kx 4 ,
636.Xr snd_envy24 4 ,
637.Xr snd_envy24ht 4 ,
638.Xr snd_es137x 4 ,
639.Xr snd_fm801 4 ,
640.Xr snd_hda 4 ,
641.Xr snd_hdspe 4 ,
642.Xr snd_ich 4 ,
643.Xr snd_maestro3 4 ,
644.Xr snd_neomagic 4 ,
645.Xr snd_solo 4 ,
646.Xr snd_spicds 4 ,
647.Xr snd_t4dwave 4 ,
648.Xr snd_uaudio 4 ,
649.Xr snd_via8233 4 ,
650.Xr snd_via82c686 4 ,
651.Xr snd_vibes 4 ,
652.Xr devfs 5 ,
653.Xr device.hints 5 ,
654.Xr loader.conf 5 ,
655.Xr dmesg 8 ,
656.Xr kldload 8 ,
657.Xr mixer 8 ,
658.Xr sysctl 8
659.Rs
660.%T "Cookbook formulae for audio EQ biquad filter coefficients (Audio-EQ-Cookbook.txt), by Robert Bristow-Johnson"
661.%U "https://www.musicdsp.org/en/latest/Filters/197-rbj-audio-eq-cookbook.html"
662.Re
663.Rs
664.%T "Julius O'Smith's Digital Audio Resampling"
665.%U "http://ccrma.stanford.edu/~jos/resample/"
666.Re
667.Rs
668.%T "Polynomial Interpolators for High-Quality Resampling of Oversampled Audio, by Olli Niemitalo"
669.%U "http://yehar.com/blog/wp-content/uploads/2009/08/deip.pdf"
670.Re
671.Rs
672.%T "The OSS API"
673.%U "http://www.opensound.com/pguide/oss.pdf"
674.Re
675.Sh HISTORY
676The
677.Nm
678device driver first appeared in
679.Fx 2.2.6
680as
681.Nm pcm ,
682written by
683.An Luigi Rizzo .
684It was later
685rewritten in
686.Fx 4.0
687by
688.An Cameron Grant .
689The API evolved from the VOXWARE
690standard which later became OSS standard.
691.Sh AUTHORS
692.An -nosplit
693.An Luigi Rizzo Aq Mt luigi@iet.unipi.it
694initially wrote the
695.Nm pcm
696device driver and this manual page.
697.An Cameron Grant Aq Mt gandalf@vilnya.demon.co.uk
698later revised the device driver for
699.Fx 4.0 .
700.An Seigo Tanimura Aq Mt tanimura@r.dl.itc.u-tokyo.ac.jp
701revised this manual page.
702It was then rewritten for
703.Fx 5.2 .
704.Sh BUGS
705Some features of your sound card (e.g., global volume control) might not
706be supported on all devices.
707