summaryrefslogtreecommitdiff
blob: e0f0d3ae5d97fa7658ecd4f82929ac48c9e7d407 (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
<?xml version='1.0' encoding="UTF-8"?>
<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/tw/Attic/alsa-guide.xml,v 1.6 2004/02/10 03:53:08 bennyc Exp $ -->
<!-- Sync with rev 1.24-->
<!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
<guide link="/doc/tw/alsa-guide.xml">
<title>Gentoo Linux ALSA 指南</title>
<author title="Author">
  <mail link="zu@pandora.be">Vincent Verleye</mail>
</author>
<author title="Author">
  <mail link="g2boojum@gentoo.org">Grant Goodyear</mail>
</author>
<author title="Author">
  <mail link="agenkin@gentoo.org">Arcady Genkin</mail>
</author>
<author title="Editor"><!-- zhen@gentoo.org -->
  John P. Davis
</author>
<author title="Editor">
  <mail link="swift@gentoo.org">Sven Vermeulen</mail>
</author>
<author title="Editor,Translator,Reviewer">
  <mail link="bennyc@gentoo.org">Benny Chuang</mail>
</author>
<author title="Editor">
  <mail link="blubber@gentoo.org">Tiemo Kieft</mail>
</author>
<author title="Translator">
  <mail link="palatis@gentoo.org.tw">【Palatis】</mail>
</author>
<author title="Reviewer">
  <mail link="bennyc@gentoo.org">Benny Chuang</mail>
</author>

<license/>

<abstract>
這篇文章交您怎樣在 Gentoo Linux 上設定 Advanced Linux Sound Architecture (進階 
Linux 音效架構)。給讀過 Gentoo Linux 桌面系統設定指南的讀者,這篇指南是希望能給
您更進一步有關 ALSA 的資訊。
</abstract>

<version>1.3.5</version>
<date>2003年12月31日</date>

<chapter>
<title>介紹</title>
<section>
<title>什麼是 ALSA?</title>
<body>

<p>
ALSA (Advanced Linux Sound Architecture - 進階 Linux 音效架構) 是個透過重寫程式
碼來增進 Linux 音效子系統的計畫。我們預計在準備好後 ALSA 將整合進 Linux 核心 
2.6.x (或 3.x.x,看那個先出來)。
</p>

<p>
ALSA  Linux 提供聲音以及 MIDI 功能!
</p>

<p>
根據 <uri>http://www.alsa-project.org</uri> 所言,ALSA 擁有底下的特色:
</p>

<ul>
  <li>有效的支援所有種類的音效介面,從消費性音效卡至專業多聲道音效介面。</li>
  <li>完全模組化的音效驅動程式。</li>
  <li>SMP 以及安全執行緒設計</li>
  <li>
    使用者級的函式庫 (alsa-lib) 讓撰寫應用程式變簡單,也提供更高級的功能。
  </li>
  <li>支援較早的 OSS API,提供大部份的 OSS 程式二進位支援。</li>
</ul>

<p>
ALSA 還有很多其他特色,例如支援全雙工錄放音、多音效卡支援、硬體音效混合、延伸混
音器支援 (以支援新音效卡的進階功能)...
</p>

</body>
</section>
<section>
<title>為什麼要用 ALSA?</title>
<body>

<p>
如果您的音效卡被 Linux 2.4.x 核心內建的商業版 OSS/4Front 音效驅動系統支援,您還
是可以使用<e>那些模組</e>來驅動您的音效卡。如果是這樣,請閱讀 
<uri link="http://www.tldp.org/HOWTO/Sound-HOWTO/index.html">Linux Sound HOWTO
</uri></p>

<p>
無論如何,那些 OSS/4Front 驅動程式還是有限制 - 商業版只是其中之一。ALSA 試圖超越
那些限制而且以開放原始碼的方式來做。ALSA 是完全使用 GPL 以及 LGPL 的音效驅動系統
,提供您專業品質的錄音、放音、以及 MIDI 撥放。
</p>

</body>
</section>
<section>
<title>ALSA 支援那些音效卡?</title>
<body>

<p>
ALSA 嘗試以提公開放原始碼驅動程式的方式支援所有 (新的) 音效卡。無論如何,某些廠
商只願意提供執行套件。
</p>

<p>
想知道您的卡有沒有被支援,您可以在以下的網址找到所有支援或不支援的音效卡清單:
<uri>http://www.alsa-project.org/alsa-doc/</uri></p>

</body>
</section>
</chapter>
<chapter>
<title>安裝</title>
<section>
<title>Gentoo USE 參數</title>
<body>

<p>
如要將程式編譯為 ALSA 支援,請確定在你的 USE 變數內加入 <e>alsa</e>。雖然目前還
沒有很多程式支援,只支援 OSS。如果你有在 USE 變數內加入 <e>oss</e>,ALSA 將會提
供 OSS 模擬。
</p>

</body>
<title>核心模組</title>
<body>

<p>
由於我們還在使用 2.4.x 的核心程式碼,我們都需要將核心與 ALSA 模組分開編譯。那些
使用 2.5.x 核心的人可以直接設定核心時順便設定,因為 ALSA 模組已經被包含在核心中
所以應該也得在那裡編譯。
</p>

<p>
首先我們要確定核心設定可以使用 ALSA。您必須做的只有打開 Sound Card Support 並且
讓它編譯成模組 (M)。它的名字會叫 <c>soundcore.o</c></p>

<note>
如果您將 Sound Card Support 編譯進核心 (Y) 而不是編譯成模組 (M),ALSA 也應該還是
可以用。無論如何,官方的 ALSA 文件建議您將它編成模組,畢竟 ALSA 會嘗試載入它。
</note>

<p>
如果您已經有個可以工作的核心設定檔,確定您將所有音效驅動程式移除 (Sound Card 
Support 例外)。如果您不想重開,您可以這麼做:
</p>

<pre>
# <i>cd /usr/src/linux</i>
# <i>cp .config ~/</i>
# <i>make mrproper</i>
# <i>cp ~/.config .</i>
# <i>make menuconfig</i>
</pre>

<p>
現在將 <e>Sound Card Support</e> 設定成模組 (M) 並且取消其他所有音效驅動程式,然
後離開並且選 Y 來儲存您的核心設定檔。在這之後,編譯模組:
</p>

<pre>
# <i>make dep clean</i>
# <i>make modules modules_install</i>
</pre>

<p>
在您安裝新的模組之前,您必須知道這會移除您之前安裝的所有模組,包括您之前安裝的 A
LSA 模組在內。
</p>

<impo>
這表示,當您以後重新編譯核心的時候,也必須重新編譯 <c>alsa-driver</c></impo>

</body>
</section>
<section>
<title>ALSA 模組</title>
<body>

<p>
現在是為您的音效卡安裝 ALSA 驅動程式的時候了!如果您使用 pci 音效卡,您可以從 
/proc/pci 找出它的資訊以及型號:
</p>

<pre>
# <i>grep audio /proc/pci</i>
</pre>

<warn>
如果您之前的非 ALSA 音效模組還是載入中,<e>現在</e>卸載它們。使用 <c>lsmod</c> 
檢查,並使用 <c>rmmod</c> 來卸載系統中所有音效相關的模組。
</warn>

<p>
接下來只要 <c>emerge alsa-driver</c> 了,這將編譯以及安裝<e>全部</e> ALSA 音效
驅動程式。
</p>

<p>
無論如何,為了節省時間,在 <uri link="http://www.alsa-project.org/alsa-doc">ALSA
Soundcard Matrix</uri> 查詢您音效卡的<e>模組名稱</e>,在 <e>Driver and Docs</e> 
中的 <e>Details</e> 連結可以找到,我的是 <c>snd-emu10k1</c>,畢竟我有張 SBlive! 
音效卡跟 <e>EMU10K1</e> 晶片。我們在 emerge 之前將 ALSA_CARDS 環境變數設定成模組
的名稱 (不過不要加入 snd 前置字串),所以 emerge 只會編譯我們需要的驅動程式。
</p>

<pre>
# <i>env ALSA_CARDS='emu10k1' emerge alsa-driver</i>
</pre>

<note>
您可以將這個設定加入 <path>/etc/make.conf</path>,那麼以後您想再次對 alsa-driver
做 emerge 的時候只要執行 <c>emerge alsa-driver</c> 就好。例如,類似這樣:
<c>echo 'ALSA_CARDS="emu10k1"' >> /etc/make.conf</c></note>

<note>
當您想要安裝一種以上的 ALSA 音效卡驅動程式的時候,您可以使用空白鍵來分隔驅動程式
清單;類似這樣:<c>env ALSA_CARDS='emu10k1 intel8x0 ens1370' 
emerge alsa-driver</c></note>

<note>
如果您想要 OSS 相容性,請確認您 emerge <i>alsa-oss</i>,他是 ALSA/OSS 相容轉換器
。
</note>

<note>
如果你打算多次重新編譯核心,我們建議你安裝 <c>alsa-driver</c> 時加上 
<c>--buildpkg</c>。這樣編譯完成後的二進位的檔案將方便你之後重邊核心時輸入 
<c>emerge --usepkg alsa-driver</c> 直接使用之前以編譯完成的檔案。
</note>

<p>
在這之後,ALSA 模組應該裝進您的系統了。
</p>

</body>
</section>
<section>
<title>ALSA 的設定</title>
<body>

<p>
現在我們嘗試設定 ALSA 讓它正常工作。我們必須編輯幾個檔案,讓系統知道我們剛才安裝
了燒燙燙的 ALSA 模組。
</p>

<p>
首先,安裝 <c>alsa-utils</c> 到你的系統上。
</p>

<pre caption="安裝 alsa-utils">
# <i>emerge alsa-utils</i>
</pre>

<p>
然後,我們將需要編輯 <path>/etc/modules.d/alsa</path></p>

<warn>
請不要直接編輯 <path>/etc/modules.conf</path>,取而代之,請永遠編輯 
<path>/etc/modules.d</path> 裡面的檔案。
</warn>

<p>
檢查<e>檔案最後</e> ALSA 設定,改變這個設定您可以指定最大的音效卡數量 (一般來
說,只有一張)。
</p>

<pre caption="在 /etc/modules.d/alsa 最後">

# 將這個設定成正確的音效卡數目。
# Set this to the correct number of cards.
<i>options snd cards_limit=1</i>
</pre>

<p>
現在我們指定 ALSA 要用的音效驅動程式。在同一個檔案,編輯如下:
</p>

<pre caption="/etc/modules.d/alsa">
## and then run 'modules-update' command.
## Read alsa-driver's INSTALL file in /usr/share/doc for more info.
##
##  ALSA portion
alias snd-card-0 snd-emu10k1
<comment>## 如果您的卡超過一張,加入:</comment>
## If you have more than one, add:
## alias snd-card-1 snd-intel8x0
## alias snd-card-2 snd-ens1370
##  OSS/Free portion
## alias sound-slot-0 snd-card-0
## alias sound-slot-1 snd-card-1
##
</pre>

<note>
如果您有一張以上的音效卡,調整 <c>cards_limit</c> 並在檔案中加入更多 snd-card 別
名。我沒有這樣的經驗,不過您可以在 
<uri link="http://www.alsa-project.org/alsa-doc/alsa-howto/alsa-howto.html">ALSA
 Howto</uri> <uri link="http://www.alsa-project.org/alsa-doc/alsa-howto/c1660.htm">第六章
</uri>找到兩張尾上網卡的範例設定檔。
</note>

<p>
我們最後要對這個檔案做的事,檢查這些東西有存在並且沒有被註解掉:
</p>

<pre caption="Near the end of /etc/modules.d/alsa">
alias /dev/mixer snd-mixer-oss
alias /dev/dsp snd-pcm-oss
alias /dev/midi snd-seq-oss
</pre>

<p>
現在,再次檢查一遍 <path>/etc/modules.d/alsa</path> 當您確定一切 ok 之後,執行 
<c>modules-update</c></p>

<pre>
# <i>modules-update</i>
</pre>

<note>
執行 <c>modules-update</c> 會將 <path>/etc/modules.d/alsa</path> 的資料加入至 
<path>/etc/modules.conf</path></note>

<p>
您也應該檢查 /etc/devfsd.conf 中包含 ALSA 設備以及註冊了正確的權限。
</p>

<pre caption="/etc/devfsd.conf">
# ALSA/OSS stuff
# Comment/change these if you want to change the permissions on
# the audio devices
LOOKUP          snd          MODLOAD ACTION snd
LOOKUP          dsp          MODLOAD
LOOKUP          mixer        MODLOAD
LOOKUP          midi         MODLOAD
REGISTER        sound/.*     PERMISSIONS root.audio 660
REGISTER        snd/.*       PERMISSIONS root.audio 660
</pre>

<note>
請注意 devfsd.conf 只將 /dev/sound 開放給 root.audio。所以,不是根 (root) 使用者
的使用者想使用音效設備,您必須把它們加入 audio 群組。
</note>

</body>
</section>
</chapter>
<chapter>
<title>啟動 ALSA</title>
<section>
<title> alsasound 加入 runlevel</title>
<body>

<p>
首先您必須確定 ALSA 在開機時啟動。像這樣:
</p>

<pre caption="將 ALSA 加到開機執行區">
# <i>rc-update add alsasound boot</i>
</pre>

<warn>
alsasound 命令稿應該被加入至 "boot" runlevel 而不是 "default" runlevel。
</warn>

</body>
</section>
<section>
<title>執行以及取消靜音</title>
<body>

<p>
畢竟我們是 Linux 使用者,我們不想重開機。所以只好手動啟動 alsascript 命令稿:
</p>

<pre>
# <i>/etc/init.d/alsasound start</i>
</pre>

<p>
現在 ALSA 已經啟動了!如果一切 ok,您現在應該可以在執行 <c>lsmod</c> 中看到 ALSA
 模組。無論如何,您的電腦還是發不出聲音,因為它們還被靜音中。我們需要 
<c>amixer</c> 才能取消靜音。
</p>

<pre caption="執行 amixer">
# <i>amixer</i>
</pre>

<warn>
您不應該得到這個錯誤,不過<e>如果</e>您看到螢幕上說 "amixer: Mixer attach 
default error: No such file or directory",您必須手動 modprobe 
<c>snd-mixer-oss</c>  <c>snd-pcm-oss</c>。在這之後再執行 amixer 一次。
</warn>

<pre caption="在執行 amixer 出問題的時候">
# <i>modprobe snd-mixer-oss</i>
# <i>modprobe snd-pcm-oss</i>
# <i>amixer</i>
</pre>

<p>
如果您做到了這裡,現在可以解除 Master  PCM 聲道的靜音了。有些硬體需要你解除中
央聲道和環繞聲道的靜音。
</p>

<pre caption="解除聲道靜音">
# <i>amixer set Master 100 unmute</i>
# <i>amixer set PCM 100 unmute</i>

<comment>如以上不能成功完成,請執行以下:</comment>

# <i>amixer set Center 100 unmute</i>
# <i>amixer set Surround 100 unmute</i>

<comment>測試聲音:</comment>
# <i>aplay $KDEDIR/share/sounds/pop.wav</i> <codenote>(pop.wav is part of KDE)</codenote>
</pre>

<p>
我們使用 aplay (alsa play) 指令來測試音效裝置。如果您聽到了一聲 "pop",那麼音效
絕對已經起來了。然後,調整您的音量設定;使用 ncurses  <c>alsamixer</c> 是個好
工具。
</p>

<p>
您可能會想 emerge <c>alsa-xmms</c>,它提供 XMMS  ALSA 支援。
</p>

<p>
當您重新啟動系統時,<e>alsasound</e> 起始命令稿會自動回復您的音量設定。
</p>

</body>
</section>
</chapter>
<chapter>
<title>最後的筆記</title>
<section>
<title>更新核心之後...</title>
<body>

<p>
當您重新編譯核心,或升級到其他核心,您必須重新編譯 ALSA 模組。
</p>

<p>
您可能安裝了 <c>alsa-driver</c><c>alsa-libs</c>  <c>alsa-utils</c>,只有第一
個需要重新安裝,畢竟它會把 alsa 模組放在 
<path>/lib/modules/*/kernel/sound/pci/</path></p>

<pre caption="每次編譯核心之後">
# <i>emerge alsa-driver</i>
</pre>

</body>
</section>
<section>
<title>/etc/modules.autoload</title>
<body>

<p>
使用 ALSA 的時候,您不需要編輯這個檔案。在 <c>rc-update add alsasound boot</c> 
之後,系統會自動在開機時載入適當的模組。
</p>

<p>
您也不需要將 <c>snd-pcm-oss</c>  <c>snd-mixer-oss</c> 加入這個檔案。查看
<uri link="http://www.djcj.org/LAU/guide/alsbook/faq1.html">這篇 FAQ</uri> 取得
更多資訊。
</p>

</body>
</section>
<section>
<title>已知的臭蟲</title>
<body>

<note>
這份指南比 alsa 的開發來得慢,在你閱讀這篇文章時,有極大可能某些錯誤已修正。
</note>

<ul>
<li>
如果你有在使用 <b>oss</b> 模擬的時候發現 <b>許多雜音</b>,請到
<path>/etc/modules.d/alsa</path> 下加入 <e>options snd-pcm-oss dsp_map=1</e></li>
</ul>
</body>
</section>

<section>
<title>啟用搖桿支援</title>
<body>

<p>
如果你的音效卡有搖桿的接口,你應該會友興趣啟用音效卡上的搖桿接口支援。請先確定音
效卡的驅動程式上有搖桿的參數。你可以使用 <c>modinfo</c> 查看你的 
<path>snd-&lt;晶片&gt;</path>。舉例來說,你的音效卡是 <c>snd-via82xx</c></p>

<pre caption="執行 modinfo">
# <i>modinfo snd-via82xx</i>
 filename:    /lib/modules/2.4.22-ck2/snd-via82xx.o
  	 description: "VIA VT82xx audio"
  	 author:      "Jaroslav Kysela &lt;perex@suse.cz&gt;"
  	 license:     "GPL"
  	 parm:        index int array (min = 1, max = 8), description "Index value for VIA 82xx bridge."
  	 parm:        id string array (min = 1, max = 8), description "ID string for VIA 82xx bridge."
  	 parm:        enable int array (min = 1, max = 8), description "Enable audio part of VIA 82xx bridge."
  	 parm:        mpu_port long array (min = 1, max = 8), description "MPU-401 port. (VT82C686x only)"
  	 <i>parm:        joystick int array (min = 1, max = 8), description "Enable joystick. (VT82C686x only)"</i>
  	 parm:        ac97_clock int array (min = 1, max = 8), description "AC'97 codec clock (default 48000Hz)."
  	 parm:        dxs_support int array (min = 1, max = 8), description "Support for DXS channels
	 (0 = auto, 1 = enable, 2 = disable, 3 = 48k only, 4 = no VRA)"
</pre>
  	 
<p>
如果有找到 <c>搖桿</c> 參數,然後將 <c>joystick=1</c> 加到
<path>/etc/modules.d/alsa</path> 裡面的 <c>options</c> 後面。舉例來說,
<c>snd-via82xx</c>將要使用:
</p>
 	 
<pre caption="增加搖桿參數">
alias snd-card-0 snd-via82xx
options snd-via82xx joystick=1
</pre>
  	 
</body>
</section>

<section>
<title>更多連結...</title>
<body>

<p>
您可以在這裡找到更多資訊:
</p>

<ul>
  <li>
    <uri link="http://www.gentoo.org/doc/en/desktop.xml">The Gentoo Linux 
    Desktop Configuration Guide</uri>
  </li>
  <li><uri link="http://www.alsa-project.org">ALSA Project Homepage</uri></li>
  <li>
    <uri link="http://www.alsa-project.org/documentation.php3">ALSA Users 
    Documentation</uri>
  </li>
  <li><uri link="http://www.djcj.org">ALSA Howto's and FAQ's</uri></li>
  <li>
    <uri link="http://tldp.org/HOWTO/Sound-HOWTO/index.html">Linux Sound HOWTO
    </uri>
  </li>
  <li>
    <uri link="http://linux-sound.org/">Sound and MIDI Software For Linux</uri>
  </li>
</ul>
</body>
</section>
</chapter>
</guide>