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