summaryrefslogtreecommitdiff
path: root/Advanced_Linux_Sound_Architecture
blob: 4c26a5a2c7a5e10f80e06d860176d41d979e7c0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
[[Category:Sound]]
[[Category:Audio/Video]]
[[cs:Advanced Linux Sound Architecture]]
[[de:Alsa]]
[[es:Advanced Linux Sound Architecture]]
[[fa:ALSA]]
[[fr:Alsa]]
[[he:Advanced Linux Sound Architecture]]
[[it:Advanced Linux Sound Architecture]]
[[ja:Advanced Linux Sound Architecture]]
[[nl:Advanced Linux Sound Architecture]]
[[pt:Advanced Linux Sound Architecture]]
[[ru:Advanced Linux Sound Architecture]]
[[sk:Advanced Linux Sound Architecture]]
[[th:Advanced Linux Sound Architecture]]
[[tr:Gelişmiş_ses_mimarisi_(ALSA)]]
[[zh-CN:Advanced Linux Sound Architecture]]
{{Related articles start}}
{{Related|Sound system}}
{{Related|Disable PC Speaker Beep}}
{{Related|Advanced Linux Sound Architecture/Example Configurations}}
{{Related|PulseAudio}}
{{Related articles end}}
The [[Wikipedia:Advanced Linux Sound Architecture|Advanced Linux Sound Architecture]] ('''ALSA''') is a Linux kernel component which replaced the original Open Sound System (OSSv3) for providing device drivers for sound cards. Besides the sound device drivers, '''ALSA''' also bundles a user space library for application developers who want to use driver features with a higher level API than direct interaction with the kernel drivers.

{{Note|For an alternative sound environment, see the [[Open Sound System]] page.}}

== Installation ==

ALSA is included in the default Arch Linux kernel ({{Pkg|linux}}) as a set of modules, so manual installation is not necessary.

[[udev]] will automatically probe your hardware at boot, loading the corresponding kernel module for your audio card. Therefore, your sound should already be working, but muted (as is the upstream default).

