aboutsummaryrefslogtreecommitdiff
path: root/en_US.ISO8859-1/books/handbook/multimedia/chapter.sgml
blob: 5fe664092bfe3e66d25bfc3a56493af570419add (plain) (blame)
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
<!--
     The FreeBSD Documentation Project

     $FreeBSD: doc/en_US.ISO8859-1/books/handbook/sound/chapter.sgml,v 1.22 2001/09/24 11:23:09 murray Exp $
-->

<chapter id="sound">
  <chapterinfo>
    <authorgroup>
      <author>
        <firstname>Moses</firstname>
	<surname>Moore</surname>
	<contrib>Contributed by </contrib>
      </author>
    </authorgroup>
    <!-- 20 November 2000 -->
  </chapterinfo>

  <title>Sound</title>

  <sect1>
    <title>Synopsis</title>

    <para>FreeBSD supports a wide variety of sound cards, allowing you
      to enjoy high fidelity output from your computer.  This includes
      the ability to record and playback audio in the MPEG Audio Layer
      3 (MP3), WAV, and Ogg Vorbis formats as well as many other
      formats.  The FreeBSD Ports Collection also contains
      applications allowing you to edit your recorded audio, add sound
      effects, and control attached MIDI devices.</para>

    <para>After reading this chapter, you will know:</para>
    <itemizedlist>
      <listitem><para>How to locate your sound card.</para></listitem>
      <listitem><para>How to configure your system so that your sound card is
      recognized.</para></listitem>
      <listitem><para>Methods to test that your card is working using
      sample applications.</para></listitem>
      <listitem><para>How to troubleshoot your sound setup.</para></listitem>
      <listitem><para>How to playback and encode MP3s.</para></listitem>
      <listitem><para>How to rip CD audio tracks into data files.</para></listitem>
    </itemizedlist>

    <para>Before reading this chapter, you should:</para>

    <itemizedlist>
      <listitem><para>Know how to configure and install a new kernel (<xref
        linkend="kernelconfig">).</para></listitem>
    </itemizedlist>
  </sect1>

  <sect1>
    <title>Locating the Correct Device</title>

    <indexterm><primary>PCI</primary></indexterm>
    <indexterm><primary>ISA</primary></indexterm>
    <indexterm><primary>sound cards</primary></indexterm>
    <para>Before you begin, you should know the model of the card you
      have, the chip it uses, and whether it is a PCI or ISA card.
      FreeBSD supports a wide variety of both PCI and ISA cards.  If you
      do not see your card in the following list, check the &man.pcm.4;
      manual page.  This is not a complete list; however, it does list
      some of the most common cards.</para>

    <itemizedlist>
      <listitem>
	<para>Crystal 4237, 4236, 4232, 4231</para>
      </listitem>

      <listitem>
	<para>Yamaha OPL-SAx</para>
      </listitem>

      <listitem>
	<para>OPTi931</para>
      </listitem>

      <listitem>
	<para>Ensoniq AudioPCI 1370/1371</para>
      </listitem>

      <listitem>
	<para>ESS Solo-1/1E</para>
      </listitem>

      <listitem>
	<para>NeoMagic 256AV/ZX</para>
      </listitem>

      <listitem>
	<para>Sound Blaster Pro, 16, 32, AWE64, AWE128, Live</para>
      </listitem>

      <listitem>
	<para>Creative ViBRA16</para>
      </listitem>

      <listitem>
	<para>Advanced Asound 100, 110, and Logic ALS120</para>
      </listitem>

      <listitem>
	<para>ES 1868, 1869, 1879, 1888</para>
      </listitem>

      <listitem>
	<para>Gravis UltraSound</para>
      </listitem>

      <listitem>
	<para>Aureal Vortex 1 or 2</para>
      </listitem>
    </itemizedlist>

    <indexterm>
      <primary>kernel</primary>
      <secondary>configuration</secondary>
    </indexterm>
    <para>The driver you use in your kernel depends on the kind of card
      you have.  The sections below provide more information and what
      you will need to add to your <link linkend="kernelconfig">kernel
      configuration</link>.</para>

    <sect2>
      <title>Creative, Advance, and ESS Sound Cards</title>

      <para>If you have one of the above cards, you will need to
	add:</para>
	
      <programlisting>device pcm</programlisting>

      <para>to your kernel configuration file.  If you have a PnP ISA
	card, you will also need to add:</para>

      <programlisting>device sbc</programlisting>

      <para>For a non-PnP ISA card, add:</para>

      <programlisting>device pcm
