]> code.delx.au - pulseaudio/blob - src/polypcore/sconv-s16le.c
unhide padsp
[pulseaudio] / src / polypcore / sconv-s16le.c
1 /* $Id$ */
2
3 /***
4 This file is part of polypaudio.
5
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.
10
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.
15
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
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <assert.h>
27 #include <inttypes.h>
28
29 #include <liboil/liboilfuncs.h>
30
31 #include <polypcore/sconv.h>
32 #include <polypcore/log.h>
33
34 #include "endianmacros.h"
35
36 #include "sconv-s16le.h"
37
38 #ifndef INT16_FROM
39 #define INT16_FROM INT16_FROM_LE
40 #endif
41
42 #ifndef INT16_TO
43 #define INT16_TO INT16_TO_LE
44 #endif
45
46 #ifndef SWAP_WORDS
47 #ifdef WORDS_BIGENDIAN
48 #define SWAP_WORDS 1
49 #else
50 #define SWAP_WORDS 0
51 #endif
52 #endif
53
54 void pa_sconv_s16le_to_float32ne(unsigned n, const void *a, float *b) {
55 const int16_t *ca = a;
56
57 assert(a);
58 assert(b);
59
60 #if SWAP_WORDS == 1
61
62 for (; n > 0; n--) {
63 int16_t s = *(ca++);
64 *(b++) = ((float) INT16_FROM(s))/0x7FFF;
65 }
66
67 #else
68 {
69 static const double add = 0, factor = 1.0/0x7FFF;
70 oil_scaleconv_f32_s16(b, ca, n, &add, &factor);
71 }
72 #endif
73 }
74
75 void pa_sconv_s16le_from_float32ne(unsigned n, const float *a, void *b) {
76 int16_t *cb = b;
77
78 assert(a);
79 assert(b);
80
81 #if SWAP_WORDS == 1
82
83 for (; n > 0; n--) {
84 int16_t s;
85 float v = *(a++);
86
87 if (v > 1)
88 v = 1;
89
90 if (v < -1)
91 v = -1;
92
93 s = (int16_t) (v * 0x7FFF);
94 *(cb++) = INT16_TO(s);
95 }
96
97 #else
98 {
99 static const double add = 0, factor = 0x7FFF;
100 oil_scaleconv_s16_f32(cb, a, n, &add, &factor);
101 }
102 #endif
103 }