annotate DOCS/tech/hwac3.txt @ 28445:c6cef3c6768f

Give _XOPEN_SOURCE #define an explicit 600 value. Fixes build on Open Solaris. patch by Imran Syed, freakabcd gmail com
author diego
date Sat, 07 Feb 2009 17:34:45 +0000
parents f3d7a1b58a82
children 0f1b5b68af32
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4778
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
1 mails by A'rpi and Marcus Blomenkamp <Marcus.Blomenkamp@epost.de>
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
2 describing how this ac3-passtrough hack work under linux and mplayer...
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
3 -----------------------------------------------------------------------
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
4 Hi,
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
5
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
6 > I received the following patch from Steven Brookes <stevenjb@mda.co.uk>.
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
7 > He is working on fixing the digital audio output of the dxr3 driver and
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
8 > told me he fixed some bugs in mplayer along the way. I don't know shit
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
9 > about hwac3 output so all I did was to make sure the patch applied
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
10 > against latest cvs.
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
11 > This is from his e-mail to me:
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
12 >
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
13 > "Secondly there is a patch to dec_audio.c and
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
14 > ac3-iec958 to fix the -ac hwac3 codec stuff and to use liba52 to sync it.
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
15
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
16 > Seems to work for everything I've thrown at and maintains sync for all audio
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
17 > types through the DXR3."
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
18
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
19 patch applied (with some comments added and an unwanted change (in software
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
20 a52 decoder) removed)
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
21
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
22 now i understand how this whole hwac3 mess work.
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
23 it's very very tricky. it virtually decodes ac3 to LPCM packets, but really
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
24 it keeps the original compressed data padded by zeros. this way it's
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
25 constant bitrate, and sync is calculated just like for stereo PCM.
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
26 (so it bypass LPCM-capable media converters...)
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
27
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
28 so, every ac3 frame is translated to 6144 byte long tricky LPCM packet.
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
29 6144 = 4*(6*256) = 4 * samples_per_ac3_frame = LPCM size of uncompressed ac3
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
30 frame.
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
31
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
32 i wanna know if it works for sblive and other ac3-capable cards too?
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
33 (i can't test it, lack of ac3 decoder)
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
34
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
35 A'rpi / Astral & ESP-team
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
36
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
37 -----------------------------------------------------------------------
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
38 Hi folks.
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
39 I spend some time fiddling with ac3 passthrough in mplayer. The
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
40 traditional way of setting the output format to AFMT_AC3 was no ideal
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
41 solution since not all digital io cards/drivers supported this format or
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
42 honoured it to set the spdif non-audio bit. To make it short, it only
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
43 worked with oss sblive driver IIRC.
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
44
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
45 Inspired by alsa's ac3dec program I found an alternative way by
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
46 inspecting to which format the alsa device had been set. Suprise: it was
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
47 simple 16bit_le 2_channel pcm. So setting the non-audio bit doesn't
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
48 necessarily mean the point. The only important thing seems to be
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
49 bit-identical output at the correct samplerate. Modern AV-Receivers seem
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
50 to be quite tolerant/compatible.
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
51
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
52 So I changed the output format of hwac3 from
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
53
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
54 AFMT_AC3 channels=1
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
55 to
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
56 AFMT_S16_LE channels=2
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
57
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
58 and corrected the absolute time calculation. That was all to get it
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
59 running for me.
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
60
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
61 -----------------------------------------------------------------------
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
62 Hi there.
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
63
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
64 Perhaps I can clear up some mystification about AC3 passthrough in
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
65 general and mplayer in special:
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
66
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
67 To get the external decoder solution working, it must be fed with data
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
68 which is bitidentical to the chunks in the source ac3 file (compressed
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
69 data is very picky about bit errors). Additionally - or better to say
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
70 'historically' - the non-audio bit should be set in the spdif status
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
71 fields to prevent old spdif hardware from reproducing ugly scratchy
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
72 noise. Note: for current decoders (probably those with DTS capability)
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
73 this safety bit isn't needed anymore. At least I can state that for my
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
74 Sherwood RVD-6095RDS. I think it is due to DTS because DTS sound can
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
75 reside on a ordinary AudioCD and an ordinary AudioCD-Player will always
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
76 have it's audio-bit set.
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
77
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
78 The sample format of the data must be 2channel 16bit (little endian
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
79 IIRC). Samplerates are 48kHz - although my receiver also accepts
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
80 44100Hz. I do not know if this is due to an over-compatability of my
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
81 receiver or if 44100 is also possible in the ac3 specs. For safety's
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
82 sake lets keep this at 48000Hz. AC3 data chunks are inserted into the
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
83 stream every 0x1600 bytes (don't bite me on that, look into
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
84 'ac3-iec958.c': 'ac3_iec958_build_burst').
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
85
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
86 To come back to the problem: data must be played bit-identically through
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
87 the soundcard at the correct samplerate and should optionally have it's
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
88 non-audio bit set. There are two ways to accomplish this:
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
89
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
90 1) Some OSS guy invented the format AFMT_AC3. Soundcard drivers
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
91 implementing this format should therefore adjust it's mixers and
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
92 switches to produce the desired output. Unfortunately some soundcard
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
93 drivers do not support this format correctly and most do not even
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
94 support it at all (including ALSA).
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
95
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
96 2) The alternative approach currently in mplayer CVS is to simply set
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
97 the output format to 48kHz16bitLE and rely on the user to have the
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
98 soundcard mixers adjusted properly.
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
99
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
100 I do have two soundcards with digital IO facilities (CMI8738 and
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
101 Trident4DWaveNX based) plus the mentioned decoder. I'm currently running
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
102 Linux-2.4.17. Following configurations are happily running here:
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
103
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
104 1. Trident with ALSA drivers (OSS does not support Hoontech's dig. IO)
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
105 2. CMI with ALSA drivers
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
106 3. CMI with OSS drivers
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
107
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
108 For Linux I'd suggest using ALSA because of it's cleaner architecture
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
109 and more consitent user interface. Not to mention that it'll be the
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
110 standard sound support in Linux soon.
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
111
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
112 For those who want to stick to OSS drivers: The CMI8738 drivers works
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
113 out-of-the-box, if the PCM/Wave mixer is set to 100%.
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
114
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
115 For ALSA I'd suggest using its OSS emulation. More on that later.
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
116 ALSA-0.9 invented the idea of cards, devices and dubdevices. You can
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
117 reach the digital interface of all supported cards consitently by using
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
118 the device 'hw:x,2' (x counting from 0 is the number of your soundcard).
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
119 So most people would end up at 'hw:0,2'. This device can only be opened
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
120 in sample formats and rates which are directly supported in hardware
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
121 hence no samplerate conversion is done keeping the stream as-is. However
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
122 most consumer soundcards do not support 44kHz so it would definitively
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
123 be a bad idea to use this as your standard device if you wanted to
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
124 listen to some mp3s (most of them are 44kHz due to CD source). Here the
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
125 OSS comes to play again. You can configure which OSS device (/dev/dsp
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
126 and /dev/adsp) uses which ALSA device. So I'd suggest pointing the
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
127 standard '/dev/dsp' to standard 'hw:0,0' which suports mixing and
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
128 samplerate conversion. No further reconfiguration would be needed for
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
129 your sound apps. For movies I'd point '/dev/adsp' to 'hw:0,2' and
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
130 configure mplayer to use adsp instead of dsp. The samplerate constrain
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
131 is no big deal here since movies usually are in 48Khz anyway. The
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
132 configuration in '/etc/modules.conf' is no big deal also:
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
133
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
134 alias snd-card-0 snd-card-cmipci # insert your card here
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
135 alias snd-card-1 snd-pcm-oss # load OSS emulation
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
136 options snd-pcm-oss snd_dsp_map=0 snd_adsp_map=2 # do the mapping
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
137
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
138 This works flawlessly in combination with alsa's native
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
139 SysVrc-init-script 'alsasound'. Be sure to disable any distribution
22316
f3d7a1b58a82 cosmetics: Fix some common typos, appropiate --> appropRiate,
diego
parents: 4778
diff changeset
140 dependent script (e.g. Mandrake-8.1 has an 'alsa' script which depends
4778
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
141 on ALSA-0.5).
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
142
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
143 Sorry for you *BSD'lers out there. I have no grasp on sound support there.
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
144
85d041ad0c87 3 mails describing hwac3 tech details
arpi
parents:
diff changeset
145 HTH Marcus