device sbc0 at isa? port 0x220 irq 5 drq 1 flags 0x15</programlisting>

      <para>to your kernel configuration file.  The settings shown
	above are the defaults.  You may need to change the IRQ or the
	other settings to match your card.  See the &man.sbc.4; manual
	page for more information.</para>

      <note>
	<para>The Sound Blaster Live is not supported under FreeBSD 4.0
	  without a patch, which this section will not cover.  It is
	  recommended that you update to the latest -STABLE before
	  trying to use this card.</para>
      </note>
    </sect2>

    <sect2>
      <title>Gravis UltraSound Cards</title>

      <para>For a PnP ISA card, you will need to add:</para>

      <programlisting>device pcm
device gusc</programlisting>

      <para>to your kernel configuration file.  If you have a non-PnP ISA card, you will
	need to add:</para>

      <programlisting>device pcm
device gus0 at isa? port 0x220 irq 5 drq 1 flags 0x13</programlisting>

      <para>to your kernel configuration file.  You may need to change
	the IRQ or the other settings to match your card. See the
	&man.gusc.4; manual page for more information.</para>
    </sect2>

    <sect2>
      <title>Crystal Sound Cards</title>

      <para>For Crystal cards, you will need to add:</para>

      <programlisting>device pcm
device csa</programlisting>

      <para>to your kernel configuration file.</para>
    </sect2>

    <sect2>
      <title>Generic Support</title>

      <para>For PnP ISA or PCI cards, you will need to add:</para>

      <programlisting>device pcm</programlisting>

      <para>to your kernel configuration file.  If you have a non-PnP ISA
	sound card that does not have a bridge driver, you will need
	to add:</para>

      <programlisting>device pcm0 at isa? irq 10 drq 1 flags 0x0</programlisting>

      <para>to your kernel configuration file.  You may need to change
	the IRQ or the other settings to match your card.</para>

    </sect2>

    <sect2>
      <title>Onboard Sound</title>

      <para>Some systems with built-in motherboard sound devices may
	require the following option in your kernel
	configuration:</para>

      <programlisting>options PNPBIOS</programlisting>
    </sect2>
  </sect1>

  <sect1>
    <title>Recompiling the Kernel</title>

    <para>After adding the requisite driver(s) to your kernel
      configuration file, you will need to recompile your kernel.  Please see
      <xref linkend="kernelconfig-building"> of the handbook for
      more information.</para>
  </sect1>

  <sect1>
    <title>Creating and Testing the Device Nodes</title>

    <indexterm><primary>device nodes</primary></indexterm>
    <para>After you reboot, log in and run <command>dmesg | grep pcm</command> as shown
      below:</para>

    <screen>&prompt.root; dmesg | grep pcm
pcm0: &lt;SB16 DSP 4.11&gt; on sbc0</screen>

    <para>The output from your system may look different.  If no
      <devicename>pcm</devicename> devices show up, something went wrong
      earlier.  If that happens, go through your kernel configuration
      file again and make sure you chose the correct device.  Consult
      the troubleshooting section for additional options.</para>

    <para>If the previous command returned <devicename>pcm0</devicename>,
      you will have to run the following as root:</para>

    <screen>&prompt.root; cd /dev
