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 February 15, 2025 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.vchans_enable 364Global VCHAN setting to enable (1) or disable (0) VCHANs. 365This setting can be overridden for an individual device by using the 366.Va dev.pcm.%d.[play|rec].vchans 367tunables. 368Default is enabled. 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 435Enable (1) or disable (0) VCHANs. 436Default is enabled. 437.It Va dev.pcm.%d.[play|rec].vchanformat 438Format for VCHAN mixing. 439All playback paths will be converted to this format before the mixing 440process begins. 441By default only 2 channels are enabled. 442Available options include: 443.Bl -tag -width 2n 444.It s16le:1.0 445Mono. 446.It s16le:2.0 447Stereo, 2 channels (left, right). 448.It s16le:2.1 4493 channels (left, right, LFE). 450.It s16le:3.0 4513 channels (left, right, rear center). 452.It s16le:4.0 453Quadraphonic, 4 channels (front/rear left and right). 454.It s16le:4.1 4555 channels (4.0 + LFE). 456.It s16le:5.0 4575 channels (4.0 + center). 458.It s16le:5.1 4596 channels (4.0 + center + LFE). 460.It s16le:6.0 4616 channels (4.0 + front/rear center). 462.It s16le:6.1 4637 channels (6.0 + LFE). 464.It s16le:7.1 4658 channels (4.0 + center + LFE + left and right side). 466.El 467.It Va dev.pcm.%d.[play|rec].vchanmode 468VCHAN format/rate selection. 469Available options include: 470.Bl -tag -width 2n 471.It fixed 472Channel mixing is done using fixed format/rate. 473Advanced operations such as digital passthrough will not work. 474Can be considered as a 475.Dq legacy 476mode. 477This is the default mode for hardware channels which lack support for digital 478formats. 479.It passthrough 480Channel mixing is done using fixed format/rate, but advanced operations such 481as digital passthrough also work. 482All channels will produce sound as usual until a digital format playback is 483requested. 484When this happens all other channels will be muted and the latest incoming 485digital format will be allowed to pass through undisturbed. 486Multiple concurrent digital streams are supported, but the latest stream will 487take precedence and mute all other streams. 488.It adaptive 489Works like the 490.Dq passthrough 491mode, but is a bit smarter, especially for 492multiple 493.Nm 494channels with different format/rate. 495When a new channel is about to start, the entire list of virtual channels will 496be scanned, and the channel with the best format/rate (usually the 497highest/biggest) will be selected. 498This ensures that mixing quality depends on the best channel. 499The downside is that the hardware DMA mode needs to be restarted, which may 500cause annoying pops or clicks. 501.El 502.It Va dev.pcm.%d.[play|rec].vchanrate 503Sample rate speed for VCHAN mixing. 504All playback paths will be converted to this sample rate before the mixing 505process begins. 506.It Va dev.pcm.%d.polling 507Experimental polling mode support where the driver operates by querying the 508device state on each tick using a 509.Xr callout 9 510mechanism. 511Disabled by default and currently only available for a few device drivers. 512.El 513.Ss Statistics 514Channel statistics are only kept while the device is open. 515So with situations involving overruns and underruns, consider the output 516while the errant application is open and running. 517.Ss IOCTL Support 518The driver supports most of the OSS 519.Fn ioctl 520functions, and most applications work unmodified. 521A few differences exist, while memory mapped playback is 522supported natively and in Linux emulation, memory mapped recording is not due 523to VM system design. 524As a consequence, some applications may need to be recompiled 525with a slightly modified audio module. 526See 527.In sys/soundcard.h 528for a complete list of the supported 529.Fn ioctl 530functions. 531.Sh FILES 532The 533.Nm 534drivers may create the following device nodes: 535.Pp 536.Bl -tag -width ".Pa /dev/sndstat" -compact 537.It Pa /dev/dsp%d 538Audio device. 539The number represents the unit number of the device. 540.It Pa /dev/dsp 541Alias of 542.Pa /dev/dsp${hw.snd.default_unit} . 543Available only if 544.Pa hw.snd.basename_clone 545is set. 546.It Pa /dev/sndstat 547Current 548.Nm 549status, including all channels and drivers. 550.El 551.Pp 552All 553.Nm 554devices are listed 555in 556.Pa /dev/sndstat . 557Additional messages are sometimes recorded when the 558device is probed and attached, these messages can be viewed with the 559.Xr dmesg 8 560utility. 561.Sh EXAMPLES 562Use the sound metadriver to load all 563.Nm 564bridge device drivers at once 565(for example if it is unclear which the correct driver to use is): 566.Pp 567.Dl kldload snd_driver 568.Pp 569Load a specific bridge device driver, in this case the Intel 570High Definition Audio driver: 571.Pp 572.Dl kldload snd_hda 573.Pp 574Check the status of all detected 575.Nm 576devices: 577.Pp 578.Dl cat /dev/sndstat 579.Pp 580Change the default sound device, in this case to the second device. 581This is handy if there are multiple 582.Nm 583devices available: 584.Pp 585.Dl mixer -d pcm1 586.Sh DIAGNOSTICS 587.Bl -diag 588.It pcm%d:play:%d:dsp%d.p%d: play interrupt timeout, channel dead 589The hardware does not generate interrupts to serve incoming (play) 590or outgoing (record) data. 591.It unsupported subdevice XX 592A device node is not created properly. 593.El 594.Sh SEE ALSO 595.Xr devfs 4 , 596.Xr snd_ai2s 4 , 597.Xr snd_als4000 4 , 598.Xr snd_atiixp 4 , 599.Xr snd_cmi 4 , 600.Xr snd_cs4281 4 , 601.Xr snd_csa 4 , 602.Xr snd_davbus 4 , 603.Xr snd_emu10k1 4 , 604.Xr snd_emu10kx 4 , 605.Xr snd_envy24 4 , 606.Xr snd_envy24ht 4 , 607.Xr snd_es137x 4 , 608.Xr snd_fm801 4 , 609.Xr snd_hda 4 , 610.Xr snd_hdsp 4 , 611.Xr snd_hdspe 4 , 612.Xr snd_ich 4 , 613.Xr snd_maestro3 4 , 614.Xr snd_neomagic 4 , 615.Xr snd_solo 4 , 616.Xr snd_spicds 4 , 617.Xr snd_t4dwave 4 , 618.Xr snd_uaudio 4 , 619.Xr snd_via8233 4 , 620.Xr snd_via82c686 4 , 621.Xr snd_vibes 4 , 622.Xr device.hints 5 , 623.Xr loader.conf 5 , 624.Xr dmesg 8 , 625.Xr kldload 8 , 626.Xr mixer 8 , 627.Xr sysctl 8 628.Rs 629.%T "Cookbook formulae for audio EQ biquad filter coefficients (Audio-EQ-Cookbook.txt), by Robert Bristow-Johnson" 630.%U "https://www.musicdsp.org/en/latest/Filters/197-rbj-audio-eq-cookbook.html" 631.Re 632.Rs 633.%T "Julius O'Smith's Digital Audio Resampling" 634.%U "http://ccrma.stanford.edu/~jos/resample/" 635.Re 636.Rs 637.%T "Polynomial Interpolators for High-Quality Resampling of Oversampled Audio, by Olli Niemitalo" 638.%U "http://yehar.com/blog/wp-content/uploads/2009/08/deip.pdf" 639.Re 640.Rs 641.%T "The OSS API" 642.%U "http://www.opensound.com/pguide/oss.pdf" 643.Re 644.Sh HISTORY 645The 646.Nm 647device driver first appeared in 648.Fx 2.2.6 649as 650.Nm pcm , 651written by 652.An Luigi Rizzo . 653It was later 654rewritten in 655.Fx 4.0 656by 657.An Cameron Grant . 658The API evolved from the VOXWARE 659standard which later became OSS standard. 660.Sh AUTHORS 661.An -nosplit 662.An Luigi Rizzo Aq Mt luigi@iet.unipi.it 663initially wrote the 664.Nm pcm 665device driver and this manual page. 666.An Cameron Grant Aq Mt gandalf@vilnya.demon.co.uk 667later revised the device driver for 668.Fx 4.0 . 669.An Seigo Tanimura Aq Mt tanimura@r.dl.itc.u-tokyo.ac.jp 670revised this manual page. 671It was then rewritten for 672.Fx 5.2 . 673.Sh BUGS 674Some features of your sound card (e.g., global volume control) might not 675be supported on all devices. 676.Pp 677Some audio devices might refuse to work properly unless the sample rate is 678configured the same for both recording and playback, even if only simplex is 679used. 680See the 681.Va dev.pcm.%d.[play|rec].vchanrate 682sysctls. 683