4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
29 #include "endianmacros.h"
32 #include "sconv-s16le.h"
33 #include "sconv-s16be.h"
35 static void u8_to_float32(unsigned n
, const void *a
, unsigned an
, float *b
) {
37 const uint8_t *ca
= a
;
38 assert(n
&& a
&& an
&& b
);
43 for (i
= 0; i
< an
; i
++) {
45 sum
+= (((float) v
)-127)/127;
57 static void u8_from_float32(unsigned n
, const float *a
, void *b
, unsigned bn
) {
61 assert(n
&& a
&& b
&& bn
);
72 u
= (uint8_t) (v
*127+127);
74 for (i
= 0; i
< bn
; i
++)
79 static void float32_to_float32(unsigned n
, const void *a
, unsigned an
, float *b
) {
82 assert(n
&& a
&& an
&& b
);
86 for (i
= 0; i
< an
; i
++)
98 static void float32_from_float32(unsigned n
, const float *a
, void *b
, unsigned bn
) {
101 assert(n
&& a
&& b
&& bn
);
104 for (i
= 0; i
< bn
; i
++)
109 pa_convert_to_float32_func_t
pa_get_convert_to_float32_function(enum pa_sample_format f
) {
112 return u8_to_float32
;
113 case PA_SAMPLE_S16LE
:
114 return pa_sconv_s16le_to_float32
;
115 case PA_SAMPLE_S16BE
:
116 return pa_sconv_s16be_to_float32
;
117 case PA_SAMPLE_FLOAT32
:
118 return float32_to_float32
;
124 pa_convert_from_float32_func_t
pa_get_convert_from_float32_function(enum pa_sample_format f
) {
127 return u8_from_float32
;
128 case PA_SAMPLE_S16LE
:
129 return pa_sconv_s16le_from_float32
;
130 case PA_SAMPLE_S16BE
:
131 return pa_sconv_s16be_from_float32
;
132 case PA_SAMPLE_FLOAT32
:
133 return float32_from_float32
;