Fixed and tested hwdep device and documentation about it.
[aic34-eq] / kernel-2.6.28 / Documentation / sound / alsa / soc / tlv320aic3x.txt
1 WARNING: THINGS DESCRIBED BELOW ARE NOT YET IN THE REPOS. THEY WILL BE, 
2 VERY SOON.
3
4 The TLV320AIC3X is a powerful four channel low power audio codec family.
5 More information is available at:
6     http://focus.ti.com/docs/prod/folders/print/tlv320aic34.html
7 Datasheet:
8     http://www.ti.com/lit/gpn/tlv320aic34
9
10 The codec driver leverages the codecs effects through alsa controls and a 
11 hwdep device for controlling the hardware fourth-order IIR filter block.
12
13 There's an alsa control, "3D Control - Depth" for depth simulation.
14 The rest of the controls are for the IIR filter:
15
16 1- A control for setting the bass/treble gain, which sets the filter's
17    coefficients to certain precalculated values.
18 2- A control for 'off' / 'on' / 'external control'. 'On' means the 
19    bass/treble gain is used, while 'external control' means the 
20    coefficients have been set through the hwdep device (see below).
21
22
23
24 The IIR Filter consists of 2 cascaded biquads. The formula is:
25  /                                \  /                                \
26 |    (N0 + 2*N1*z^-1 + N2*z^-2)    ||    (N3 + 2*N4*z^-1 + N5*z^-2)    |
27 |  ------------------------------  ||  ------------------------------  |
28 |  (32768 - 2*D1*z^-1 - D2*z^-2)   ||   (32768 - 2*D4*z^-1 - D5*z^-2)  |
29 \                                 /  \                                /
30
31 The filter can be controlled through an alsa hwdep device, via 
32 libasound. A short example follows, note that the data struct must be
33 passed *EXACTLY* as shown. Remember to link against libasound:
34 gcc myapp.c -lasound -o myapp
35
36 -------------------------------EXAMPLE----------------------------------
37 #include <stdint.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <fcntl.h>
41 #include <alsa/asoundlib.h>
42 #include <alsa/hwdep.h>
43
44 struct iirfilter_data {
45     int16_t N0, N1, N2, D1, D2;
46     int16_t N3, N4, N5, D4, D5;
47 };
48
49 int main() {
50     int ret;
51     snd_hwdep_t *hwdep;
52     struct iirfilter_data data = {
53             .N0 = 27619, .N1 = -27034, .N2 = 26461, .D1 = 32131, .D2 = -31506,
54         .N3 = 27619, .N4 = -27034, .N5 = 26461, .D4 = 32131, .D5 = -31506
55     };
56
57 /* Initialize */
58     ret = snd_hwdep_open(&hwdep, "hw:0,0", SND_HWDEP_OPEN_DUPLEX);
59     if(ret != 0) exit(1);
60
61 /* To write: */
62     snd_hwdep_write(hwdep, (void*)&data, sizeof(data));
63
64 /* To read: */
65     snd_hwdep_read(hwdep, (void*)&data, sizeof(data));
66
67 /* To enable/disable filtering: */
68     int arg = 1; /* 1 = enable, 0 = disable */
69     snd_hwdep_ioctl(hwdep, 1, &arg);
70     return 0;
71 }
72 ------------------------------------------------------------------------
73
74
75