&prompt.root; sh MAKEDEV snd0</screen>

    <para>If the command returned <devicename>pcm1</devicename>,
      follow the same steps as shown above, replacing
      <devicename>snd0</devicename> with
      <devicename>snd1</devicename>.</para>

    <note>
      <para>The above commands will <emphasis>not</emphasis> create a
	<devicename>/dev/snd</devicename> device!</para>
    </note>

    <para><command>MAKEDEV</command> will create a group of device
      nodes, including:</para>

    <informaltable frame="none">
      <tgroup cols="2">
	<thead>
	  <row>
	    <entry>Device</entry>
	    <entry>Description</entry>
	  </row>
	</thead>

	<tbody>
	  <row>
	    <entry><devicename>/dev/audio</devicename></entry>
	    <entry>SPARC-compatible audio device</entry>
	  </row>

	  <row>
	    <entry><devicename>/dev/dsp</devicename></entry>
	    <entry>Digitized voice device</entry>
	  </row>

	  <row>
	    <entry><devicename>/dev/dspW</devicename></entry>
	    <entry>Like <devicename>/dev/dsp</devicename>, but 16 bits
	      per sample</entry>
	  </row>

	  <row>
	    <entry><devicename>/dev/midi</devicename></entry>
	    <entry>Raw midi access device</entry>
	  </row>

	  <row>
	    <entry><devicename>/dev/mixer</devicename></entry>
	    <entry>Control port mixer device</entry>
	  </row>

	  <row>
	    <entry><devicename>/dev/music</devicename></entry>
	    <entry>Level 2 sequencer interface</entry>
	  </row>

	  <row>
	    <entry><devicename>/dev/sequencer</devicename></entry>
	    <entry>Sequencer device</entry>
	  </row>

	  <row>
	    <entry><devicename>/dev/pss</devicename></entry>
	    <entry>Programmable device interface</entry>
	  </row>
	</tbody>
      </tgroup>
    </informaltable>

    <para>If all goes well, you should now have a functioning sound
      card.  If you do not, read the next section.</para>
  </sect1>

  <sect1>
    <title>Common Problems</title>

    <qandaset>
      <indexterm><primary>device node</primary></indexterm>
      <qandaentry>
	<question>
	  <para>I get an unsupported subdevice XX error!</para>
	</question>

	<answer>
	  <para>One or more of the device nodes was not created
	    correctly.  Repeat the steps above.</para>
	</answer>
      </qandaentry>

      <indexterm><primary>I/O port</primary></indexterm>
      <qandaentry>
	<question>
	  <para>I get a sb_dspwr(XX) timed out error!</para>
	</question>

	<answer>
	  <para>The I/O port is not set correctly.</para>
	</answer>
      </qandaentry>

      <indexterm><primary>IRQ</primary></indexterm>
      <qandaentry>
	<question>
	  <para>I get a bad irq XX error!</para>
	</question>

	<answer>
	  <para>The IRQ is set incorrectly.  Make sure that the set IRQ
	    and the sound IRQ are the same.</para>
	</answer>
      </qandaentry>

      <qandaentry>
	<question>
	  <para>I get a <errorname>xxx: gus pcm not attached, out of 
	    memory</errorname>
	    error.  What causes that?</para>
	</question>

	<answer>
	  <para>If this happens, it is because there is not enough
	    available memory to use the device.</para>
	</answer>
      </qandaentry>
    </qandaset>
  </sect1>

  <sect1 id="mp3">
    <sect1info>
      <authorgroup>
	<author>
	  <firstname>Chern</firstname>
	  <surname>Lee</surname>
	  <contrib>Contributed by </contrib>
	</author>
      </authorgroup>
      <!-- 11 Sept 2001 -->
    </sect1info>

    <title>MP3 Audio</title>

    <para>MP3 (MPEG Layer 3 Audio) accomplishes near CD-quality sound,
      leaving no reason to let your FreeBSD workstation fall short of
      its offerings.</para>

    <sect2 id="mp3-players">
      <title>MP3 Players</title>

      <para>By far, the most popular XFree86 MP3 player is
	<application>XMMS</application> (X Multimedia System).  
	<application>WinAmp</application>
	skins can be used with <application>XMMS</application> since the
	GUI is almost identical to that of Nullsoft 
	<application>Winamp</application>'s.
	<application>XMMS</application> also has native plug-in
	support.</para>

      <para><application>XMMS</application> can be installed from the
	<port>audio/xmms</port> port or package.</para>

      <para><application>XMMS'</application> interface is intuitive, with
	a playlist, graphic equalizer, and more.  Those familiar with WinAmp
	will find <application>XMMS</application> simple to use.</para>

      <para>The <port>audio/mpg123</port> port is an alternative,
	command-line MP3 player.</para>

      <para><application>mpg123</application> can be run by specifying the
	sound device and the MP3 file on the command line, as shown below:</para>

      <screen>&prompt.root; mpg123 -a <replaceable>/dev/dsp1.0</replaceable> Foobar-GreatestHits.mp3
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layer 1, 2 and 3.
Version 0.59r (1999/Jun/15). Written and copyrights by Michael Hipp.
Uses code from various people. See 'README' for more!
THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK!





