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 Lesser 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 Lesser 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
30 #include <liboil/liboilfuncs.h>
31 #include <liboil/liboil.h>
33 #include <polypcore/g711.h>
35 #include "endianmacros.h"
36 #include "sconv-s16le.h"
37 #include "sconv-s16be.h"
41 static void u8_to_float32ne(unsigned n, const void *a, float *b) {
42 const uint8_t *ca = a;
43 static const double add = -128.0/127.0, factor = 1.0/127.0;
48 oil_scaleconv_f32_u8(b, ca, n, &add, &factor);
51 static void u8_from_float32ne(unsigned n, const float *a, void *b) {
53 static const double add = 128.0, factor = 127.0;
58 oil_scaleconv_u8_f32(cb, a, n, &add, &factor);
61 static void float32ne_to_float32ne(unsigned n, const void *a, float *b) {
65 oil_memcpy(b, a, sizeof(float) * n);
68 static void float32ne_from_float32ne(unsigned n, const float *a, void *b) {
72 oil_memcpy(b, a, sizeof(float) * n);
75 static void ulaw_to_float32ne(unsigned n, const void *a, float *b) {
76 const uint8_t *ca = a;
82 *(b++) = st_ulaw2linear16(*(ca++)) * 1.0F / 0x7FFF;
85 static void ulaw_from_float32ne(unsigned n, const float *a, void *b) {
100 *(cb++) = st_14linear2ulaw((int16_t) (v * 0x1FFF));
104 static void alaw_to_float32ne(unsigned n, const void *a, float *b) {
105 const uint8_t *ca = a;
111 *(b++) = st_alaw2linear16(*(ca++)) * 1.0F / 0x7FFF;
114 static void alaw_from_float32ne(unsigned n, const float *a, void *b) {
129 *(cb++) = st_13linear2alaw((int16_t) (v * 0xFFF));
133 pa_convert_to_float32ne_func_t pa_get_convert_to_float32ne_function(pa_sample_format_t f) {
136 return u8_to_float32ne;
137 case PA_SAMPLE_S16LE:
138 return pa_sconv_s16le_to_float32ne;
139 case PA_SAMPLE_S16BE:
140 return pa_sconv_s16be_to_float32ne;
141 case PA_SAMPLE_FLOAT32NE:
142 return float32ne_to_float32ne;
144 return alaw_to_float32ne;
146 return ulaw_to_float32ne;
152 pa_convert_from_float32ne_func_t pa_get_convert_from_float32ne_function(pa_sample_format_t f) {
155 return u8_from_float32ne;
156 case PA_SAMPLE_S16LE:
157 return pa_sconv_s16le_from_float32ne;
158 case PA_SAMPLE_S16BE:
159 return pa_sconv_s16be_from_float32ne;
160 case PA_SAMPLE_FLOAT32NE:
161 return float32ne_from_float32ne;
163 return alaw_from_float32ne;
165 return ulaw_from_float32ne;