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