Playing MPEG stream from BT - Foobar-GreastHits.mp3 ...
MPEG 1.0 layer III, 128 kbit/s, 44100 Hz joint-stereo
</screen>

      <para><literal>/dev/dsp1.0</literal> should be replaced with the
	<devicename>dsp</devicename> device entry on your system.</para>

    </sect2>

    <sect2 id="rip-cd">
      <title>Ripping CD Audio Tracks</title>

      <para>Before encoding a CD or CD track to MP3, the audio data on
	the CD must be ripped onto the hard drive.  This is done by
	copying the raw CDDA (CD Digital Audio) data to WAV
	files.</para>

      <para>The <command>cdda2wav</command> tool, which is a part of the
	<port>sysutils/cdrtools</port> suite, is used for ripping audio
	information of CDs and the information associated with it.</para>

      <para>With the audio CD in the drive, the following command
	can be issued (as <username>root</username>) to rip an entire
	CD into individual (per track) WAV files:</para>

      <screen>&prompt.root; cdda2wav -D <replaceable>0,1,0</replaceable> -B</screen>

      <para>The <option>-D <replaceable>0,1,0</replaceable></option>
	indicates the SCSI device <devicename>0,1,0</devicename>, which
	corresponds to the output of <command>cdrecord
	  -scanbus</command>.</para>

      <para>To rip individual tracks, make use of the
	<option>-t</option> option as shown:</para>

      <screen>&prompt.root; cdda2wav -D <replaceable>0,1,0</replaceable> -t 7</screen>

      <para>This example rips track seven of the audio CDROM.  To rip a range
	of tracks, for example, track one to seven, specify a range:</para>

      <screen>&prompt.root; cdda2wav -D <replaceable>0,1,0</replaceable> -t 1+7</screen>

      <para><application>cdda2wav</application> only supports SCSI
	CDROM drives.  For IDE drives, try out <port>audio/cdd</port> or
	some of the various other utilities in the audio ports
	collection.</para>

    </sect2>

    <sect2 id="mp3-encoding">
      <title>Encoding MP3s</title>

      <para>Nowadays, the mp3 encoder of choice is
	<application>lame</application>.
	<application>Lame</application> can be found at
	<port>audio/lame</port> in the ports tree.</para>

      <para>Using the ripped WAV files, the following command will
	convert <filename>audio01.wav</filename> to
	<filename>audio01.mp3</filename>:</para>

      <screen>&prompt.root; lame -h -b <replaceable>128</replaceable> \
--tt "<replaceable>Foo Song Title</replaceable>" \
--ta "<replaceable>FooBar Artist</replaceable>" \
--tl "<replaceable>FooBar Album</replaceable>" \
--ty "<replaceable>2001</replaceable>" \
--tc "<replaceable>Ripped and encoded by Foo</replaceable>" \
--tg "<replaceable>Genre</replaceable>" \
<replaceable>audio01.wav audio01.mp3</replaceable></screen>

      <para>128 kbits seems to be the standard MP3 bitrate in use.
	Many enjoy the higher quality 160, or 192.  The higher the
	bitrate, the more disk space the resulting MP3 will consume--but
	the quality will be higher.  The <option>-h</option> option
	turns on the <quote>higher quality but a little slower</quote>
	mode.  The options beginning with <option>--t</option> indicate
	ID3 tags, which usually contain song information, to be embedded
	within the MP3 file.  Additional encoding options can be found
	by consulting the lame man page.</para>
    </sect2>

    <sect2 id="mp3-decoding">
      <title>Decoding MP3s</title>

      <para>In order to burn an audio CD from MP3s, they must be converted
	to a non-compressed WAV format.  Both <application>XMMS</application>
	and <application>mpg123</application> support the output of MP3 to
	an uncompressed file format.</para>

      <para>Writing to Disk in <application>XMMS</application>:</para>

      <procedure>
	<step>
	  <para>Launch <application>XMMS</application>.</para>
	</step>

	<step>
	  <para>Right-click on the window to bring up the
	    <application>XMMS</application> menu.</para>
	</step>

	<step>
	  <para>Select <literal>Preference</literal> under
	    <literal>Options</literal>.</para>
	</step>

	<step>
	  <para>Change the Output Plugin to <quote>Disk Writer
	      Plugin</quote>.</para>
	</step>

	<step>
	  <para>Press <literal>Configure</literal>.</para>
	</step>

	<step>
	  <para>Enter (or choose browse) a directory to write the
	    uncompressed files to.</para>
	</step>

	<step>
	  <para>Load the MP3 file into <application>XMMS</application>
	    as usual, with volume at 100% and EQ settings turned
	    off.</para>
	</step>

	<step>
	  <para>Press <literal>Play</literal> &mdash; <application>XMMS</application>
	    will appear as if it is playing the MP3, but no music will be heard.  It
	    is actually playing the MP3 to a file.</para>
	</step>

	<step>
	  <para>Be sure to set the default Output Plugin back to what it was before
	    in order to listen to MP3s again.</para>
	</step>
      </procedure>

      <para>Writing to stdout in <application>mpg123</application>:</para>

      <procedure>
	<step>
	  <para>Run mpg123 -s <replaceable>audio01.mp3</replaceable>
	    &gt; audio01.pcm</para>
	</step>
      </procedure>

      <para><application>XMMS</application> writes a file in the WAV format, while
	<application>mpg123</application> converts the MP3 into raw PCM audio data.
	Both of these formats can be used with <application>cdrecord</application>
	or <application>burncd</application> to create audio CDROMs.</para>

      <para>Read <xref linkend="creating-cds"> for more information on using a
	  CD burner in FreeBSD.</para>
    </sect2>
  </sect1>
</chapter>