1 /***************************************************************************
4 * Fri Jul 18 14:16:22 2003
5 * Copyright 2003 mjander
6 * mjander@users.sourceforge.net
8 * A3D. You may think i'm crazy, but this may work someday. Who knows...
9 ****************************************************************************/
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include "au88x0_a3d.h"
28 #include "au88x0_a3ddata.c"
29 #include "au88x0_xtalk.h"
33 a3dsrc_SetTimeConsts(a3dsrc_t
* a
, short HrtfTrack
, short ItdTrack
,
34 short GTrack
, short CTrack
)
36 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
38 a3d_addrA(a
->slice
, a
->source
, A3D_A_HrtfTrackTC
), HrtfTrack
);
40 a3d_addrA(a
->slice
, a
->source
, A3D_A_ITDTrackTC
), ItdTrack
);
42 a3d_addrA(a
->slice
, a
->source
, A3D_A_GainTrackTC
), GTrack
);
44 a3d_addrA(a
->slice
, a
->source
, A3D_A_CoeffTrackTC
), CTrack
);
49 a3dsrc_GetTimeConsts(a3dsrc_t
* a
, short *HrtfTrack
, short *ItdTrack
,
50 short *GTrack
, short *CTrack
)
56 /* Atmospheric absorption. */
59 a3dsrc_SetAtmosTarget(a3dsrc_t
* a
, short aa
, short b
, short c
, short d
,
62 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
64 a3d_addrB(a
->slice
, a
->source
, A3D_B_A21Target
),
67 a3d_addrB(a
->slice
, a
->source
, A3D_B_B10Target
),
70 a3d_addrB(a
->slice
, a
->source
, A3D_B_B2Target
), c
);
74 a3dsrc_SetAtmosCurrent(a3dsrc_t
* a
, short aa
, short b
, short c
, short d
,
77 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
79 a3d_addrB(a
->slice
, a
->source
, A3D_B_A12Current
),
82 a3d_addrB(a
->slice
, a
->source
, A3D_B_B01Current
),
85 a3d_addrB(a
->slice
, a
->source
, A3D_B_B2Current
), c
);
89 a3dsrc_SetAtmosState(a3dsrc_t
* a
, short x1
, short x2
, short y1
, short y2
)
91 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
92 hwwrite(vortex
->mmio
, a3d_addrA(a
->slice
, a
->source
, A3D_A_x1
), x1
);
93 hwwrite(vortex
->mmio
, a3d_addrA(a
->slice
, a
->source
, A3D_A_x2
), x2
);
94 hwwrite(vortex
->mmio
, a3d_addrA(a
->slice
, a
->source
, A3D_A_y1
), y1
);
95 hwwrite(vortex
->mmio
, a3d_addrA(a
->slice
, a
->source
, A3D_A_y2
), y2
);
100 a3dsrc_GetAtmosTarget(a3dsrc_t
* a
, short *aa
, short *b
, short *c
,
105 a3dsrc_GetAtmosCurrent(a3dsrc_t
* a
, short *bb01
, short *ab01
, short *b2
,
106 short *aa12
, short *ba12
)
108 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
111 a3d_addrA(a
->slice
, a
->source
, A3D_A_A12Current
));
114 a3d_addrB(a
->slice
, a
->source
, A3D_B_A12Current
));
117 a3d_addrA(a
->slice
, a
->source
, A3D_A_B01Current
));
120 a3d_addrB(a
->slice
, a
->source
, A3D_B_B01Current
));
123 a3d_addrA(a
->slice
, a
->source
, A3D_A_B2Current
));
127 a3dsrc_GetAtmosState(a3dsrc_t
* a
, short *x1
, short *x2
, short *y1
, short *y2
)
136 a3dsrc_SetHrtfTarget(a3dsrc_t
* a
, a3d_Hrtf_t
const aa
, a3d_Hrtf_t
const b
)
138 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
141 for (i
= 0; i
< HRTF_SZ
; i
++)
142 hwwrite(vortex
->mmio
,
143 a3d_addrB(a
->slice
, a
->source
,
144 A3D_B_HrtfTarget
) + (i
<< 2),
145 (b
[i
] << 0x10) | aa
[i
]);
149 a3dsrc_SetHrtfCurrent(a3dsrc_t
* a
, a3d_Hrtf_t
const aa
, a3d_Hrtf_t
const b
)
151 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
154 for (i
= 0; i
< HRTF_SZ
; i
++)
155 hwwrite(vortex
->mmio
,
156 a3d_addrB(a
->slice
, a
->source
,
157 A3D_B_HrtfCurrent
) + (i
<< 2),
158 (b
[i
] << 0x10) | aa
[i
]);
162 a3dsrc_SetHrtfState(a3dsrc_t
* a
, a3d_Hrtf_t
const aa
, a3d_Hrtf_t
const b
)
164 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
167 for (i
= 0; i
< HRTF_SZ
; i
++)
168 hwwrite(vortex
->mmio
,
169 a3d_addrB(a
->slice
, a
->source
,
170 A3D_B_HrtfDelayLine
) + (i
<< 2),
171 (b
[i
] << 0x10) | aa
[i
]);
174 static void a3dsrc_SetHrtfOutput(a3dsrc_t
* a
, short left
, short right
)
176 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
177 hwwrite(vortex
->mmio
,
178 a3d_addrA(a
->slice
, a
->source
, A3D_A_HrtfOutL
), left
);
179 hwwrite(vortex
->mmio
,
180 a3d_addrA(a
->slice
, a
->source
, A3D_A_HrtfOutR
), right
);
184 static void a3dsrc_GetHrtfTarget(a3dsrc_t
* a
, a3d_Hrtf_t aa
, a3d_Hrtf_t b
)
186 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
189 for (i
= 0; i
< HRTF_SZ
; i
++)
192 a3d_addrA(a
->slice
, a
->source
,
193 A3D_A_HrtfTarget
+ (i
<< 2)));
194 for (i
= 0; i
< HRTF_SZ
; i
++)
197 a3d_addrB(a
->slice
, a
->source
,
198 A3D_B_HrtfTarget
+ (i
<< 2)));
201 static void a3dsrc_GetHrtfCurrent(a3dsrc_t
* a
, a3d_Hrtf_t aa
, a3d_Hrtf_t b
)
203 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
206 for (i
= 0; i
< HRTF_SZ
; i
++)
209 a3d_addrA(a
->slice
, a
->source
,
210 A3D_A_HrtfCurrent
+ (i
<< 2)));
211 for (i
= 0; i
< HRTF_SZ
; i
++)
214 a3d_addrB(a
->slice
, a
->source
,
215 A3D_B_HrtfCurrent
+ (i
<< 2)));
218 static void a3dsrc_GetHrtfState(a3dsrc_t
* a
, a3d_Hrtf_t aa
, a3d_Hrtf_t b
)
220 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
222 // FIXME: verify this!
223 for (i
= 0; i
< HRTF_SZ
; i
++)
226 a3d_addrA(a
->slice
, a
->source
,
227 A3D_A_HrtfDelayLine
+ (i
<< 2)));
228 for (i
= 0; i
< HRTF_SZ
; i
++)
231 a3d_addrB(a
->slice
, a
->source
,
232 A3D_B_HrtfDelayLine
+ (i
<< 2)));
235 static void a3dsrc_GetHrtfOutput(a3dsrc_t
* a
, short *left
, short *right
)
237 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
240 a3d_addrA(a
->slice
, a
->source
, A3D_A_HrtfOutL
));
243 a3d_addrA(a
->slice
, a
->source
, A3D_A_HrtfOutR
));
248 /* Interaural Time Difference.
249 * "The other main clue that humans use to locate sounds, is called
250 * Interaural Time Difference (ITD). The differences in distance from
251 * the sound source to a listeners ears means that the sound will
252 * reach one ear slightly before the other....", found somewhere with google.*/
253 static void a3dsrc_SetItdTarget(a3dsrc_t
* a
, short litd
, short ritd
)
255 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
265 hwwrite(vortex
->mmio
,
266 a3d_addrB(a
->slice
, a
->source
, A3D_B_ITDTarget
),
267 (ritd
<< 0x10) | litd
);
268 //hwwrite(vortex->mmio, addr(0x191DF+5, this04, this08), (ritd<<0x10)|litd);
271 static void a3dsrc_SetItdCurrent(a3dsrc_t
* a
, short litd
, short ritd
)
273 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
283 hwwrite(vortex
->mmio
,
284 a3d_addrB(a
->slice
, a
->source
, A3D_B_ITDCurrent
),
285 (ritd
<< 0x10) | litd
);
286 //hwwrite(vortex->mmio, addr(0x191DF+1, this04, this08), (ritd<<0x10)|litd);
289 static void a3dsrc_SetItdDline(a3dsrc_t
* a
, a3d_ItdDline_t
const dline
)
291 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
293 /* 45 != 40 -> Check this ! */
294 for (i
= 0; i
< DLINE_SZ
; i
++)
295 hwwrite(vortex
->mmio
,
296 a3d_addrA(a
->slice
, a
->source
,
297 A3D_A_ITDDelayLine
) + (i
<< 2), dline
[i
]);
301 static void a3dsrc_GetItdTarget(a3dsrc_t
* a
, short *litd
, short *ritd
)
303 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
306 a3d_addrA(a
->slice
, a
->source
, A3D_A_ITDTarget
));
309 a3d_addrB(a
->slice
, a
->source
, A3D_B_ITDTarget
));
312 static void a3dsrc_GetItdCurrent(a3dsrc_t
* a
, short *litd
, short *ritd
)
314 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
318 a3d_addrA(a
->slice
, a
->source
, A3D_A_ITDCurrent
));
321 a3d_addrB(a
->slice
, a
->source
, A3D_B_ITDCurrent
));
324 static void a3dsrc_GetItdDline(a3dsrc_t
* a
, a3d_ItdDline_t dline
)
326 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
329 for (i
= 0; i
< DLINE_SZ
; i
++)
332 a3d_addrA(a
->slice
, a
->source
,
333 A3D_A_ITDDelayLine
+ (i
<< 2)));
337 /* This is may be used for ILD Interaural Level Difference. */
339 static void a3dsrc_SetGainTarget(a3dsrc_t
* a
, short left
, short right
)
341 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
342 hwwrite(vortex
->mmio
,
343 a3d_addrB(a
->slice
, a
->source
, A3D_B_GainTarget
),
344 (right
<< 0x10) | left
);
347 static void a3dsrc_SetGainCurrent(a3dsrc_t
* a
, short left
, short right
)
349 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
350 hwwrite(vortex
->mmio
,
351 a3d_addrB(a
->slice
, a
->source
, A3D_B_GainCurrent
),
352 (right
<< 0x10) | left
);
356 static void a3dsrc_GetGainTarget(a3dsrc_t
* a
, short *left
, short *right
)
358 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
361 a3d_addrA(a
->slice
, a
->source
, A3D_A_GainTarget
));
364 a3d_addrB(a
->slice
, a
->source
, A3D_B_GainTarget
));
367 static void a3dsrc_GetGainCurrent(a3dsrc_t
* a
, short *left
, short *right
)
369 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
372 a3d_addrA(a
->slice
, a
->source
, A3D_A_GainCurrent
));
375 a3d_addrB(a
->slice
, a
->source
, A3D_B_GainCurrent
));
378 /* CA3dIO this func seems to be inlined all over this place. */
379 static void CA3dIO_WriteReg(a3dsrc_t
* a
, unsigned long addr
, short aa
, short b
)
381 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
382 hwwrite(vortex
->mmio
, addr
, (aa
<< 0x10) | b
);
386 /* Generic A3D stuff */
388 static void a3dsrc_SetA3DSampleRate(a3dsrc_t
* a
, int sr
)
390 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
393 esp0
= (((esp0
& 0x7fffffff) | 0xB8000000) & 0x7) | ((sr
& 0x1f) << 3);
394 hwwrite(vortex
->mmio
, A3D_SLICE_Control
+ ((a
->slice
) << 0xd), esp0
);
395 //hwwrite(vortex->mmio, 0x19C38 + (this08<<0xd), esp0);
398 static void a3dsrc_EnableA3D(a3dsrc_t
* a
)
400 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
401 hwwrite(vortex
->mmio
, A3D_SLICE_Control
+ ((a
->slice
) << 0xd),
403 //hwwrite(vortex->mmio, 0x19C38 + (this08<<0xd), 0xF0000001);
406 static void a3dsrc_DisableA3D(a3dsrc_t
* a
)
408 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
409 hwwrite(vortex
->mmio
, A3D_SLICE_Control
+ ((a
->slice
) << 0xd),
413 static void a3dsrc_SetA3DControlReg(a3dsrc_t
* a
, unsigned long ctrl
)
415 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
416 hwwrite(vortex
->mmio
, A3D_SLICE_Control
+ ((a
->slice
) << 0xd), ctrl
);
419 static void a3dsrc_SetA3DPointerReg(a3dsrc_t
* a
, unsigned long ptr
)
421 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
422 hwwrite(vortex
->mmio
, A3D_SLICE_Pointers
+ ((a
->slice
) << 0xd), ptr
);
426 static void a3dsrc_GetA3DSampleRate(a3dsrc_t
* a
, int *sr
)
428 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
429 *sr
= ((hwread(vortex
->mmio
, A3D_SLICE_Control
+ (a
->slice
<< 0xd))
431 //*sr = ((hwread(vortex->mmio, 0x19C38 + (this08<<0xd))>>3)&0x1f);
434 static void a3dsrc_GetA3DControlReg(a3dsrc_t
* a
, unsigned long *ctrl
)
436 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
437 *ctrl
= hwread(vortex
->mmio
, A3D_SLICE_Control
+ ((a
->slice
) << 0xd));
440 static void a3dsrc_GetA3DPointerReg(a3dsrc_t
* a
, unsigned long *ptr
)
442 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
443 *ptr
= hwread(vortex
->mmio
, A3D_SLICE_Pointers
+ ((a
->slice
) << 0xd));
447 static void a3dsrc_ZeroSliceIO(a3dsrc_t
* a
)
449 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
452 for (i
= 0; i
< 8; i
++)
453 hwwrite(vortex
->mmio
,
455 ((((a
->slice
) << 0xb) + i
) << 2), 0);
456 for (i
= 0; i
< 4; i
++)
457 hwwrite(vortex
->mmio
,
458 A3D_SLICE_VDBSource
+
459 ((((a
->slice
) << 0xb) + i
) << 2), 0);
462 /* Reset Single A3D source. */
463 static void a3dsrc_ZeroState(a3dsrc_t
* a
)
466 pr_debug( "vortex: ZeroState slice: %d, source %d\n",
467 a->slice, a->source);
469 a3dsrc_SetAtmosState(a
, 0, 0, 0, 0);
470 a3dsrc_SetHrtfState(a
, A3dHrirZeros
, A3dHrirZeros
);
471 a3dsrc_SetItdDline(a
, A3dItdDlineZeros
);
472 a3dsrc_SetHrtfOutput(a
, 0, 0);
473 a3dsrc_SetTimeConsts(a
, 0, 0, 0, 0);
475 a3dsrc_SetAtmosCurrent(a
, 0, 0, 0, 0, 0);
476 a3dsrc_SetAtmosTarget(a
, 0, 0, 0, 0, 0);
477 a3dsrc_SetItdCurrent(a
, 0, 0);
478 a3dsrc_SetItdTarget(a
, 0, 0);
479 a3dsrc_SetGainCurrent(a
, 0, 0);
480 a3dsrc_SetGainTarget(a
, 0, 0);
482 a3dsrc_SetHrtfCurrent(a
, A3dHrirZeros
, A3dHrirZeros
);
483 a3dsrc_SetHrtfTarget(a
, A3dHrirZeros
, A3dHrirZeros
);
486 /* Reset entire A3D engine */
487 static void a3dsrc_ZeroStateA3D(a3dsrc_t
*a
, vortex_t
*v
)
491 if ((a
->vortex
) == NULL
) {
492 dev_err(v
->card
->dev
,
493 "ZeroStateA3D: ERROR: a->vortex is NULL\n");
497 a3dsrc_SetA3DControlReg(a
, 0);
498 a3dsrc_SetA3DPointerReg(a
, 0);
502 for (i
= 0; i
< 4; i
++) {
504 a3dsrc_ZeroSliceIO(a
);
505 //a3dsrc_ZeroState(a);
511 /* Program A3D block as pass through */
512 static void a3dsrc_ProgramPipe(a3dsrc_t
* a
)
514 a3dsrc_SetTimeConsts(a
, 0, 0, 0, 0);
515 a3dsrc_SetAtmosCurrent(a
, 0, 0x4000, 0, 0, 0);
516 a3dsrc_SetAtmosTarget(a
, 0x4000, 0, 0, 0, 0);
517 a3dsrc_SetItdCurrent(a
, 0, 0);
518 a3dsrc_SetItdTarget(a
, 0, 0);
519 a3dsrc_SetGainCurrent(a
, 0x7fff, 0x7fff);
520 a3dsrc_SetGainTarget(a
, 0x7fff, 0x7fff);
524 /* Single spike leads to identity transfer function. */
525 a3dsrc_SetHrtfCurrent(a
, A3dHrirImpulse
, A3dHrirImpulse
);
526 a3dsrc_SetHrtfTarget(a
, A3dHrirImpulse
, A3dHrirImpulse
);
528 /* Test: Sounds saturated. */
529 //a3dsrc_SetHrtfCurrent(a, A3dHrirSatTest, A3dHrirSatTest);
530 //a3dsrc_SetHrtfTarget(a, A3dHrirSatTest, A3dHrirSatTest);
533 /* VDB = Vortex audio Dataflow Bus */
535 static void a3dsrc_ClearVDBData(a3dsrc_t
* a
, unsigned long aa
)
537 vortex_t
*vortex
= (vortex_t
*) (a
->vortex
);
539 // ((aa >> 2) << 8) - (aa >> 2)
540 hwwrite(vortex
->mmio
,
541 a3d_addrS(a
->slice
, A3D_SLICE_VDBDest
) + (a
->source
<< 2), 0);
542 hwwrite(vortex
->mmio
,
544 A3D_SLICE_VDBDest
+ 4) + (a
->source
<< 2), 0);
546 hwwrite(vortex->mmio, 0x19c00 + (((aa>>2)*255*4)+aa)*8, 0);
547 hwwrite(vortex->mmio, 0x19c04 + (((aa>>2)*255*4)+aa)*8, 0);
552 /* A3D HwSource stuff. */
554 static void vortex_A3dSourceHw_Initialize(vortex_t
* v
, int source
, int slice
)
556 a3dsrc_t
*a3dsrc
= &(v
->a3d
[source
+ (slice
* 4)]);
557 //a3dsrc_t *a3dsrc = &(v->a3d[source + (slice*4)]);
559 a3dsrc
->vortex
= (void *)v
;
560 a3dsrc
->source
= source
; /* source */
561 a3dsrc
->slice
= slice
; /* slice */
562 a3dsrc_ZeroState(a3dsrc
);
564 a3dsrc_SetA3DSampleRate(a3dsrc
, 0x11);
567 static int Vort3DRend_Initialize(vortex_t
* v
, unsigned short mode
)
569 v
->xt_mode
= mode
; /* this_14 */
571 vortex_XtalkHw_init(v
);
572 vortex_XtalkHw_SetGainsAllChan(v
);
573 switch (v
->xt_mode
) {
575 vortex_XtalkHw_ProgramXtalkNarrow(v
);
578 vortex_XtalkHw_ProgramXtalkWide(v
);
582 vortex_XtalkHw_ProgramPipe(v
);
585 vortex_XtalkHw_ProgramDiamondXtalk(v
);
588 vortex_XtalkHw_SetSampleRate(v
, 0x11);
589 vortex_XtalkHw_Enable(v
);
593 /* 3D Sound entry points. */
595 static int vortex_a3d_register_controls(vortex_t
* vortex
);
596 static void vortex_a3d_unregister_controls(vortex_t
* vortex
);
597 /* A3D base support init/shudown */
598 static void vortex_Vort3D_enable(vortex_t
*v
)
602 Vort3DRend_Initialize(v
, XT_HEADPHONE
);
603 for (i
= 0; i
< NR_A3D
; i
++) {
604 vortex_A3dSourceHw_Initialize(v
, i
% 4, i
>> 2);
605 a3dsrc_ZeroStateA3D(&v
->a3d
[0], v
);
607 /* Register ALSA controls */
608 vortex_a3d_register_controls(v
);
611 static void vortex_Vort3D_disable(vortex_t
* v
)
613 vortex_XtalkHw_Disable(v
);
614 vortex_a3d_unregister_controls(v
);
617 /* Make A3D subsystem connections. */
618 static void vortex_Vort3D_connect(vortex_t
* v
, int en
)
622 // Disable AU8810 routes, since they seem to be wrong (in au8810.h).
628 /* Alloc Xtalk mixin resources */
630 vortex_adb_checkinout(v
, v
->fixed_res
, en
, VORTEX_RESOURCE_MIXIN
);
631 if (v
->mixxtlk
[0] < 0) {
632 dev_warn(v
->card
->dev
,
633 "vortex_Vort3D: ERROR: not enough free mixer resources.\n");
637 vortex_adb_checkinout(v
, v
->fixed_res
, en
, VORTEX_RESOURCE_MIXIN
);
638 if (v
->mixxtlk
[1] < 0) {
639 dev_warn(v
->card
->dev
,
640 "vortex_Vort3D: ERROR: not enough free mixer resources.\n");
645 /* Connect A3D -> XTALK */
646 for (i
= 0; i
< 4; i
++) {
647 // 2 outputs per each A3D slice.
648 vortex_route(v
, en
, 0x11, ADB_A3DOUT(i
* 2), ADB_XTALKIN(i
));
649 vortex_route(v
, en
, 0x11, ADB_A3DOUT(i
* 2) + 1, ADB_XTALKIN(5 + i
));
652 vortex_route(v
, en
, 0x11, ADB_XTALKOUT(0), ADB_EQIN(2));
653 vortex_route(v
, en
, 0x11, ADB_XTALKOUT(1), ADB_EQIN(3));
655 /* Connect XTalk -> mixer */
656 vortex_route(v
, en
, 0x11, ADB_XTALKOUT(0), ADB_MIXIN(v
->mixxtlk
[0]));
657 vortex_route(v
, en
, 0x11, ADB_XTALKOUT(1), ADB_MIXIN(v
->mixxtlk
[1]));
658 vortex_connection_mixin_mix(v
, en
, v
->mixxtlk
[0], v
->mixplayb
[0], 0);
659 vortex_connection_mixin_mix(v
, en
, v
->mixxtlk
[1], v
->mixplayb
[1], 0);
660 vortex_mix_setinputvolumebyte(v
, v
->mixplayb
[0], v
->mixxtlk
[0],
661 en
? MIX_DEFIGAIN
: VOL_MIN
);
662 vortex_mix_setinputvolumebyte(v
, v
->mixplayb
[1], v
->mixxtlk
[1],
663 en
? MIX_DEFIGAIN
: VOL_MIN
);
664 if (VORTEX_IS_QUAD(v
)) {
665 vortex_connection_mixin_mix(v
, en
, v
->mixxtlk
[0],
667 vortex_connection_mixin_mix(v
, en
, v
->mixxtlk
[1],
669 vortex_mix_setinputvolumebyte(v
, v
->mixplayb
[2],
671 en
? MIX_DEFIGAIN
: VOL_MIN
);
672 vortex_mix_setinputvolumebyte(v
, v
->mixplayb
[3],
674 en
? MIX_DEFIGAIN
: VOL_MIN
);
679 /* Initialize one single A3D source. */
680 static void vortex_Vort3D_InitializeSource(a3dsrc_t
*a
, int en
, vortex_t
*v
)
682 if (a
->vortex
== NULL
) {
683 dev_warn(v
->card
->dev
,
684 "Vort3D_InitializeSource: A3D source not initialized\n");
688 a3dsrc_ProgramPipe(a
);
689 a3dsrc_SetA3DSampleRate(a
, 0x11);
690 a3dsrc_SetTimeConsts(a
, HrtfTCDefault
,
691 ItdTCDefault
, GainTCDefault
,
693 /* Remark: zero gain is muted. */
694 //a3dsrc_SetGainTarget(a,0,0);
695 //a3dsrc_SetGainCurrent(a,0,0);
698 a3dsrc_DisableA3D(a
);
703 /* Conversion of coordinates into 3D parameters. */
705 static void vortex_a3d_coord2hrtf(a3d_Hrtf_t hrtf
, int *coord
)
707 /* FIXME: implement this. */
710 static void vortex_a3d_coord2itd(a3d_Itd_t itd
, int *coord
)
712 /* FIXME: implement this. */
715 static void vortex_a3d_coord2ild(a3d_LRGains_t ild
, int left
, int right
)
717 /* FIXME: implement this. */
720 static void vortex_a3d_translate_filter(a3d_atmos_t filter
, int *params
)
722 /* FIXME: implement this. */
726 /* ALSA control interface. */
729 snd_vortex_a3d_hrtf_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
731 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
733 uinfo
->value
.integer
.min
= 0x00000000;
734 uinfo
->value
.integer
.max
= 0xffffffff;
738 snd_vortex_a3d_itd_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
740 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
742 uinfo
->value
.integer
.min
= 0x00000000;
743 uinfo
->value
.integer
.max
= 0xffffffff;
747 snd_vortex_a3d_ild_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
749 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
751 uinfo
->value
.integer
.min
= 0x00000000;
752 uinfo
->value
.integer
.max
= 0xffffffff;
756 snd_vortex_a3d_filter_info(struct snd_kcontrol
*kcontrol
,
757 struct snd_ctl_elem_info
*uinfo
)
759 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
761 uinfo
->value
.integer
.min
= 0x00000000;
762 uinfo
->value
.integer
.max
= 0xffffffff;
767 snd_vortex_a3d_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
769 //a3dsrc_t *a = kcontrol->private_data;
770 /* No read yet. Would this be really useable/needed ? */
776 snd_vortex_a3d_hrtf_put(struct snd_kcontrol
*kcontrol
,
777 struct snd_ctl_elem_value
*ucontrol
)
779 a3dsrc_t
*a
= kcontrol
->private_data
;
782 for (i
= 0; i
< 6; i
++)
783 coord
[i
] = ucontrol
->value
.integer
.value
[i
];
784 /* Translate orientation coordinates to a3d params. */
785 vortex_a3d_coord2hrtf(a
->hrtf
[0], coord
);
786 vortex_a3d_coord2hrtf(a
->hrtf
[1], coord
);
787 a3dsrc_SetHrtfTarget(a
, a
->hrtf
[0], a
->hrtf
[1]);
788 a3dsrc_SetHrtfCurrent(a
, a
->hrtf
[0], a
->hrtf
[1]);
793 snd_vortex_a3d_itd_put(struct snd_kcontrol
*kcontrol
,
794 struct snd_ctl_elem_value
*ucontrol
)
796 a3dsrc_t
*a
= kcontrol
->private_data
;
799 for (i
= 0; i
< 6; i
++)
800 coord
[i
] = ucontrol
->value
.integer
.value
[i
];
801 /* Translate orientation coordinates to a3d params. */
802 vortex_a3d_coord2itd(a
->hrtf
[0], coord
);
803 vortex_a3d_coord2itd(a
->hrtf
[1], coord
);
804 /* Inter aural time difference. */
805 a3dsrc_SetItdTarget(a
, a
->itd
[0], a
->itd
[1]);
806 a3dsrc_SetItdCurrent(a
, a
->itd
[0], a
->itd
[1]);
807 a3dsrc_SetItdDline(a
, a
->dline
);
812 snd_vortex_a3d_ild_put(struct snd_kcontrol
*kcontrol
,
813 struct snd_ctl_elem_value
*ucontrol
)
815 a3dsrc_t
*a
= kcontrol
->private_data
;
818 /* There may be some scale tranlation needed here. */
819 l
= ucontrol
->value
.integer
.value
[0];
820 r
= ucontrol
->value
.integer
.value
[1];
821 vortex_a3d_coord2ild(a
->ild
, l
, r
);
822 /* Left Right panning. */
823 a3dsrc_SetGainTarget(a
, l
, r
);
824 a3dsrc_SetGainCurrent(a
, l
, r
);
829 snd_vortex_a3d_filter_put(struct snd_kcontrol
*kcontrol
,
830 struct snd_ctl_elem_value
*ucontrol
)
832 a3dsrc_t
*a
= kcontrol
->private_data
;
835 for (i
= 0; i
< 6; i
++)
836 params
[i
] = ucontrol
->value
.integer
.value
[i
];
837 /* Translate generic filter params to a3d filter params. */
838 vortex_a3d_translate_filter(a
->filter
, params
);
839 /* Atmospheric absorption and filtering. */
840 a3dsrc_SetAtmosTarget(a
, a
->filter
[0],
841 a
->filter
[1], a
->filter
[2],
842 a
->filter
[3], a
->filter
[4]);
843 a3dsrc_SetAtmosCurrent(a
, a
->filter
[0],
844 a
->filter
[1], a
->filter
[2],
845 a
->filter
[3], a
->filter
[4]);
849 static const struct snd_kcontrol_new vortex_a3d_kcontrol
= {
850 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
851 .name
= "Playback PCM advanced processing",
852 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
853 .info
= snd_vortex_a3d_hrtf_info
,
854 .get
= snd_vortex_a3d_get
,
855 .put
= snd_vortex_a3d_hrtf_put
,
858 /* Control (un)registration. */
859 static int vortex_a3d_register_controls(vortex_t
*vortex
)
861 struct snd_kcontrol
*kcontrol
;
864 for (i
= 0; i
< NR_A3D
; i
++) {
866 snd_ctl_new1(&vortex_a3d_kcontrol
, &vortex
->a3d
[i
])) == NULL
)
868 kcontrol
->id
.numid
= CTRLID_HRTF
;
869 kcontrol
->info
= snd_vortex_a3d_hrtf_info
;
870 kcontrol
->put
= snd_vortex_a3d_hrtf_put
;
871 if ((err
= snd_ctl_add(vortex
->card
, kcontrol
)) < 0)
875 for (i
= 0; i
< NR_A3D
; i
++) {
877 snd_ctl_new1(&vortex_a3d_kcontrol
, &vortex
->a3d
[i
])) == NULL
)
879 kcontrol
->id
.numid
= CTRLID_ITD
;
880 kcontrol
->info
= snd_vortex_a3d_itd_info
;
881 kcontrol
->put
= snd_vortex_a3d_itd_put
;
882 if ((err
= snd_ctl_add(vortex
->card
, kcontrol
)) < 0)
885 /* ILD (gains) controls. */
886 for (i
= 0; i
< NR_A3D
; i
++) {
888 snd_ctl_new1(&vortex_a3d_kcontrol
, &vortex
->a3d
[i
])) == NULL
)
890 kcontrol
->id
.numid
= CTRLID_GAINS
;
891 kcontrol
->info
= snd_vortex_a3d_ild_info
;
892 kcontrol
->put
= snd_vortex_a3d_ild_put
;
893 if ((err
= snd_ctl_add(vortex
->card
, kcontrol
)) < 0)
896 /* Filter controls. */
897 for (i
= 0; i
< NR_A3D
; i
++) {
899 snd_ctl_new1(&vortex_a3d_kcontrol
, &vortex
->a3d
[i
])) == NULL
)
901 kcontrol
->id
.numid
= CTRLID_FILTER
;
902 kcontrol
->info
= snd_vortex_a3d_filter_info
;
903 kcontrol
->put
= snd_vortex_a3d_filter_put
;
904 if ((err
= snd_ctl_add(vortex
->card
, kcontrol
)) < 0)
910 static void vortex_a3d_unregister_controls(vortex_t
* vortex
)