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 June 23, 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 VCHANs 145Each device can optionally support more playback and recording channels 146than physical hardware provides by using 147.Dq virtual channels 148or 149.Tn VCHANs . 150.Tn VCHAN 151options can be configured via the 152.Xr sysctl 8 153interface but can only be manipulated while the device is inactive. 154.Ss Runtime Configuration 155There are a number of 156.Xr sysctl 8 157variables available. 158.Va hw.snd.* 159tunables are global settings and 160.Va dev.pcm.* 161are device specific. 162.Bl -tag -width ".Va hw.snd.report_soft_formats" -offset indent 163.It Va hw.snd.compat_linux_mmap 164Enable to allow PROT_EXEC page mappings. 165All Linux applications using sound and 166.Xr mmap 2 167require this. 168.It Va hw.snd.default_auto 169Enable to automatically assign default sound unit to the most recent 170attached device. 171.It Va hw.snd.default_unit 172Default sound card for systems with multiple sound cards. 173When using 174.Xr devfs 5 , 175the default device for 176.Pa /dev/dsp . 177Equivalent to a symlink from 178.Pa /dev/dsp 179to 180.Pa /dev/dsp Ns Va ${hw.snd.default_unit} . 181.It Va hw.snd.feeder_eq_exact_rate 182Only certain rates are allowed for precise processing. 183The default behavior is however to allow sloppy processing for all rates, 184even the unsupported ones. 185Enable to toggle this requirement and only allow processing for supported 186rates. 187.It Va hw.snd.feeder_rate_max 188Maximum allowable sample rate. 189.It Va hw.snd.feeder_rate_min 190Minimum allowable sample rate. 191.It Va hw.snd.feeder_rate_round 192Sample rate rounding threshold, to avoid large prime division at the 193cost of accuracy. 194All requested sample rates will be rounded to the nearest threshold value. 195Possible values range between 0 (disabled) and 500. 196Default is 25. 197.It Va hw.snd.feeder_polyphase_max 198Adjust to set the maximum number of allowed polyphase entries during the 199process of building resampling filters. 200Only applicable when the SINC interpolator is used. 201Default value is 183040. 202Set to 0 to disable polyphase resampling. 203.It Va hw.snd.feeder_quality 204Sample rate converter quality. 205Default value is 1, linear interpolation. 206Available options include: 207.Bl -tag -width 2n 208.It 0 209Zero Order Hold, ZOH. 210Very fast, but with poor quality. 211.It 1 212Linear interpolation. 213Fast, quality is subject to personal preference. 214Technically the quality is poor however, due to the lack of anti-aliasing 215filtering. 216.It 2 217Bandlimited SINC interpolator. 218Implements polyphase banking to boost the conversion speed, at the cost of 219memory usage, with multiple high quality polynomial interpolators to improve 220the conversion accuracy. 221100% fixed point, 64bit accumulator with 32bit coefficients and high precision 222sample buffering. 223Quality values are 100dB stopband, 8 taps and 85% bandwidth. 224.It 3 225Continuation of the bandlimited SINC interpolator, with 100dB stopband, 36 226taps and 90% bandwidth as quality values. 227.It 4 228Continuation of the bandlimited SINC inteprolator, with 100dB stopband, 164 229taps and 97% bandwidth as quality values. 230.El 231.It Va hw.snd.latency 232Configure the buffering latency. 233Only affects applications that do not explicitly request 234blocksize / fragments. 235This tunable provides finer granularity than the 236.Va hw.snd.latency_profile 237tunable. 238Possible values range between 0 (lowest latency) and 10 (highest latency). 239.It Va hw.snd.latency_profile 240Define sets of buffering latency conversion tables for the 241.Va hw.snd.latency 242tunable. 243A value of 0 will use a low and aggressive latency profile which can result 244in possible underruns if the application cannot keep up with a rapid irq 245rate, especially during high workload. 246The default value is 1, which is considered a moderate/safe latency profile. 247.It Va hw.snd.maxautovchans 248Global 249.Tn VCHAN 250setting that only affects devices with at least one playback or recording channel available. 251The sound system will dynamically create up to this many 252.Tn VCHANs . 253Set to 254.Dq 0 255if no 256.Tn VCHANS 257are desired. 258Maximum value is 256. 259.It Va hw.snd.report_soft_formats 260Controls the internal format conversion if it is 261available transparently to the application software. 262When disabled or not available, the application will 263only be able to select formats the device natively supports. 264.It Va hw.snd.report_soft_matrix 265Enable seamless channel matrixing even if the hardware does not support it. 266Makes it possible to play multichannel streams even with a simple stereo 267sound card. 268.It Va hw.snd.verbose 269Level of verbosity for the 270.Pa /dev/sndstat 271device. 272Higher values include more output and the highest level, 273four, should be used when reporting problems. 274Other options include: 275.Bl -tag -width 2n 276.It 0 277Installed devices and their allocated bus resources. 278.It 1 279The number of playback, record, virtual channels, and 280flags per device. 281.It 2 282Channel information per device including the channel's 283current format, speed, and pseudo device statistics such as 284buffer overruns and buffer underruns. 285.It 3 286File names and versions of the currently loaded sound modules. 287.It 4 288Various messages intended for debugging. 289.El 290.It Va hw.snd.vpc_0db 291Default value for 292.Nm 293volume. 294Increase to give more room for attenuation control. 295Decrease for more amplification, with the possible cost of sound clipping. 296.It Va hw.snd.vpc_autoreset 297When a channel is closed the channel volume will be reset to 0db. 298This means that any changes to the volume will be lost. 299Enabling this will preserve the volume, at the cost of possible confusion 300when applications tries to re-open the same device. 301.It Va hw.snd.vpc_mixer_bypass 302The recommended way to use the vpc feature is to teach applications to use 303the correct 304.Fn ioctl : 305.Dv SNDCTL_DSP_GETPLAYVOL, SNDCTL_DSP_SETPLAYVOL, 306.Dv SNDCTL_DSP_SETRECVOL, SNDCTL_DSP_SETRECVOL. 307This is however not always possible. 308Enable this to allow applications to use their own existing mixer logic 309to control their own channel volume. 310.It Va hw.snd.vpc_reset 311Enable to restore all channel volumes back to the default value of 0db. 312.It Va dev.pcm.%d.bitperfect 313Enable or disable bitperfect mode. 314When enabled, channels will skip all dsp processing, such as channel 315matrixing, rate converting and equalizing. 316The pure 317.Nm 318stream will be fed directly to the hardware. 319If 320.Tn VCHANs 321are enabled, the bitperfect mode will use the 322.Tn VCHAN 323format/rate as the definitive format/rate target. 324The recommended way to use bitperfect mode is to disable 325.Tn VCHANs 326and enable this sysctl. 327Default is disabled. 328.It Va dev.pcm.%d.[play|rec].vchans 329The current number of 330.Tn VCHANs 331allocated per device. 332This can be set to preallocate a certain number of 333.Tn VCHANs . 334Setting this value to 335.Dq 0 336will disable 337.Tn VCHANs 338for this device. 339.It Va dev.pcm.%d.[play|rec].vchanformat 340Format for 341.Tn VCHAN 342mixing. 343All playback paths will be converted to this format before the mixing 344process begins. 345.It Va dev.pcm.%d.[play|rec].vchanmode 346.Tn VCHAN 347format/rate selection. 348Available options include: 349.Bl -tag -width 2n 350.It fixed 351Channel mixing is done using fixed format/rate. 352Advanced operations such as digital passthrough will not work. 353Can be considered as a 354.Dq legacy 355mode. 356This is the default mode for hardware channels which lack support for digital 357formats. 358.It passthrough 359Channel mixing is done using fixed format/rate, but advanced operations such 360as digital passthrough also work. 361All channels will produce sound as usual until a digital format playback is 362requested. 363When this happens all other channels will be muted and the latest incoming 364digital format will be allowed to pass through undisturbed. 365Multiple concurrent digital streams are supported, but the latest stream will 366take precedence and mute all other streams. 367.It adaptive 368Works like the 369.Dq passthrough 370mode, but is a bit smarter, especially for 371multiple 372.Nm 373channels with different format/rate. 374When a new channel is about to start, the entire list of virtual channels will 375be scanned, and the channel with the best format/rate (usually the 376highest/biggest) will be selected. 377This ensures that mixing quality depends on the best channel. 378The downside is that the hardware DMA mode needs to be restarted, which may 379cause annoying pops or clicks. 380.El 381.It Va dev.pcm.%d.[play|rec].vchanrate 382Sample rate speed for 383.Tn VCHAN 384mixing. 385All playback paths will be converted to this sample rate before the mixing 386process begins. 387.It Va dev.pcm.%d.polling 388Experimental polling mode support where the driver operates by querying the 389device state on each tick using a 390.Xr callout 9 391mechanism. 392Disabled by default and currently only available for a few device drivers. 393.El 394.Ss Recording Channels 395On devices that have more than one recording source (ie: mic and line), 396there is a corresponding 397.Pa /dev/dsp%d.r%d 398device. 399.Ss Statistics 400Channel statistics are only kept while the device is open. 401So with situations involving overruns and underruns, consider the output 402while the errant application is open and running. 403.Ss IOCTL Support 404The driver supports most of the 405.Tn OSS 406.Fn ioctl 407functions, and most applications work unmodified. 408A few differences exist, while memory mapped playback is 409supported natively and in 410.Tn Linux 411emulation, memory mapped recording is 412not due to 413.Tn VM 414system design. 415As a consequence, some applications may need to be recompiled 416with a slightly modified audio module. 417See 418.In sys/soundcard.h 419for a complete list of the supported 420.Fn ioctl 421functions. 422.Sh FILES 423The 424.Nm 425drivers may create the following 426device nodes: 427.Pp 428.Bl -tag -width ".Pa /dev/audio%d.%d" -compact 429.It Pa /dev/audio%d.%d 430Sparc-compatible audio device. 431.It Pa /dev/dsp%d.%d 432Digitized voice device. 433.It Pa /dev/dspW%d.%d 434Like 435.Pa /dev/dsp , 436but 16 bits per sample. 437.It Pa /dev/dsp%d.p%d 438Playback channel. 439.It Pa /dev/dsp%d.r%d 440Record channel. 441.It Pa /dev/dsp%d.vp%d 442Virtual playback channel. 443.It Pa /dev/dsp%d.vr%d 444Virtual recording channel. 445.It Pa /dev/sndstat 446Current 447.Nm 448status, including all channels and drivers. 449.El 450.Pp 451The first number in the device node 452represents the unit number of the 453.Nm 454device. 455All 456.Nm 457devices are listed 458in 459.Pa /dev/sndstat . 460Additional messages are sometimes recorded when the 461device is probed and attached, these messages can be viewed with the 462.Xr dmesg 8 463utility. 464.Pp 465The above device nodes are only created on demand through the dynamic 466.Xr devfs 5 467clone handler. 468Users are strongly discouraged to access them directly. 469For specific sound card access, please instead use 470.Pa /dev/dsp 471or 472.Pa /dev/dsp%d . 473.Sh DIAGNOSTICS 474.Bl -diag 475.It pcm%d:play:%d:dsp%d.p%d: play interrupt timeout, channel dead 476The hardware does not generate interrupts to serve incoming (play) 477or outgoing (record) data. 478.It unsupported subdevice XX 479A device node is not created properly. 480.El 481.Sh SEE ALSO 482.Xr snd_ad1816 4 , 483.Xr snd_als4000 4 , 484.Xr snd_atiixp 4 , 485.Xr snd_audiocs 4 , 486.Xr snd_cmi 4 , 487.Xr snd_cs4281 4 , 488.Xr snd_csa 4 , 489.Xr snd_ds1 4 , 490.Xr snd_emu10k1 4 , 491.Xr snd_emu10kx 4 , 492.Xr snd_envy24 4 , 493.Xr snd_envy24ht 4 , 494.Xr snd_es137x 4 , 495.Xr snd_ess 4 , 496.Xr snd_fm801 4 , 497.Xr snd_gusc 4 , 498.Xr snd_hda 4 , 499.Xr snd_ich 4 , 500.Xr snd_maestro 4 , 501.Xr snd_maestro3 4 , 502.Xr snd_mss 4 , 503.Xr snd_neomagic 4 , 504.Xr snd_sbc 4 , 505.Xr snd_solo 4 , 506.Xr snd_spicds 4 , 507.Xr snd_t4dwave 4 , 508.Xr snd_uaudio 4 , 509.Xr snd_via8233 4 , 510.Xr snd_via82c686 4 , 511.Xr snd_vibes 4 , 512.Xr devfs 5 , 513.Xr device.hints 5 , 514.Xr loader.conf 5 , 515.Xr dmesg 8 , 516.Xr kldload 8 , 517.Xr sysctl 8 518.Rs 519.%T "Cookbook formulae for audio EQ biquad filter coefficients, by Robert Bristow-Johnson" 520.%O "http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt" 521.Re 522.Rs 523.%T "Julius O'Smith's Digital Audio Resampling" 524.%O "http://ccrma.stanford.edu/~jos/resample/" 525.Re 526.Rs 527.%T "Polynomial Interpolators for High-Quality Resampling of Oversampled Audio, by Olli Niemitalo" 528.%O "http://www.student.oulu.fi/~oniemita/dsp/deip.pdf" 529.Re 530.Rs 531.%T "The OSS API" 532.%O "http://www.opensound.com/pguide/oss.pdf" 533.Re 534.Sh HISTORY 535The 536.Nm 537device driver first appeared in 538.Fx 2.2.6 539as 540.Nm pcm , 541written by 542.An Luigi Rizzo . 543It was later 544rewritten in 545.Fx 4.0 546by 547.An Cameron Grant . 548The API evolved from the VOXWARE 549standard which later became OSS standard. 550.Sh AUTHORS 551.An -nosplit 552.An Luigi Rizzo Aq luigi@iet.unipi.it 553initially wrote the 554.Nm pcm 555device driver and this manual page. 556.An Cameron Grant Aq gandalf@vilnya.demon.co.uk 557later revised the device driver for 558.Fx 4.0 . 559.An Seigo Tanimura Aq tanimura@r.dl.itc.u-tokyo.ac.jp 560revised this manual page. 561It was then rewritten for 562.Fx 5.2 . 563.Sh BUGS 564Some features of your sound card (e.g., global volume control) might not 565be supported on all devices. 566