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