]> code.delx.au - pulseaudio/blob - src/pulsecore/sconv-s16le.c
5f45ef66d46cc9286eb0f807f80036561709ec8b
[pulseaudio] / src / pulsecore / sconv-s16le.c
1 /* $Id$ */
2
3 /***
4 This file is part of PulseAudio.
5
6 Copyright 2004-2006 Lennart Poettering
7
8 PulseAudio is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published
10 by the Free Software Foundation; either version 2 of the License,
11 or (at your option) any later version.
12
13 PulseAudio is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with PulseAudio; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 USA.
22 ***/
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <assert.h>
29 #include <inttypes.h>
30
31 #include <liboil/liboilfuncs.h>
32
33 #include <pulsecore/sconv.h>
34 #include <pulsecore/log.h>
35
36 #include "endianmacros.h"
37
38 #include "sconv-s16le.h"
39
40 #ifndef INT16_FROM
41 #define INT16_FROM INT16_FROM_LE
42 #endif
43
44 #ifndef INT16_TO
45 #define INT16_TO INT16_TO_LE
46 #endif
47
48 #ifndef SWAP_WORDS
49 #ifdef WORDS_BIGENDIAN
50 #define SWAP_WORDS 1
51 #else
52 #define SWAP_WORDS 0
53 #endif
54 #endif
55
56 void pa_sconv_s16le_to_float32ne(unsigned n, const void *a, float *b) {
57 const int16_t *ca = a;
58
59 assert(a);
60 assert(b);
61
62 #if SWAP_WORDS == 1
63
64 for (; n > 0; n--) {
65 int16_t s = *(ca++);
66 *(b++) = ((float) INT16_FROM(s))/0x7FFF;
67 }
68
69 #else
70 {
71 static const double add = 0, factor = 1.0/0x7FFF;
72 oil_scaleconv_f32_s16(b, ca, n, &add, &factor);
73 }
74 #endif
75 }
76
77 void pa_sconv_s16le_from_float32ne(unsigned n, const float *a, void *b) {
78 int16_t *cb = b;
79
80 assert(a);
81 assert(b);
82
83 #if SWAP_WORDS == 1
84
85 for (; n > 0; n--) {
86 int16_t s;
87 float v = *(a++);
88
89 if (v > 1)
90 v = 1;
91
92 if (v < -1)
93 v = -1;
94
95 s = (int16_t) (v * 0x7FFF);
96 *(cb++) = INT16_TO(s);
97 }
98
99 #else
100 {
101 static const double add = 0, factor = 0x7FFF;
102 oil_scaleconv_s16_f32(cb, a, n, &add, &factor);
103 }
104 #endif
105 }