2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
5 Copyright 2009 Wim Taymans <wim.taymans@collabora.co.uk.com>
7 PulseAudio is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published
9 by the Free Software Foundation; either version 2.1 of the License,
10 or (at your option) any later version.
12 PulseAudio is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with PulseAudio; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
29 #include <pulse/sample.h>
30 #include <pulsecore/log.h>
31 #include <pulsecore/macro.h>
35 static void remap_mono_to_stereo_c(pa_remap_t
*m
, void *dst
, const void *src
, unsigned n
) {
39 case PA_SAMPLE_FLOAT32NE
:
46 for (i
= n
>> 2; i
; i
--) {
54 for (i
= n
& 3; i
; i
--) {
68 for (i
= n
>> 2; i
; i
--) {
76 for (i
= n
& 3; i
; i
--) {
84 pa_assert_not_reached();
88 static void remap_channels_matrix_c(pa_remap_t
*m
, void *dst
, const void *src
, unsigned n
) {
92 n_ic
= m
->i_ss
->channels
;
93 n_oc
= m
->o_ss
->channels
;
96 case PA_SAMPLE_FLOAT32NE
:
100 memset(dst
, 0, n
* sizeof(float) * n_oc
);
102 for (oc
= 0; oc
< n_oc
; oc
++) {
104 for (ic
= 0; ic
< n_ic
; ic
++) {
107 vol
= m
->map_table_f
[oc
][ic
];
112 d
= (float *)dst
+ oc
;
113 s
= (float *)src
+ ic
;
116 for (i
= n
; i
> 0; i
--, s
+= n_ic
, d
+= n_oc
)
119 for (i
= n
; i
> 0; i
--, s
+= n_ic
, d
+= n_oc
)
127 case PA_SAMPLE_S16NE
:
131 memset(dst
, 0, n
* sizeof(int16_t) * n_oc
);
133 for (oc
= 0; oc
< n_oc
; oc
++) {
135 for (ic
= 0; ic
< n_ic
; ic
++) {
138 vol
= m
->map_table_i
[oc
][ic
];
143 d
= (int16_t *)dst
+ oc
;
144 s
= (int16_t *)src
+ ic
;
146 if (vol
>= 0x10000) {
147 for (i
= n
; i
> 0; i
--, s
+= n_ic
, d
+= n_oc
)
150 for (i
= n
; i
> 0; i
--, s
+= n_ic
, d
+= n_oc
)
151 *d
+= (int16_t) (((int32_t)*s
* vol
) >> 16);
158 pa_assert_not_reached();
162 /* set the function that will execute the remapping based on the matrices */
163 static void init_remap_c(pa_remap_t
*m
) {
166 n_oc
= m
->o_ss
->channels
;
167 n_ic
= m
->i_ss
->channels
;
169 /* find some common channel remappings, fall back to full matrix operation. */
170 if (n_ic
== 1 && n_oc
== 2 &&
171 m
->map_table_f
[0][0] >= 1.0 && m
->map_table_f
[1][0] >= 1.0) {
172 m
->do_remap
= (pa_do_remap_func_t
) remap_mono_to_stereo_c
;
173 pa_log_info("Using mono to stereo remapping");
175 m
->do_remap
= (pa_do_remap_func_t
) remap_channels_matrix_c
;
176 pa_log_info("Using generic matrix remapping");
181 /* default C implementation */
182 static pa_init_remap_func_t remap_func
= init_remap_c
;
184 void pa_init_remap(pa_remap_t
*m
) {
185 pa_assert(remap_func
);
189 /* call the installed remap init function */
192 if (m
->do_remap
== NULL
) {
193 /* nothing was installed, fallback to C version */
198 pa_init_remap_func_t
pa_get_init_remap_func(void) {
202 void pa_set_init_remap_func(pa_init_remap_func_t func
) {