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 March 24, 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_hdsp 4 105.It 106.Xr snd_hdspe 4 107.It 108.Xr snd_ich 4 (enabled by default on amd64, i386) 109.It 110.Xr snd_maestro3 4 111.It 112.Xr snd_neomagic 4 113.It 114.Xr snd_solo 4 115.It 116.Xr snd_spicds 4 117.It 118.Xr snd_uaudio 4 (auto-loaded on device plug) 119.It 120.Xr snd_via8233 4 (enabled by default on amd64, i386) 121.It 122.Xr snd_via82c686 4 123.It 124.Xr snd_vibes 4 125.El 126.Pp 127Refer to the manual page for each bridge device driver for driver specific 128settings and information. 129.Ss Boot Variables 130In general, the module 131.Pa snd_foo 132corresponds to 133.Cd "device snd_foo" 134and can be 135loaded by the boot 136.Xr loader 8 137via 138.Xr loader.conf 5 139or from the command line using the 140.Xr kldload 8 141utility. 142Options which can be specified in 143.Pa /boot/loader.conf 144include: 145.Bl -tag -width ".Va snd_driver_load" -offset indent 146.It Va snd_driver_load 147.Pq Dq Li NO 148If set to 149.Dq Li YES , 150this option loads all available drivers. 151.It Va snd_hda_load 152.Pq Dq Li NO 153If set to 154.Dq Li YES , 155only the Intel High Definition Audio bridge device driver and dependent 156modules will be loaded. 157.It Va snd_foo_load 158.Pq Dq Li NO 159If set to 160.Dq Li YES , 161load driver for card/chipset foo. 162.El 163.Pp 164To define default values for the different mixer channels, 165set the channel to the preferred value using hints, e.g.: 166.Va hint.pcm.0.line Ns = Ns Qq Li 0 . 167This will mute the input channel per default. 168.Ss Multichannel Audio 169Multichannel audio, popularly referred to as 170.Dq surround sound 171is supported and enabled by default. 172The 173.Fx 174multichannel matrix processor supports up to 18 interleaved channels, but the 175limit is currently set to 8 channels (as commonly used for 7.1 surround sound). 176The internal matrix mapping can handle reduction, expansion or 177re-routing of channels. 178This provides a base interface for related multichannel 179.Fn ioctl 180support. 181Multichannel audio works both with and without VCHANs. 182.Pp 183Most bridge device drivers are still missing multichannel matrixing 184support, but in most cases this should be trivial to implement. 185Use the 186.Va dev.pcm.%d.[play|rec].vchanformat 187.Xr sysctl 8 188to adjust the number of channels used. 189The current multichannel interleaved structure and arrangement was 190implemented by inspecting various popular UNIX applications. 191There were no single standard, so much care has been taken to try 192to satisfy each possible scenario, despite the fact that each 193application has its own conflicting standard. 194.Ss EQ 195The Parametric Software Equalizer (EQ) enables the use of 196.Dq tone 197controls (bass and treble). 198Commonly used for ear-candy or frequency compensation due to the vast 199difference in hardware quality. 200EQ is disabled by default, but can be enabled with the 201.Va hint.pcm.%d.eq 202tunable. 203.Ss VCHANs 204Each device can optionally support more playback and recording channels 205than physical hardware provides by using 206.Dq virtual channels 207or VCHANs. 208VCHAN options can be configured via the 209.Xr sysctl 8 210interface but can only be manipulated while the device is inactive. 211.Ss VPC 212.Fx 213supports independent and individual volume controls for each active 214application, without touching the master 215.Nm 216volume. 217This is sometimes referred to as Volume Per Channel (VPC). 218The VPC feature is enabled by default. 219.Ss Loader Tunables 220The following loader tunables are used to set driver configuration at the 221.Xr loader 8 222prompt before booting the kernel, or they can be stored in 223.Pa /boot/loader.conf 224in order to automatically set them before booting the kernel. 225It is also possible to use 226.Xr kenv 1 227to change these tunables before loading the 228.Nm 229driver. 230The following tunables can not be changed during runtime using 231.Xr sysctl 8 . 232.Bl -tag -width indent 233.It Va hint.pcm.%d.eq 234Set to 1 or 0 to explicitly enable (1) or disable (0) the equalizer. 235Requires a driver reload if changed. 236Enabling this will make bass and treble controls appear in mixer applications. 237This tunable is undefined by default. 238Equalizing is disabled by default. 239.It Va hint.pcm.%d.vpc 240Set to 1 or 0 to explicitly enable (1) or disable (0) the VPC feature. 241This tunable is undefined by default. 242VPC is however enabled by default. 243.El 244.Ss Runtime Configuration 245There are a number of 246.Xr sysctl 8 247variables available which can be modified during runtime. 248These values can also be stored in 249.Pa /etc/sysctl.conf 250in order to automatically set them during the boot process. 251.Va hw.snd.* 252are global settings and 253.Va dev.pcm.* 254are device specific. 255.Bl -tag -width indent 256.It Va hw.snd.compat_linux_mmap 257Linux 258.Xr mmap 2 259compatibility. 260The following values are supported (default is 0): 261.Bl -tag -width 2n 262.It -1 263Force disabling/denying PROT_EXEC 264.Xr mmap 2 265requests. 266.It 0 267Auto detect proc/ABI type, allow 268.Xr mmap 2 269for Linux applications, and deny for everything else. 270.It 1 271Always allow PROT_EXEC page mappings. 272.El 273.It Va hw.snd.default_auto 274Automatically assign the default sound unit. 275The following values are supported (default is 1): 276.Bl -tag -width 2n 277.It 0 278Do not assign the default sound unit automatically. 279.It 1 280Use the best available sound device based on playing and recording 281capabilities of the device. 282.It 2 283Use the most recently attached device. 284.El 285.It Va hw.snd.default_unit 286Default sound card for systems with multiple sound cards. 287When using 288.Xr devfs 4 , 289the default device for 290.Pa /dev/dsp . 291Equivalent to a symlink from 292.Pa /dev/dsp 293to 294.Pa /dev/dsp Ns Va ${hw.snd.default_unit} . 295.It Va hw.snd.feeder_eq_exact_rate 296Only certain rates are allowed for precise processing. 297The default behavior is however to allow sloppy processing for all rates, 298even the unsupported ones. 299Enable to toggle this requirement and only allow processing for supported 300rates. 301.It Va hw.snd.feeder_rate_max 302Maximum allowable sample rate. 303.It Va hw.snd.feeder_rate_min 304Minimum allowable sample rate. 305.It Va hw.snd.feeder_rate_polyphase_max 306Adjust to set the maximum number of allowed polyphase entries during the 307process of building resampling filters. 308Disabling polyphase resampling has the benefit of reducing memory usage, at 309the expense of slower and lower quality conversion. 310Only applicable when the SINC interpolator is used. 311Default value is 183040. 312Set to 0 to disable polyphase resampling. 313.It Va hw.snd.feeder_rate_quality 314Sample rate converter quality. 315Default value is 1, linear interpolation. 316Available options include: 317.Bl -tag -width 2n 318.It 0 319Zero Order Hold, ZOH. 320Very fast, but with poor quality. 321.It 1 322Linear interpolation. 323Fast, quality is subject to personal preference. 324Technically the quality is poor however, due to the lack of anti-aliasing 325filtering. 326.It 2 327Bandlimited SINC interpolator. 328Implements polyphase banking to boost the conversion speed, at the cost of 329memory usage, with multiple high quality polynomial interpolators to improve 330the conversion accuracy. 331100% fixed point, 64bit accumulator with 32bit coefficients and high precision 332sample buffering. 333Quality values are 100dB stopband, 8 taps and 85% bandwidth. 334.It 3 335Continuation of the bandlimited SINC interpolator, with 100dB stopband, 36 336taps and 90% bandwidth as quality values. 337.It 4 338Continuation of the bandlimited SINC interprolator, with 100dB stopband, 164 339taps and 97% bandwidth as quality values. 340.El 341.It Va hw.snd.feeder_rate_round 342Sample rate rounding threshold, to avoid large prime division at the 343cost of accuracy. 344All requested sample rates will be rounded to the nearest threshold value. 345Possible values range between 0 (disabled) and 500. 346Default is 25. 347.It Va hw.snd.latency 348Configure the buffering latency. 349Only affects applications that do not explicitly request 350blocksize / fragments. 351This tunable provides finer granularity than the 352.Va hw.snd.latency_profile 353tunable. 354Possible values range between 0 (lowest latency) and 10 (highest latency). 355.It Va hw.snd.latency_profile 356Define sets of buffering latency conversion tables for the 357.Va hw.snd.latency 358tunable. 359A value of 0 will use a low and aggressive latency profile which can result 360in possible underruns if the application cannot keep up with a rapid irq 361rate, especially during high workload. 362The default value is 1, which is considered a moderate/safe latency profile. 363.It Va hw.snd.maxautovchans 364Global VCHAN setting that only affects devices with at least one playback or 365recording channel available. 366The sound system will dynamically create up to this many VCHANs. 367Set to 368.Dq 0 369if no VCHANs are 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 VPC feature is to teach applications to use the 415correct 416.Fn ioctl : 417.Dv SNDCTL_DSP_GETPLAYVOL , SNDCTL_DSP_SETPLAYVOL , 418.Dv SNDCTL_DSP_SETRECVOL , SNDCTL_DSP_SETRECVOL . 419This is however not always possible. 420Enable this to allow applications to use their own existing mixer logic 421to control their own channel volume. 422.It Va hw.snd.vpc_reset 423Enable to restore all channel volumes back to the default value of 0db. 424.It Va dev.pcm.%d.bitperfect 425Enable or disable bitperfect mode. 426When enabled, channels will skip all dsp processing, such as channel 427matrixing, rate converting and equalizing. 428The pure 429.Nm 430stream will be fed directly to the hardware. 431If VCHANs are enabled, the bitperfect mode will use the VCHAN format/rate as 432the definitive format/rate target. 433The recommended way to use bitperfect mode is to disable VCHANs and enable this 434sysctl. 435Default is disabled. 436.It Va dev.pcm.%d.[play|rec].vchans 437The current number of VCHANs allocated per device. 438This can be set to preallocate a certain number of VCHANs. 439Setting this value to 440.Dq 0 441will disable VCHANs for this device. 442.It Va dev.pcm.%d.[play|rec].vchanformat 443Format for VCHAN mixing. 444All playback paths will be converted to this format before the mixing 445process begins. 446By default only 2 channels are enabled. 447Available options include: 448.Bl -tag -width 2n 449.It s16le:1.0 450Mono. 451.It s16le:2.0 452Stereo, 2 channels (left, right). 453.It s16le:2.1 4543 channels (left, right, LFE). 455.It s16le:3.0 4563 channels (left, right, rear center). 457.It s16le:4.0 458Quadraphonic, 4 channels (front/rear left and right). 459.It s16le:4.1 4605 channels (4.0 + LFE). 461.It s16le:5.0 4625 channels (4.0 + center). 463.It s16le:5.1 4646 channels (4.0 + center + LFE). 465.It s16le:6.0 4666 channels (4.0 + front/rear center). 467.It s16le:6.1 4687 channels (6.0 + LFE). 469.It s16le:7.1 4708 channels (4.0 + center + LFE + left and right side). 471.El 472.It Va dev.pcm.%d.[play|rec].vchanmode 473VCHAN format/rate selection. 474Available options include: 475.Bl -tag -width 2n 476.It fixed 477Channel mixing is done using fixed format/rate. 478Advanced operations such as digital passthrough will not work. 479Can be considered as a 480.Dq legacy 481mode. 482This is the default mode for hardware channels which lack support for digital 483formats. 484.It passthrough 485Channel mixing is done using fixed format/rate, but advanced operations such 486as digital passthrough also work. 487All channels will produce sound as usual until a digital format playback is 488requested. 489When this happens all other channels will be muted and the latest incoming 490digital format will be allowed to pass through undisturbed. 491Multiple concurrent digital streams are supported, but the latest stream will 492take precedence and mute all other streams. 493.It adaptive 494Works like the 495.Dq passthrough 496mode, but is a bit smarter, especially for 497multiple 498.Nm 499channels with different format/rate. 500When a new channel is about to start, the entire list of virtual channels will 501be scanned, and the channel with the best format/rate (usually the 502highest/biggest) will be selected. 503This ensures that mixing quality depends on the best channel. 504The downside is that the hardware DMA mode needs to be restarted, which may 505cause annoying pops or clicks. 506.El 507.It Va dev.pcm.%d.[play|rec].vchanrate 508Sample rate speed for VCHAN mixing. 509All playback paths will be converted to this sample rate before the mixing 510process begins. 511.It Va dev.pcm.%d.polling 512Experimental polling mode support where the driver operates by querying the 513device state on each tick using a 514.Xr callout 9 515mechanism. 516Disabled by default and currently only available for a few device drivers. 517.El 518.Ss Statistics 519Channel statistics are only kept while the device is open. 520So with situations involving overruns and underruns, consider the output 521while the errant application is open and running. 522.Ss IOCTL Support 523The driver supports most of the OSS 524.Fn ioctl 525functions, and most applications work unmodified. 526A few differences exist, while memory mapped playback is 527supported natively and in Linux emulation, memory mapped recording is not due 528to VM system design. 529As a consequence, some applications may need to be recompiled 530with a slightly modified audio module. 531See 532.In sys/soundcard.h 533for a complete list of the supported 534.Fn ioctl 535functions. 536.Sh FILES 537The 538.Nm 539drivers may create the following device nodes: 540.Pp 541.Bl -tag -width ".Pa /dev/sndstat" -compact 542.It Pa /dev/dsp%d 543Audio device. 544The number represents the unit number of the device. 545.It Pa /dev/dsp 546Alias of 547.Pa /dev/dsp${hw.snd.default_unit} . 548Available only if 549.Pa hw.snd.basename_clone 550is set. 551.It Pa /dev/sndstat 552Current 553.Nm 554status, including all channels and drivers. 555.El 556.Pp 557All 558.Nm 559devices are listed 560in 561.Pa /dev/sndstat . 562Additional messages are sometimes recorded when the 563device is probed and attached, these messages can be viewed with the 564.Xr dmesg 8 565utility. 566.Sh EXAMPLES 567Use the sound metadriver to load all 568.Nm 569bridge device drivers at once 570(for example if it is unclear which the correct driver to use is): 571.Pp 572.Dl kldload snd_driver 573.Pp 574Load a specific bridge device driver, in this case the Intel 575High Definition Audio driver: 576.Pp 577.Dl kldload snd_hda 578.Pp 579Check the status of all detected 580.Nm 581devices: 582.Pp 583.Dl cat /dev/sndstat 584.Pp 585Change the default sound device, in this case to the second device. 586This is handy if there are multiple 587.Nm 588devices available: 589.Pp 590.Dl mixer -d pcm1 591.Sh DIAGNOSTICS 592.Bl -diag 593.It pcm%d:play:%d:dsp%d.p%d: play interrupt timeout, channel dead 594The hardware does not generate interrupts to serve incoming (play) 595or outgoing (record) data. 596.It unsupported subdevice XX 597A device node is not created properly. 598.El 599.Sh SEE ALSO 600.Xr devfs 4 , 601.Xr snd_ai2s 4 , 602.Xr snd_als4000 4 , 603.Xr snd_atiixp 4 , 604.Xr snd_cmi 4 , 605.Xr snd_cs4281 4 , 606.Xr snd_csa 4 , 607.Xr snd_davbus 4 , 608.Xr snd_emu10k1 4 , 609.Xr snd_emu10kx 4 , 610.Xr snd_envy24 4 , 611.Xr snd_envy24ht 4 , 612.Xr snd_es137x 4 , 613.Xr snd_fm801 4 , 614.Xr snd_hda 4 , 615.Xr snd_hdsp 4 , 616.Xr snd_hdspe 4 , 617.Xr snd_ich 4 , 618.Xr snd_maestro3 4 , 619.Xr snd_neomagic 4 , 620.Xr snd_solo 4 , 621.Xr snd_spicds 4 , 622.Xr snd_t4dwave 4 , 623.Xr snd_uaudio 4 , 624.Xr snd_via8233 4 , 625.Xr snd_via82c686 4 , 626.Xr snd_vibes 4 , 627.Xr device.hints 5 , 628.Xr loader.conf 5 , 629.Xr dmesg 8 , 630.Xr kldload 8 , 631.Xr mixer 8 , 632.Xr sysctl 8 633.Rs 634.%T "Cookbook formulae for audio EQ biquad filter coefficients (Audio-EQ-Cookbook.txt), by Robert Bristow-Johnson" 635.%U "https://www.musicdsp.org/en/latest/Filters/197-rbj-audio-eq-cookbook.html" 636.Re 637.Rs 638.%T "Julius O'Smith's Digital Audio Resampling" 639.%U "http://ccrma.stanford.edu/~jos/resample/" 640.Re 641.Rs 642.%T "Polynomial Interpolators for High-Quality Resampling of Oversampled Audio, by Olli Niemitalo" 643.%U "http://yehar.com/blog/wp-content/uploads/2009/08/deip.pdf" 644.Re 645.Rs 646.%T "The OSS API" 647.%U "http://www.opensound.com/pguide/oss.pdf" 648.Re 649.Sh HISTORY 650The 651.Nm 652device driver first appeared in 653.Fx 2.2.6 654as 655.Nm pcm , 656written by 657.An Luigi Rizzo . 658It was later 659rewritten in 660.Fx 4.0 661by 662.An Cameron Grant . 663The API evolved from the VOXWARE 664standard which later became OSS standard. 665.Sh AUTHORS 666.An -nosplit 667.An Luigi Rizzo Aq Mt luigi@iet.unipi.it 668initially wrote the 669.Nm pcm 670device driver and this manual page. 671.An Cameron Grant Aq Mt gandalf@vilnya.demon.co.uk 672later revised the device driver for 673.Fx 4.0 . 674.An Seigo Tanimura Aq Mt tanimura@r.dl.itc.u-tokyo.ac.jp 675revised this manual page. 676It was then rewritten for 677.Fx 5.2 . 678.Sh BUGS 679Some features of your sound card (e.g., global volume control) might not 680be supported on all devices. 681