Users with a local login (at a virtual terminal or a display manager) have permission to play audio and change mixer levels. To allow this for a remote login, the user has to be [[Users and groups#Group management|added]] to the {{ic|audio}} group. Membership in the {{ic|audio}} group also allows direct access to devices, which can lead to applications grabbing exclusive output (breaking software mixing) and breaks fast-user-switching, and multiseat. Therefore, adding a user to the {{ic|audio}} group is '''not''' recommended, unless you specifically need to[https://wiki.ubuntu.com/Audio/TheAudioGroup].

=== User space utilities ===

[[pacman|Install]] the {{Pkg|alsa-utils}} package from the [[official repositories]], which (among other utilities) contains the programs {{ic|alsamixer}} and {{ic|amixer}}. ''alsamixer'' provides an [[Wikipedia:Ncurses|ncurses]] based interface for shell based configuration of audio devices. Also install the {{Pkg|alsa-plugins}} package if you want [[#High quality resampling|high quality resampling]], [[#Upmixing/downmixing|upmixing/downmixing]] and other advanced features.

If you want [[OSS]] applications to work with [[#Dmix|dmix]] install the {{Pkg|alsa-oss}} package as well. Load the [[kernel modules]] {{ic|snd_seq_oss}}, {{ic|snd_pcm_oss}} and {{ic|snd_mixer_oss}} to enable OSS emulation.

== Unmuting the channels ==

ALSA by default has all channels muted, all of which will need to be unmuted manually. This can be done using ''amixer'':

 $ amixer sset Master unmute

This can alternatively be done using ''alsamixer'':

 $ alsamixer

The {{ic|MM}} label below a channel indicates that the channel is muted, and {{ic|00}} indicates that it is open.

Scroll to the {{ic|Master}} and {{ic|PCM}} channels with the {{ic|←}} and {{ic|→}} keys and unmute them by pressing the {{ic|m}} key. Use the {{ic|↑}} key to increase the volume and obtain a value of {{ic|0}} dB gain. The gain can be found in the upper left next to the {{ic|Item:}} field.
{{Note|If gain is set above 0 dB audible distortion can become present.}}

To get full 5.1 or 7.1 surround sound you will likely need to unmute other channels such as {{ic|Front}}, {{ic|Surround}}, {{ic|Center}}, {{ic|LFE}} (subwoofer) and {{ic|Side}} (these are the names of the channels with Intel HD Audio, they may vary with different hardware). Please take note that this will not automatically upmix stereo sources (like most music). In order to accomplish that, see [[#Upmixing/downmixing]].

To enable your microphone, switch to the Capture tab with {{ic|F4}} and enable a channel with {{ic|Space}}.

To exit ''alsamixer'', press {{ic|Esc}}.

{{Note|
* Some cards need to have digital output muted or disabled in order to hear analog sound. For the Soundblaster Audigy LS mute the channel labeled {{ic|IEC958}}.
* Some machines, (like the Thinkpad T61), have a {{ic|Speaker}} channel which must be unmuted and adjusted as well.
* Some machines, (like the Dell E6400) may also require the {{ic|Front}} and {{ic|Headphone}} channels to be unmuted and adjusted.
* If your volume adjustments seem to be lost after you reboot, try running alsamixer as root.
}}

Next, test to see if sound works:

 $ speaker-test -c 2

Change {{ic|-c}} to fit your speaker setup. Use {{ic|-c 8}} for 7.1, for instance:

 $ speaker-test -c 8

If audio is being outputted to the wrong device, try manually specifying it with the  argument {{ic|-D}}. 

 $ speaker-test -D default -c 8

{{ic|-D}} accepts PCM channel names as values, which can be retrieved by running the following:

{{hc|<nowiki>$ aplay -L | grep :CARD</nowiki>|2=
default:CARD=PCH  # 'default' is the PCM channel name
sysdefault:CARD=PCH
front:CARD=PCH,DEV=0
surround21:CARD=PCH,DEV=0
surround40:CARD=PCH,DEV=0
surround41:CARD=PCH,DEV=0
surround50:CARD=PCH,DEV=0
surround51:CARD=PCH,DEV=0
surround71:CARD=PCH,DEV=0
}}

If that does not work, consult the [[#Configuration|Configuration]] and then [[#Troubleshooting|Troubleshooting]] sections.

The {{Pkg|alsa-utils}} package includes the [[systemd]] unit configuration files {{ic|alsa-restore.service}} and {{ic|alsa-store.service}}, which are activated during boot and before shutdown respectively. They do not need to be manually enabled using {{ic|systemctl}}.
For reference, ALSA stores its settings in {{ic|/var/lib/alsa/asound.state}}.

== Configuration ==

=== Basic syntax ===

ALSA configuration files follow a simple syntax consisting of hierarchical value to parameter (key) assignments. Below are (modified) excerpts from asoundrc.txt, which is usually found in {{ic|alsa-lib}} package but can be also reached [http://www.alsa-project.org/alsa-doc/alsa-lib/conf.html here].

==== Assignments and Separators ====

Assignments define a value of a given key. There are different assignment types and styles available.

{{hc|Simple assignment|2=
# This is a comment. Everything after the '#' symbol to the end of the line will be ignored by ALSA.
key = value # Equal signs are usually left out, since space can also be used as an separator.

key value # Equivalent to the example above.
}}

Separators are used to indicate the start and end of an assignment, but using commas or whitespace is also possible.

{{hc|Seperators|2=
# The following three assignments are equivalent.
key value0; key valueN;
key value0, key valueN,
key value0 key valueN

key
value0
	key
valueN
}}

Compound assignments use braces as separators.
{{hc|Compound assignment|2=
key {	subkey0 value0;
	subkeyN valueN;	}

key.subkey0 value0; # Equivalent to the example above.
key.subkeyN valueN;
}}

For easier reading, it is recommended to use first style for definitions including more then three keys.

Array definitions use brackets as separators.

{{hc|Single array|2=
key [	"value0";
	"valueN";	]

key.0 "value0"; # Equivalent to the example above
key.N "valueN";
}}

Everything depends on user preferences when it comes to different styles of configuration, however one should avoid mixing different styles. Further information on basic configuration can be found [http://www.volkerschatz.com/noise/alsa.html#basicconf here].

==== Data types ====

ALSA uses different data types for parameter values, which must be set in the users respective configuration file. Some keys accept multiple data types, while most do not. A list of configuration options and their respective type requirements for PCM plugins can be found [http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html here]

==== Operation modes ====

There are different operation modes for parsing nodes, the default mode is merge and create. If operation mode is either merge/create or merge type checking is done. Only same type assignments can be merged, so strings cannot be merged with integers. Trying to define a simple assignment in default operation mode to a compound (and vice versa) will also not work.

Prefixes of operation modes:
* "+" -- merge and create
* "-" -- merge
* "?" -- do not override
* "!" -- override

{{hc|Operation modes|2=
# Merge/create - If a node does not exist, it is created. If it does exist and types match,
# subkeyN is merged into key.
key.subkeyN valueN;

# Merge/create - Equivalent to above
key.+subkeyN valueN;

# Merge - Node key.subkeyN must already exist and must have same data type
key.-subkeyN valueN;

# No override - Ignore new assignment if key.subkeyN node already exists
key.?subkeyN valueN;

# Override - Removes subkeyN and all keys below it, then creates node key.subkeyN
key.!subkeyN valueN;
}}

Using override operation mode, when done correctly, is usually safe, however one should bear in mind, that there might be other necessary keys in a node for proper functioning.

{{warning| Overriding pcm node itself will most definitely make alsa unusable, since every plugin definition will be deleted. Therefore <b>do not use !pcm.key</b> unless you are making a configuration from scratch.}}

===== An example of setting default device using "defaults" node =====

Assuming that "defaults" node is set in /usr/share/alsa/alsa.conf, where defaults.pcm.card and its ctl counterpart have assignment values "0" (type integer), user wants to set default pcm and control device to (third) sound card "2" or "SB" for an Azalia sound card.

{{hc|Defaults node|2=
defaults.ctl.card 2; # Sets default device and control to third card (counting begins with 0).
defaults.pcm.card 2; # This does not change the data type.

defaults.ctl.+card 2; # Equivalent to above.
defaults.pcm.+card 2;

defaults.ctl.-card 2; # Same effect on a default setup, however if defaults node was removed or
defaults.pcm.-card 2; # type has been changed merge operation mode will result in no changes.

defaults.pcm.?card 2; # This does nothing, since this assignment already exists.
defaults.ctl.?card 2;

defaults.pcm.!card "SB"; # The override operation mode is necessary here, because of
defaults.ctl.!card "SB"; # different value types.
}}

Using double quotes here automatically sets values data type to string, so in the above example setting defaults.pcm.!card "2" would result in retaining last default device, in this case card 0. Using double quotes for strings is not mandatory as long as no special characters are used, which ideally should never be the case. This may be irrelevant in other assignments.

{{note| From a configuration point of view those are not equivalent to setting a compound "default" pcm device, since most users specify addressing type in there also, which actually may be the same, but the assignment itself still differs. Also defaults.pcm.card is referred to multiple times in alsa configuration files, usually as a fallback assignment, where different environment variables take precedence.}}

==== Nesting ====

Sometimes it may be useful and even easier to read using nesting in configuration.

{{hc|Nesting PCM plugins|2=
pcm.azalia {	type hw; card 0	}
pcm.!default {	type plug; slave.pcm "azalia"	}

# is equivalent to

pcm.!default {	type plug; slave.pcm {	type hw; card 0;	}	}

# which is also equivalent to

pcm.!default.type plug;
pcm.default.slave.pcm.type hw;
pcm.default.slave.pcm.card 0;
}}

==== Including configuration files ====

{{hc|Include other configuration files|2=
</path/to/configuration-file> # Include a configuration file
<confdir:/path/to/configuration-file> # Reference to a global configuration directory
}}

=== Set the default sound card ===

{{Expansion|Explain the difference between a "card" and a "device." {{ic|amixer --help}} suggests the two are not synonymous}}

If your sound card order changes on boot, you can specify their order in any file ending with {{ic|.conf}} in {{ic|/etc/modprobe.d}} ({{ic|/etc/modprobe.d/alsa-base.conf}} is suggested).
For example, if you want your mia sound card to be #0:

{{hc|/etc/modprobe.d/alsa-base.conf|2=
options snd_mia index=0
options snd_hda_intel index=1
}}

Use {{ic|$ cat /proc/asound/modules}} to get the loaded sound modules and their order. This list is usually all that is needed for the loading order. Use {{ic|<nowiki>$ lsmod | grep snd</nowiki>}} to get a devices & modules list. This configuration assumes you have one mia sound card using {{ic|snd_mia}} and one (e.g. onboard) card using {{ic|snd_hda_intel}}.

You can also provide an index of {{ic|-2}} to instruct ALSA to never use a card as the primary one. Distributions such as Linux Mint and Ubuntu use the following settings to avoid USB and other "abnormal" drivers from getting index {{ic|0}}:

{{hc|/etc/modprobe.d/alsa-base.conf|2=
options bt87x index=-2
options cx88_alsa index=-2
options saa7134-alsa index=-2
options snd-atiixp-modem index=-2
options snd-intel8x0m index=-2
options snd-via82xx-modem index=-2
options snd-usb-audio index=-2
options snd-usb-caiaq index=-2
options snd-usb-ua101 index=-2
options snd-usb-us122l index=-2
options snd-usb-usx2y index=-2
options snd-pcsp index=-2
options snd-usb-audio index=-2
}}

These changes require a system reboot.

See also [https://bbs.archlinux.org/viewtopic.php?pid=1446773#p1446773]

==== Select the default PCM via environment variable ====

In your configuration file, preferably global, add:
{{bc|1=
pcm.!default {
    type plug
    slave.pcm {
        @func getenv
        vars [ ALSAPCM ]
        default "hw:Audigy2"
    }
}
}}

You need to replace the default line with the name of your card (in the example is {{ic|Audigy2}}). You can get the names with {{ic|aplay -l}} or you can also use PCMs like '''surround51'''. But if you need to use the microphone it is a good idea to select full-duplex PCM as default.

Now you can start programs selecting the sound card just changing the environment variable {{ic|ALSAPCM}}. It works fine for all program that do not allow to select the card, for the others ensure you keep the default card.
For example, assuming you wrote a downmix PCM called {{ic|mix51to20}} you can use it with {{Pkg|mplayer}} using the commandline {{ic|ALSAPCM&#61;mix51to20 mplayer example_6_channel.wav}}

Instead of using new variables, you could set one of those mentioned in default global configuration.
{{hc|/usr/share/alsa/alsa.conf|2=
Variable name # Definition
ALSA_CARD # pcm.default pcm.hw pcm.plughw ctl.sysdefault ctl.hw rawmidi.default rawmidi.hw hwdep.hw
ALSA_CTL_CARD # ctl.sysdefault ctl.hw
ALSA_HWDEP_CARD # hwdep.default hwdep.hw
ALSA_HWDEP_DEVICE # hwdep.default hwdep.hw
ALSA_PCM_CARD # pcm.default pcm.hw pcm.plughw
ALSA_PCM_DEVICE # pcm.hw pcm.plughw
ALSA_RAWMIDI_CARD # rawmidi.default rawmidi.hw
ALSA_RAWMIDI_DEVICE # rawmidi.default rawmidi.hw
}}
{{note|Pay attention to default addressing type.}}

==== Alternative method ====
{{Tip|This process can be partly automated using {{AUR|asoundconf}} from the [[Arch User Repository]].}}

First you will have to find out the card and device id that you want to set as the default:

{{hc|$ aplay -l|2=
**** List of PLAYBACK Hardware Devices ****
card 0: Intel [HDA Intel], device 0: CONEXANT Analog [CONEXANT Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: Intel [HDA Intel], device 1: Conexant Digital [Conexant Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: JamLab [JamLab], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: Audio [Altec Lansing XT1 - USB Audio], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
}}

{{Warning|Simply setting a {{ic|type hw}} as default card is equivalent to addressing hardware directly, which leaves the device unavailable to other applications. This method is only recommended if it is a part of a more sophisticated setup {{ic|~/.asoundrc}} or if user deliberately wants to address sound card directly (digital output through {{ic|eic958}} or dedicated music server for example).}}

For example, the last entry in this list has the card ID 2 and the device ID 0. To set this card as the default, you can either use the system-wide file {{ic|/etc/asound.conf}} or the user-specific file {{ic|~/.asoundrc}}. You may have to create the file if it does not exist. Then insert the following options with the corresponding card.
{{bc|
pcm.!default {
    type hw
    card 2
}

ctl.!default {
    type hw
    card 2
}
}}

{{Note|For the Asus U32U serie it seems that card should be set to 1 for both pcm and ctl.}}

In most cases it is recommended to use sound card names instead of number references, which also solves boot order problem. Therefore the following would be correct for the above example.
{{bc|
pcm.!default {
    type hw
    card Audio
}

ctl.!default {
    type hw
    card Audio
}
}}

To get valid ALSA card names, use ''aplay'':
{{hc|<nowiki>$ aplay -l | awk -F \: '/,/{print $2}' | awk '{print $1}' | uniq</nowiki>|
PCH
}}

Alternatively use ''cat'', which might return unused devices:
{{hc|$ cat /proc/asound/card*/id|
PCH
ThinkPadEC
}}

{{Note|This method could be problematic if your system has several cards of the same (ALSA)name.}}

The 'pcm' options affect which card and device will be used for audio playback while the 'ctl' option affects which card is used by control utilities like alsamixer .

The changes should take effect as soon as you (re-)start an application (MPlayer etc.). You can also test with a command like ''aplay''.

 $ aplay -D default ''your_favourite_sound.wav''

If you receive an error regarding your asound configuration, check the [http://www.alsa-project.org/main/index.php/Asoundrc#The_default_plugin upstream documentation] for possible changes to the config file format.

=== Verifying correct sound modules are loaded ===

You can assume that udev will autodetect your sound properly. You can check this with the command

{{hc|<nowiki>$ lsmod | grep '^snd' | column -t</nowiki>|2=
snd_hda_codec_hdmi     22378   4
snd_hda_codec_realtek  294191  1
snd_hda_intel          21738   1
snd_hda_codec          73739   3  snd_hda_codec_hdmi,snd_hda_codec_realtek,snd_hda_intel
snd_hwdep              6134    1  snd_hda_codec
snd_pcm                71032   3  snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec
snd_timer              18992   1  snd_pcm
snd                    55132   9  snd_hda_codec_hdmi,snd_hda_codec_realtek,snd_hda_intel,snd_hda_codec,snd_hwdep,snd_pcm,snd_timer
snd_page_alloc         7017    2  snd_hda_intel,snd_pcm
}}

If the output looks similar, your sound drivers have been successfully autodetected.
{{Note|Since {{ic|udev>&#61;171}}, the OSS emulation modules ({{ic|snd_seq_oss, snd_pcm_oss, snd_mixer_oss}}) are not loaded by default: [[kernel modules#Loading|Load them manually]] if they are needed.}}

You might also want to check the directory {{ic|/dev/snd/}} for the right device files:

{{hc|$ ls -l /dev/snd|2=
total 0
crw-rw----  1 root audio 116,  0 Apr  8 14:17 controlC0
crw-rw----  1 root audio 116, 32 Apr  8 14:17 controlC1
crw-rw----  1 root audio 116, 24 Apr  8 14:17 pcmC0D0c
crw-rw----  1 root audio 116, 16 Apr  8 14:17 pcmC0D0p
crw-rw----  1 root audio 116, 25 Apr  8 14:17 pcmC0D1c
crw-rw----  1 root audio 116, 56 Apr  8 14:17 pcmC1D0c
crw-rw----  1 root audio 116, 48 Apr  8 14:17 pcmC1D0p
crw-rw----  1 root audio 116,  1 Apr  8 14:17 seq
crw-rw----  1 root audio 116, 33 Apr  8 14:17 timer
}}

{{Note|If requesting help on IRC or the forums, please post the output of the above commands if requested.}}

If you have at least the devices '''controlC0''' and '''pcmC0D0p''' or similar, then your sound modules have been detected and loaded properly.

If this is not the case, your sound modules have not been detected properly. To solve this, you can try loading the modules manually:

* Locate the module for your sound card: [http://www.alsa-project.org/main/index.php/Matrix:Main ALSA Soundcard Matrix] The module will be prefixed with 'snd-' (for example: {{ic|snd-via82xx}}).
* [[Kernel modules#Loading|Load the module]].
* Check for the device files in {{ic|/dev/snd}} (see above) and/or try if {{ic|alsamixer}} or {{ic|amixer}} have reasonable output.
* Configure {{ic|snd-NAME-OF-MODULE}} and {{ic|snd-pcm-oss}} to [[Kernel modules#Loading|load at boot]].

=== Getting S/PDIF output ===
[[wikipedia:S/PDIF|S/PDIF]] is a digital audio interface often used to connect a computer to a digital amplifier (such as a home theatre with 5.1/7.1 surround sound). 
{{note|With some soundcards this disables analog sound output  (eg. Audigy2).}}
Depending on what [[shell]] you use, add the following line to your shell's configuration file:
 amixer -c 0 cset name='IEC958 Playback Switch' on

You can see the name of your card's digital output with:
 $ amixer scontrols

=== System-wide equalizer ===

==== Using ALSAEqual (provides UI) ====

Install the {{AUR|alsaequal}} package from the [[Arch User Repository]].

{{Note|If you have a x86_64-system and are using a 32bit-flashplugin the sound in flash will not work. You have to disable alsaequal or build alsaequal for 32bit.}}

After installing the package, add the following to your ALSA configuration file:

{{hc|/etc/asound.conf|2=
ctl.equal {
    type equal;
}

pcm.plugequal {
    type equal;
    # Modify the line below if you do not
    # want to use sound card 0.
    #slave.pcm "plughw:0,0";
    # by default we want to play from more sources at time:
    slave.pcm "plug:dmix";
}

# pcm.equal {
# If you do not want the equalizer to be your
# default soundcard comment the following
# line and uncomment the above line. (You can
# choose it as the output device by addressing
# it with specific apps,eg mpg123 -a equal 06.Back_In_Black.mp3)
pcm.!default {
    type plug;
    slave.pcm plugequal;
}
}}

And you are ready to change your equalizer using command
 $ alsamixer -D equal

Note that configuration file is different for each user (until not specified else) it is saved in {{ic|~/.alsaequal.bin}}.
so if you want to use ALSAEqual with [[mpd]] or another software running under different user, you can configure it using
 $ su mpd -c 'alsamixer -D equal'
or for example, you can make a symlink to your {{ic|.alsaequal.bin}} in his home...

===== Managing ALSAEqual states =====

Install {{AUR|alsaequal-mgr}} from the [[Arch User Repository]].

Configure the equalizer as usual with
 $ alsamixer -D equal

When you are satisfied with the state, you may give it a name ("foo" in this example) and save it:
 $ alsaequal-mgr save foo

The state "foo" can then be restored at a later time with
 $ alsaequal-mgr load foo

You can thus create different equalizer states for games, movies, music genres, VoIP apps, etc. and reload them as necessary.

See the [http://xyne.archlinux.ca/projects/alsaequal-mgr/ project page] and the help message for more options.

==== Using mbeq ====

{{Note|This method requires the use of a [[Wikipedia:LADSPA|LADSPA]] plugin which might be CPU intensive during playback. In addition, this was made with stereophonic sound (e.g. headphones) in mind.}}

Install the {{Pkg|alsa-plugins}}, {{Pkg|ladspa}} and {{Pkg|swh-plugins}} packages if you do not already have them.

If you have not already created either an {{ic|~/.asoundrc}} or a {{ic|/etc/asound.conf}} file, then create either one and insert the following:

{{hc|/etc/asound.conf|2=
pcm.eq {
    type ladspa

    # The output from the EQ can either go direct to a hardware device
    # (if you have a hardware mixer, e.g. SBLive/Audigy) or it can go
    # to the software mixer shown here.
    #slave.pcm "plughw:0,0"
    slave.pcm "plug:dmix"

    # Sometimes you may need to specify the path to the plugins,
    # especially if you have just installed them.  Once you have logged
    # out/restarted this should not be necessary, but if you get errors
    # about being unable to find plugins, try uncommenting this.
    #path "/usr/lib/ladspa"

    plugins [
    {
        label mbeq
        id 1197
        input {
            # The following setting is just an example, edit to your own taste:
            # bands: 50hz, 100hz, 156hz, 220hz, 311hz, 440hz, 622hz, 880hz, 1250hz, 1750hz, 25000hz,
            # 50000hz, 10000hz, 20000hz
            controls [ -5 -5 -5 -5 -5 -10 -20 -15 -10 -10 -10 -10 -10 -3 -2 ]
            }
        }
    ]
}

# Redirect the default device to go via the EQ - you may want to do
# this last, once you are sure everything is working.  Otherwise all
# your audio programs will break/crash if something has gone wrong.
pcm.!default {
    type plug
    slave.pcm "eq"
}

# Redirect the OSS emulation through the EQ too (when programs are running through "aoss")
pcm.dsp0 {
    type plug
    slave.pcm "eq"
}
}}

== High quality resampling ==

When software mixing is enabled, ALSA is forced to resample everything to the same frequency (48 kHz by default when supported). By default, it will try to use the ''speexrate'' converter to do so, and fallback to low-quality linear interpolation if it is not available[http://git.alsa-project.org/?p=alsa-lib.git;a=blob;f=src/pcm/pcm_rate.c;h=2eb4b1b33933dec878d0f25ad118869adac95767;hb=HEAD#l1278].
Thus, if you are getting poor sound quality due to bad resampling, the problem can be solved by simply installing {{Pkg|alsa-plugins}}.

For even higher quality resampling, you can change the default rate converter to {{ic|speexrate_medium}} or {{ic|speexrate_best}}. Both perform well enough that in practice it does not matter which one you choose, so using the best converter is usually not worth the extra CPU cycles it requires.

To change the default converter place the following contents in your {{ic|~/.asoundrc}} or {{ic|/etc/asound.conf}}:

{{hc|/etc/asound.conf|
defaults.pcm.rate_converter "speexrate_medium"
}}

{{note|It is also possible to use {{Pkg|libsamplerate}} converters, which are only about half as fast as the ''speexrate'' converters but do not achieve much greater performance. See [[Talk:Advanced_Linux_Sound_Architecture#On_high_quality_resampling|discussion]].}}
{{note|Some applications (like MPlayer and its forks) do their own resampling by default because some ALSA drivers have incorrect delay reporting when resampling is enabled (hence leading to AV desynchronization), so changing this setting will not have any effect unless you configure them to use ALSA resampling.}}

== Upmixing/downmixing ==

=== Upmixing ===

In order for stereo sources like music to be able to saturate a 5.1 or 7.1 sound system, you need to use upmixing. In darker days this used to be tricky and error prone but nowadays plugins exist to easily take care of this task. We will use the {{ic|upmix}} plugin, included in {{Pkg|alsa-plugins}}.

Then add the following to your ALSA configuration file of choice (either {{ic|/etc/asound.conf}} or {{ic|~/.asoundrc}}):

{{bc|
pcm.upmix71 {
    type upmix
    slave.pcm "surround71"
    delay 15
    channels 8
}
}}

You can easily change this example for 7.1 upmixing to 5.1 or 4.0.

The following example adds a new PCM channel that you can use for upmixing. If you want all sound sources to go through this channel, add it as a default below the previous definition like so:

 pcm.!default "plug:upmix71"

The plugin automatically allows multiple sources to play through it without problems so setting is as a default is actually a safe choice.
If this is not working, you have to setup your own dmixer for the upmixing PCM like this:
{{bc|1=
pcm.dmix6 {
    type asym
    playback.pcm {
        type dmix
        ipc_key 567829
        slave {
            pcm "hw:0,0"
            channels 6
        }
    }
}

}}

and use "dmix6" instead of "surround71".
If you experience skipping or distorted sound, consider increasing the buffer_size (to 32768, for example) or use a [[#High quality resampling|high quality resampler]].

=== Downmixing ===

If you want to downmix sources to stereo because you, for instance, want to watch a movie with 5.1 sound on a stereo system, use the {{ic|vdownmix}} plugin, included in {{Pkg|alsa-plugins}}..

Again, in your configuration file, add this:

{{bc|1=
pcm.!surround51 {
    type vdownmix
    slave.pcm "default"
}
pcm.!surround40 {
    type vdownmix
    slave.pcm "default"
}
}}

{{Note|1=This might not be enough to make downmixing working, see [http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=541786]. So, you might also need to add {{ic|pcm.!default "plug:surround51"}} or {{ic|pcm.!default "plug:surround40"}}. Only one {{ic|vdownmix}} plug can be used; if you have 7.1 channels, you will need to use {{ic|surround71}} instead the configuration above. A good example, which includes a configuration that makes both {{ic|vdownmix}} and {{ic|dmix}} working, can be found [https://bbs.archlinux.org/viewtopic.php?id=167275 here].}}

== Dmix ==

Mixing enables multiple applications to output sound at the same time. Most discrete sound cards support hardware mixing, which is enabled by default if available. Integrated motherboard sound cards (such as Intel HD Audio), usually do not support hardware mixing. On such cards, software mixing is done by an ALSA plugin called {{ic|dmix}}. This feature is enabled automatically if hardware mixing is unavailable.

{{Note|Dmix is enabled by default for soundcards which do not support hardware mixing. Dmix is not enabled by default for digital output (S/PDIF) and will require the configuration snippet below.}}

To manually enable dmix, add the following to your ALSA configuration file:

{{hc|/etc/asound.conf|2=
pcm.dsp {
    type plug
    slave.pcm "dmix"
}
}}

== Troubleshooting ==

{{Moveto|Advanced Linux Sound Architecture/Troubleshooting|Long enough to live on its own.|section=Split up article into Main/Troubleshoot sections and reorganize Troubleshooting}}

=== No sound in VirtualBox ===

If you experience problems with VirtualBox, the following command might be helpful:

{{hc|$ alsactl init|2=
Found hardware: "ICH" "SigmaTel STAC9700,83,84" "AC97a:83847600" "0x8086" "0x0000"
Hardware is initialized using a generic method
}}

You might need to activate the ALSA output in your audio software as well.

=== Sound skipping while using dynamic CPU frequency scaling ===

Some combinations of ALSA drivers and chipsets may cause audio from all sources to skip when used in combination with a dynamic frequency scaling governor such as {{ic|ondemand}} or {{ic|conservative}}. Currently, the solution is to switch back to the {{ic|performance}} governor.

Refer to the [[CPU frequency scaling]] for more information.

=== Problems with availability to only one user at a time ===

You might find that only one user can use the dmixer at a time.  This is probably ok for most, but for those who run [[mpd]] as a separate user this poses a problem.  When mpd is playing a normal user cannot play sounds though the dmixer.  While it is quite possible to just run mpd under a user's login account, another solution has been found.  Adding the line {{ic|ipc_key_add_uid 0}} to the {{ic|pcm.dmixer}} block disables this locking.  The following is a snippet from {{ic|asound.conf}}, the rest is the same as above.

{{bc|1=
...
pcm.dmixer {
    type dmix
    ipc_key 1024
    ipc_key_add_uid 0
    ipc_perm 0660
slave {
 ...
}}

=== Simultaneous playback problems ===

If you are having problems with simultaneous playback, and if [[PulseAudio]] is installed, its default configuration is set to "hijack" the soundcard. Some users of ALSA may not want to use [[PulseAudio]] and are quite content with their current ALSA settings. One fix is to edit {{ic|/etc/asound.conf}} and comment out the following lines:
{{bc|1=
# Use PulseAudio by default
pcm.!default {
    type pulse
    fallback "sysdefault"
    hint {
        show on
        description "Default ALSA Output (currently PulseAudio Sound Server)"
    }
}
}}

Commenting the following out also may help:
{{bc|1=
ctl.!default {
    type pulse
    fallback "sysdefault"
}
}}

This may be a much simpler solution than completely uninstalling [[PulseAudio]].

Effectively, here is an example of a working {{ic|/etc/asound.conf}}:
{{bc|1=
pcm.dmixer {
    type dmix
    ipc_key 1024
    ipc_key_add_uid 0
    ipc_perm 0660
}
pcm.dsp {
    type plug
    slave.pcm "dmix"
}
}}

{{Note|This {{ic|/etc/asound.conf}} file was intended for and used successfully with a global [[MPD]] configuration. See [[ALSA#Problems with availability to only one user at a time|this section]] on multiple users}}

=== Random lack of sound on startup ===

You can quickly test sound by running {{ic|speaker-test}}. If there is no sound, the error message might look something like

  ALSA lib pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave
  Playback open error: -16
  Device or resource busy

If you have no sound on startup, this may be because your system has multiple sound cards, and their order may sometimes change on startup.  If this is the case, try [[#Set the default sound card|setting the default sound card]].

If you use mpd and the configuration tips above do not work for you, try [http://mpd.wikia.com/wiki/Configuration#ALSA_MPD_software_volume_control reading this] instead.

==== Timidity ====

[[Timidity]] can be the cause of missing audio. Try running:

 $ systemctl status timidity

If it failed, try {{ic|# killall -9 timidity}}. If this solves the issue, then you should disable the timidity daemon to be started at boot.

=== Specific program problems ===

For other programs who insist on their own audio setup, e.g., XMMS or MPlayer, you would need to set their specific options.

For [[MPlayer]] or [[mpv]], add the following line to the respective configuration file:
 ao=alsa

For XMMS2, go into their options and make sure the sound driver is set to ALSA, not oss.

To do this in XMMS:
* Open XMMS
** Options > Preferences.
** Choose the ALSA output plugin.

For applications which do not provide a ALSA output, you can use aoss from the alsa-oss package. To use aoss, when you run the program, prefix it with {{ic|aoss}}, e.g.:
 aoss realplay

pcm.!default{ ... }  doesnt work for me anymore. but this does:
 pcm.default pcm.dmixer

=== Model settings ===

Although ALSA detects your soundcard through the BIOS, at times ALSA may not be able to recognize your [http://www.kernel.org/doc/Documentation/sound/alsa/HD-Audio-Models.txt model type].  The soundcard chip can be found in {{ic|alsamixer}} (e.g. ALC662) and the model can be set in {{ic|/etc/modprobe.d/modprobe.conf}} or {{ic|/etc/modprobe.d/sound.conf}}.  For example:

 options snd-hda-intel model=MODEL

There are other model settings too.  For most cases ALSA defaults will do.  If you want to look at more specific settings for your soundcard take a look at the [http://bugtrack.alsa-project.org/main/index.php/Matrix:Main ALSA Soundcard List] find your model, then Details, then look at the "Setting up modprobe..." section.  Enter these values in {{ic|/etc/modprobe.d/modprobe.conf}}.  For example, for an Intel AC97 audio:

{{bc|
# ALSA portion
alias char-major-116 snd
alias snd-card-0 snd-intel8x0
# module options should go here

# OSS/Free portion
alias char-major-14 soundcore
alias sound-slot-0 snd-card-0

# card #1
alias sound-service-0-0 snd-mixer-oss
alias sound-service-0-1 snd-seq-oss
alias sound-service-0-3 snd-pcm-oss
alias sound-service-0-8 snd-seq-oss
alias sound-service-0-12 snd-pcm-oss
}}

=== Conflicting PC speaker ===

If you are sure nothing is muted, that your drivers are installed correctly, and that your volume is right, but you still do not hear anything, then try adding the following line to {{ic|/etc/modprobe.d/modprobe.conf}}:

 options snd-NAME-OF-MODULE ac97_quirk=0

The above fix has been observed to work with {{ic|via82xx}}
 options snd-NAME-OF-MODULE ac97_quirk=1
The above fix has been reported to work with {{ic|snd-intel8x0}}

{{Poor writing|Duplicated sections (e.g. for microphone) should be merged with eachother}}

=== No microphone input ===

In alsamixer, make sure that all the volume levels are up under recording, and that CAPTURE is toggled active on the microphone (e.g. Mic, Internal Mic) and/or on Capture (in alsamixer, select these items and press space). Try making positive Mic Boost and raising Capture and Digital levels higher; this make make static or distortion, but then you can adjust them back down once you are hearing ''something'' when you record

As the pulseaudio wrapper is shown as "default" in alsamixer, you may have to press F6 to select your actual soundcard first. You may also need to enable and increase the volume of Line-in in the Playback section.

To test the microphone, run these commands (see arecord's man page for further information):
 $ arecord -d 5 test-mic.wav
 $ aplay test-mic.wav

If all fails, you may want to eliminate hardware failure by testing the microphone with a different device.

For at least some computers, muting a microphone (MM) simply means its input does not go immediately to the speakers. It still receives input.

Many Dell laptops need "-dmic" to be appended to the model name in {{ic|/etc/modprobe.d/modprobe.conf}}:
  options snd-hda-intel model=dell-m6-dmic

Some programs use try to use OSS as the main input software. If you have enabled the {{ic|snd_pcm_oss}}, {{ic|snd_mixer_oss}} or {{ic|snd_seq_oss}} [[kernel modules]] previously (they are not loaded by default), try unloading them.

See also:
* http://www.alsa-project.org/main/index.php/SoundcardTesting
* http://alsa.opensrc.org/Record_from_mic

=== Crackling in microphone ===

If you are getting a crackling or popping from your microphone that cannot be resolved with ALSA settings or cleaning your microphone jack, try adding the following line to {{ic|/etc/modprobe.d/modprobe.conf}}:

 options snd-hda-intel model=MODEL position_fix=3

This option will fix crackling on pure ALSA, but will cause issues to pulseaudio. To let Pulse use these settings effectively, edit {{ic|/etc/pulse/default.pa}} and find this line:

 load-module module-udev-detect

And change it to this:

 load-module module-udev-detect tsched=0

See the DMA-Position Problem in the kernel docs.

* [https://www.kernel.org/doc/Documentation/sound/alsa/HD-Audio.txt HD-audio Kernel Docs]

=== Setting the default microphone/capture device ===

Some applications (Pidgin, Adobe Flash) do not provide an option to change the capture device. It becomes a problem if your microphone is on a separate device (e.g. USB webcam or microphone) than your internal sound card. To change only the default capture device, leaving the default playback device as is, you can modify your {{ic|~/.asoundrc}} file to include the following:

{{bc|
pcm.usb
{
    type hw
    card U0x46d0x81d
}

pcm.!default
{
    type asym
    playback.pcm
    {
        type plug
        slave.pcm "dmix"
    }
    capture.pcm
    {
        type plug
        slave.pcm "usb"
    }
}
}}

Replace "U0x46d0x81d" with your capture device's card name in ALSA. You can use {{ic|arecord -L}} to list all the capture devices detected by ALSA.

=== Internal microphone not working ===

First make sure the volume is enabled under the {{ic|Capture}} view in ''alsamixer''. Add the following to {{ic|/etc/modprobe.d/snd-hda-intel.conf}}:

 options snd-hda-intel enable_msi=1

Then reload the module:

 # rmmod snd-hda-intel && modprobe snd-hda-intel

Now there should be an additional input under the previously mentioned {{ic|Capture}} view.

=== No sound with onboard Intel sound card ===

There may be a problem with two conflicting modules loaded, namely {{ic|snd-intel8x0}} and {{ic|snd-intel8x0m}}. In this case, blacklist snd-intel8x0m:

{{hc|/etc/modprobe.d/modprobe.conf|blacklist snd-intel8x0m}}

''Muting'' the "External Amplifier" in {{ic|alsamixer}} or {{ic|amixer}} may also help. See [http://alsa.opensrc.org/Intel8x0#Dell_Inspiron_8600_.28and_probably_others.29 the ALSA wiki].

Unmuting the "Mix" setting in the mixer might help, also.

=== No headphone sound with onboard Intel sound card ===

With '''Intel Corporation 82801 I (ICH9 Family) HD Audio Controller''' on laptop, you may need to add this line to modprobe or sound.conf:

 options snd-hda-intel model=''model''

Where ''model'' is any one of the following:

* dell-m6
* dell-vostro
* generic
* laptop
* laptop-hpsense
* olpc-xo-1_5

{{Note|It may be necessary to put this "options" line below (after) any "alias" lines about your card.}}

You can see all the available models in the kernel documentation. For example [http://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/Documentation/sound/alsa/HD-Audio-Models.txt here], but check that it is the correct version of that document for your kernel version.

A list of available models is also available [http://www.mjmwired.net/kernel/Documentation/sound/alsa/HD-Audio-Models.txt here]. To know your chip name type the following command (with * being corrected to match your files). Note that some chips could have been renamed and do not directly match the available ones in the file.

 $ grep Codec /proc/asound/card*/codec*

Note that there is a high chance none of the input devices (all internal and external mics) will work if you choose to do this, so it is either your headphones or your mic. Please report to ALSA if you are affected by this bug.

And also, if you have problems getting beeps to work (pcspkr):

 options snd-hda-intel model=$model enable=1 index=0

=== No sound when S/PDIF video card is installed ===

Discover available modules and their order:

{{hc|$ cat /proc/asound/modules|
 0 snd_hda_intel
 1 snd_ca0106
}}

Disable the undesired video card audio codec in {{ic|/etc/modprobe.d/modprobe.conf}}:

{{hc|/etc/modprobe.d/modprobe.conf|
install snd_hda_intel /bin/false
}}

If both devices use the same module then we can use the {{ic|enable}} parameter from snd-hda-intel module; it is an array of booleans that can enable/disable the desired sound card.

 options snd-hda-intel enable=1,0

=== Poor sound quality or clipping ===

If you experience poor sound quality, try setting the PCM volume (in alsamixer) to a level such that gain is 0.

If snd-usb-audio driver has been loaded, you could try to enable {{ic|softvol}} in {{ic|/etc/asound.conf}} file. Example configuration for the first audio device:

{{bc|1=
pcm.!default {
    type plug
    slave.pcm "softvol"
}
pcm.dmixer {
    type dmix
    ipc_key 1024
    slave {
        pcm "hw:0"
        period_size 4096
        buffer_size 131072
        rate 50000
    }
    bindings {
        0 0
        1 1
    }
}
pcm.dsnooper {
    type dsnoop
    ipc_key 1024
    slave {
        pcm "hw:0"
        channels 2
        period_size 4096
        buffer_size 131072
        rate 50000
    }
    bindings {
        0 0
        1 1
        }
}
pcm.softvol {
  type softvol
  slave { pcm "dmixer" }
  control {
    name "Master"
    card 0
  }
}
ctl.!default {
  type hw
  card 0
}
ctl.softvol {
  type hw
  card 0
}
ctl.dmixer {
  type hw
  card 0
}
}}

=== Pops when starting and stopping playback===

Some modules (e.g. snd_ac97_codec and snd_hda_intel) can power off your sound card when not in use. This can make an audible noise (like a crack/pop/scratch) when turning on/off your sound card. Sometimes even when move the slider volume, or open and close windows (KDE4). If you find this annoying try {{ic|modinfo snd_MY_MODULE}}, and look for a module option that adjusts or disables this feature.

''Example'': disable the power saving mode and solve cracking sound trough speakers problem, using snd_hda_intel add in {{ic|/etc/modprobe.d/modprobe.conf}}:
 options snd_hda_intel power_save=0
or:
 options snd_hda_intel power_save=0 power_save_controller=N

You can also try it with {{ic|1=modprobe snd_hda_intel power_save=0}} before.

You may also have to unmute the 'Line' ALSA channel for this to work. Any value will do (other than '0' or something too high).

''Example:'' on an onboard VIA VT1708S (using the snd_hda_intel module) these cracks occured even though 'power_save' was set to 0. Unmuting the 'Line' channel and setting a value of '1' solved the problem.

Source: https://www.kernel.org/doc/Documentation/sound/alsa/powersave.txt

If you use a laptop, pm-utils will change {{ic|power_save}} back to 1 when you go onto battery power even if you disable power saving in {{ic|/etc/modprobe.d}}. Disable this for pm-utils by disabling the script that makes the change (see [[Pm-utils#Disabling_a_hook|Disabling a hook]] for more information):
 # touch /etc/pm/power.d/intel-audio-powersave

=== S/PDIF output does not work ===

If the optical/coaxial digital output of your motherboard/sound card is not working or stopped working, and have already enabled and unmuted it in alsamixer, try running the following:
 $ iecset audio on

You can also put this command in an enabled [[systemd]] service as it sometimes it may stop working after a reboot.

=== HDMI ===

==== Output does not work ====

The procedure described below can be used to test HDMI audio. Before proceeding, make sure you have enabled and unmuted the output with {{ic|alsamixer}}.

{{Note|If you are using an AMD card a necessary kernel module is disabled by default. See [[ATI#HDMI_audio]].}}

Connect your PC to the Display via HDMI cable and enable the display with [[xrandr]].

Use {{ic|aplay -l}} to get the discover the card and device number. For example:

{{hc|$ aplay -l|2=
**** List of PLAYBACK Hardware Devices ****
card 0: SB [HDA ATI SB], device 0: ALC892 Analog [ALC892 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: SB [HDA ATI SB], device 1: ALC892 Digital [ALC892 Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
'''card 1''': Generic [HD-Audio Generic], '''device 3''': HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
}}

Send sound to the device. Following the example in the previous step, you would send sound to {{ic|'''card 1'''}}, {{ic|'''device 3'''}}:

 $ aplay -D plughw:1,3 /usr/share/sounds/alsa/Front_Center.wav

If aplay does not output any errors, but still no sound is heared, "reboot" the receiver, monitor or tv set. Since the HDMI interface executes a handshake on connection, it might have noticed before that there was no audio stream embedded, and disabled audio decoding. If you are using a standalone window manager, you may need to have sound playing while plugging in the HDMI cable.

mplay and other application could be configured to use special HDMI device as audio output. But flashplugin could only use default device. The following method is used to override default device. But you need to change it back when your TV is disconnected from HDMI port.

If the test is successful, create or edit your {{ic|~/.asoundrc}} file to set HDMI as the default audio device.

{{hc|~/.asoundrc|
pcm.!default {
    type hw
    card 0
    device 3
}
}}

Or if the above configuration does not work try:

{{hc|~/.asoundrc|
defaults.pcm.card 0
defaults.pcm.device 3
defaults.ctl.card 0
}}

==== Multi-channel PCM output does not work (Intel) ====

As of Linux 3.1 multi-channel PCM output through HDMI with a Intel card (Intel Eaglelake, IbexPeak/Ironlake,SandyBridge/CougarPoint and IvyBridge/PantherPoint) is not yet supported. Support for it has been recently added and expected to be available in Linux 3.2. To make it work in Linux 3.1 you need to apply the following patches:

* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=patch;h=76adaa34db407f174dd06370cb60f6029c33b465 drm: support routines for HDMI/DP ELD]
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=patch;h=e0dac65ed45e72fe34cc7ccc76de0ba220bd38bb drm/i915: pass ELD to HDMI/DP audio driver]

==== 5.1 sound goes to wrong speakers ====

Sound can be redirected to the intended speakers using ALSA's {{ic|remap}} function. To do so, add the following to {{ic|/etc/asound.conf}}:

{{bc|1=
pcm.!hdmi-remap {
    type asym
    playback.pcm {
        type plug
        slave.pcm "remap-surround51"
    }
}

pcm.!remap-surround51 {
    type route
    slave.pcm "hw:0,3"
    ttable {
        0.0= 1
        1.1= 1
        2.4= 1
        3.5= 1
        4.2= 1
        5.3= 1
    }
}
}}

=== HP TX2500 ===

Add these 2 lines into {{ic|/etc/modprobe.d/modprobe.conf}}:
 options snd-cmipci mpu_port=0x330 fm_port=0x388
 options snd-hda-intel index=0 model=toshiba position_fix=1

 options snd-hda-intel model=hp (works for tx2000cto)

=== Sound skipping during playback ===

Run ''alsamixer'', and if channels exist for nonexistent output devices then disable them (e.g. ''alsamixer'' showing a center speaker but you not having one).

=== Crackling sound with USB devices ===

Try modifying the parameters of the {{ic|snd-usb-audio}} [[kernel_module]] for minimal latency via {{ic|modprobe.conf}}.

{{hc|/etc/modprobe.d/modprobe.conf|2=
options snd-usb-audio nrpacks=1}}

For more information, see the following: [http://alsa.opensrc.org/Usb-audio#Tuning_USB_devices_for_minimal_latencies Tuning USB devices for minimal latency]

=== Error 'Unknown hardware' appears after a kernel update===

The following messages may be displayed during ALSA's initialization:
 Unknown hardware "foo" "bar" ...
 Hardware is initialized using a guess method
 /usr/bin/alsactl: set_control:nnnn:failed to obtain info for control #mm (No such file or directory)

or:
 Found hardware: "HDA-Intel" "VIA VT1705" "HDA:11064397,18490397,00100000" "0x1849" "0x0397"
 Hardware is initialized using a generic method
 /usr/bin/alsactl: set_control:1328: failed to obtain info for control #1 (No such file or directory)
 /usr/bin/alsactl: set_control:1328: failed to obtain info for control #2 (No such file or directory)
 /usr/bin/alsactl: set_control:1328: failed to obtain info for control #25 (No such file or directory)
 /usr/bin/alsactl: set_control:1328: failed to obtain info for control #26 (No such file or directory)

Simply store ALSA mixer settings again:
 # alsactl -f /var/lib/alsa/asound.state store

It may be necessary configure ALSA again with alsamixer

=== HDA analyzer ===

If the mappings to your audio pins(plugs) do not correspond but ALSA works fine, you could try HDA Analyzer -- a pyGTK2 GUI for HD-audio control can be found [http://www.alsa-project.org/main/index.php/HDA_Analyzer at the ALSA wiki].
Try tweaking the Widget Control section of the PIN nodes, to make microphones IN and headphone jacks OUT. Referring to the Config Defaults heading is a good idea.

{{Note|The script is incompatible with Python 3, which is the default Python implementation on Arch Linux. In order to use the script, replace all occurrences of {{ic|python}} in the {{ic|run.py}} file with {{ic|python2}} to point the script to the Python 2 version. Then make the script [[chmod|executable]] and run it.}}

=== No sound with SDL ===

If you get no sound using SDL based applications, try setting the [[environment variable]] {{ic|SDL_AUDIODRIVER}} to {{ic|alsa}}.

=== Low sound workaround ===

If you are facing low sound even after maxing out your speakers/headphones, you can give the softvol plugin a try. Add the following to {{ic|/etc/asound.conf}}.
{{bc|1=
pcm.!default {
    type plug
    slave.pcm "softvol"
}

pcm.softvol {
    type softvol
    slave {
        pcm "dmix"
    }
    control {
        name "Pre-Amp"
        card 0
    }
    min_dB -5.0
    max_dB 20.0
    resolution 6
}
}}

{{Note|You will probably have to restart the computer, as restarting the alsa daemon did not load the new configuration for me. Also, if the configuration does not work even after restarting, try changing {{ic|plug}} with {{ic|hw}} in the above configuration.}}

After the changes are loaded successfully, you will see a {{ic|Pre-Amp}} section in alsamixer. You can adjust the levels there.
{{Note|
* Setting a high value for {{ic|Pre-Amp}} can cause sound distortion, so adjust it according to the level that suits you.
* Some audio codecs may need to have settings adjusted in the HDA Analyzer ([[#HDA analyzer|see above]]) in order to achieve proper volume without distortion. Checking the HP option under widget control in the Playback Switch (Node[0x14] PIN in the ALC892 codec, for instance) can sometimes improve audio quality and volume significantly.
}}

=== Popping sound after resuming from suspension ===

You might hear a popping sound after resuming the computer from suspension. This can be fixed by editing {{ic|/etc/pm/sleep.d/90alsa}} and removing the line that says {{ic|aplay -d 1 /dev/zero}}

=== Output is muted after reboot ===

Run the following command:

 # alsactl restore

If the problem persists, verify that the {{ic|Auto-Mute}} option in ''alsamixer'' is set to {{ic|Disabled}}.

=== Volume is too low ===

Run ''|alsamixer'' and try to increase the value of the sliders, unmuting channels if necessary. Note that if you have many sliders, you may have to scroll to the right to see any missing sliders.

If all the sliders are maxed out, and the volume is still too low, you can try running the script at http://www.alsa-project.org/hda-analyzer.py to reset your codec settings:

 $ wget http://www.alsa-project.org/hda-analyzer.py
 $ su -c 'python2 hda-analyzer.py'

The script assumes the {{ic|python}} binary refers to Python 2, which is incorrect on Arch by default. To avoid this issue run the following command:

 $ sed -i 's/python %s/python2 %s/' hda-analyzer_run.py

Close the analyzer, and when prompted as to whether you want to reset the codecs, say "yes".

If the volume is *still* too low, run {{ic|alsamixer}} again: resetting the codecs may have caused new sliders to become enabled, and some of them may be set to a low value.

=== Verifying output parameters ===

Check the contents of {{ic|/proc/asound/cardX/pcmYp/subZ/hw_params}}, where {{ic|X}}, {{ic|Y}}, and {{ic|Z}} are system dependent.
In order to find this file, execute the following command while outputting anything via ALSA:
 $ find /proc/asound/ -name hw_params | xargs -I FILE grep -v -l "closed" FILE | grep '/proc/asound/card./pcm.p/sub./hw_params'
If nothing is playing there should be no results.

Here is an example output for audio with a [[Wikipedia:Audio_bit_depth|bit depth]] of 24 bits and a [[Wikipedia:Sampling frequency|sampling frequency]] of 44.1 kilohertz:
{{hc|cat /proc/asound/card1/pcm0p/sub0/hw_params|
access: RW_INTERLEAVED
format: S24_3LE
subformat: STD
channels: 2
rate: 44100 (44100/1)
period_size: 5513
buffer_size: 22050
}}

More info is available in the [http://alsa.opensrc.org/Proc_asound_documentation ALSA documentation].

=== Removing old ALSA state file (asound.state) ===

The {{Pkg|alsa-utils}} package provides {{ic|alsa-store.service}} which automatically stores the current ALSA state to {{ic|/var/lib/alsa/asound.state}} upon system shutdown.  This can be problematic for users who are trying to reset their current ALSA state as the {{ic|asound.state}} file will be recreated with the current state upon every shutdown (e.g., attempting to remove user-defined channels from the mixer).  The {{ic|alsa-store.service}} service may be temporarily disabled by creating the following empty file:

 # mkdir -p /etc/alsa
 # touch /etc/alsa/state-daemon.conf

The presence of {{ic|state-daemon.conf}} prevents {{ic|alsa-store.service}} from saving {{ic|asound.state}} during shutdown. After disabling this service, the {{ic|asound.state}} file may be removed as such:

 # rm /var/lib/alsa/asound.state

After rebooting, the previous ALSA state should be lost and the current state should be reset to defaults.  Re-enable {{ic|alsa-store.service}} by deleting the condition file we created:

 # rm /etc/alsa/state-daemon.conf

On the next shutdown, the {{ic|asound.state}} file should be recreated with ALSA defaults.  The file may also be generated immediately using:

 # alsactl store

=== No sound in applications that use OpenAL ===

OpenAL defaults to pulseaudio, to change the order, add the following configuration to {{ic|/etc/openal/alsoft.conf}}:

{{bc|1=
drivers=alsa,pulse
}}

== Tips and tricks ==

=== Hot-plugging a USB sound card ===

The following [[udev]] rule can be used to automatically make a USB sound card the primary output device when the card is plugged in. To do so, create the following file with the specified contents and.

{{hc|/etc/udev/rules.d/00-local.rules|2=
KERNEL=="pcmC[D0-9cp]*", ACTION=="add", PROGRAM="/usr/bin/sh -c 'K=%k; K=$${K#pcmC}; K=$${K%%D*}; echo defaults.ctl.card $$K > /etc/asound.conf; echo defaults.pcm.card $$K >>/etc/asound.conf'"
KERNEL=="pcmC[D0-9cp]*", ACTION=="remove", PROGRAM="/usr/bin/sh -c 'echo defaults.ctl.card 0 > /etc/asound.conf; echo defaults.pcm.card 0 >>/etc/asound.conf'"}}

For information regarding loading udev rules see the following: [[Udev#Loading_new_rules]]

== See also ==

* [http://www.alsa-project.org/ ALSA wiki]
* [http://alsa.opensrc.org/ Unofficial ALSA wiki]
* [http://www.mjmwired.net/kernel/Documentation/sound/alsa/ALSA-Configuration.txt Advanced ALSA module configuration]
* [https://bbs.archlinux.org/viewtopic.php?id=36815 HOWTO: compile driver from svn]
* [http://www.volkerschatz.com/noise/alsa.html A close look at ALSA: ALSA concept introduction]
* [http://www.sabi.co.uk/Notes/linuxSoundALSA.html Linux ALSA sound notes]