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