]> code.delx.au - pulseaudio/blob - src/pulsecore/sconv-s16le.c
Some strings done in German translation
[pulseaudio] / src / pulsecore / sconv-s16le.c
1 /***
2 This file is part of PulseAudio.
3
4 Copyright 2004-2006 Lennart Poettering
5
6 PulseAudio 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 PulseAudio 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 PulseAudio; 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 /* Despite the name of this file we implement S32 handling here, too. */
27
28 #include <inttypes.h>
29 #include <stdio.h>
30
31 #include <liboil/liboilfuncs.h>
32
33 #include <pulsecore/sconv.h>
34 #include <pulsecore/macro.h>
35 #include <pulsecore/log.h>
36
37 #include "endianmacros.h"
38
39 #include "sconv-s16le.h"
40
41 #ifndef INT16_FROM
42 #define INT16_FROM PA_INT16_FROM_LE
43 #endif
44
45 #ifndef INT16_TO
46 #define INT16_TO PA_INT16_TO_LE
47 #endif
48
49 #ifndef INT32_FROM
50 #define INT32_FROM PA_INT32_FROM_LE
51 #endif
52
53 #ifndef INT32_TO
54 #define INT32_TO PA_INT32_TO_LE
55 #endif
56
57 #ifndef SWAP_WORDS
58 #ifdef WORDS_BIGENDIAN
59 #define SWAP_WORDS 1
60 #else
61 #define SWAP_WORDS 0
62 #endif
63 #endif
64
65 void pa_sconv_s16le_to_float32ne(unsigned n, const int16_t *a, float *b) {
66 pa_assert(a);
67 pa_assert(b);
68
69 #if SWAP_WORDS == 1
70
71 for (; n > 0; n--) {
72 int16_t s = *(a++);
73 *(b++) = ((float) INT16_FROM(s))/(float) 0x7FFF;
74 }
75
76 #else
77 {
78 static const double add = 0, factor = 1.0/0x7FFF;
79 oil_scaleconv_f32_s16(b, a, (int) n, &add, &factor);
80 }
81 #endif
82 }
83
84 void pa_sconv_s32le_to_float32ne(unsigned n, const int32_t *a, float *b) {
85 pa_assert(a);
86 pa_assert(b);
87
88 #if SWAP_WORDS == 1
89
90 for (; n > 0; n--) {
91 int32_t s = *(a++);
92 *(b++) = (float) (((double) INT32_FROM(s))/0x7FFFFFFF);
93 }
94
95 #else
96 {
97 static const double add = 0, factor = 1.0/0x7FFFFFFF;
98 oil_scaleconv_f32_s32(b, a, (int) n, &add, &factor);
99 }
100 #endif
101 }
102
103 void pa_sconv_s16le_from_float32ne(unsigned n, const float *a, int16_t *b) {
104 pa_assert(a);
105 pa_assert(b);
106
107 #if SWAP_WORDS == 1
108
109 for (; n > 0; n--) {
110 int16_t s;
111 float v = *(a++);
112
113 v = PA_CLAMP_UNLIKELY(v, -1.0f, 1.f);
114 s = (int16_t) (v * 0x7FFF);
115 *(b++) = INT16_TO(s);
116 }
117
118 #else
119 {
120 static const double add = 0, factor = 0x7FFF;
121 oil_scaleconv_s16_f32(b, a, (int) n, &add, &factor);
122 }
123 #endif
124 }
125
126 void pa_sconv_s32le_from_float32ne(unsigned n, const float *a, int32_t *b) {
127 pa_assert(a);
128 pa_assert(b);
129
130 #if SWAP_WORDS == 1
131
132 for (; n > 0; n--) {
133 int32_t s;
134 float v = *(a++);
135
136 v = PA_CLAMP_UNLIKELY(v, -1.0f, 1.0f);
137 s = (int32_t) ((double) v * (double) 0x7FFFFFFF);
138 *(b++) = INT32_TO(s);
139 }
140
141 #else
142 {
143 static const double add = 0, factor = 0x7FFFFFFF;
144 oil_scaleconv_s32_f32(b, a, (int) n, &add, &factor);
145 }
146 #endif
147 }
148
149 void pa_sconv_s16le_to_float32re(unsigned n, const int16_t *a, float *b) {
150 pa_assert(a);
151 pa_assert(b);
152
153 for (; n > 0; n--) {
154 int16_t s = *(a++);
155 float k = ((float) INT16_FROM(s))/0x7FFF;
156 uint32_t *j = (uint32_t*) &k;
157 *j = PA_UINT32_SWAP(*j);
158 *(b++) = k;
159 }
160 }
161
162 void pa_sconv_s32le_to_float32re(unsigned n, const int32_t *a, float *b) {
163 pa_assert(a);
164 pa_assert(b);
165
166 for (; n > 0; n--) {
167 int32_t s = *(a++);
168 float k = (float) (((double) INT32_FROM(s))/0x7FFFFFFF);
169 uint32_t *j = (uint32_t*) &k;
170 *j = PA_UINT32_SWAP(*j);
171 *(b++) = k;
172 }
173 }
174
175 void pa_sconv_s16le_from_float32re(unsigned n, const float *a, int16_t *b) {
176 pa_assert(a);
177 pa_assert(b);
178
179 for (; n > 0; n--) {
180 int16_t s;
181 float v = *(a++);
182 uint32_t *j = (uint32_t*) &v;
183 *j = PA_UINT32_SWAP(*j);
184 v = PA_CLAMP_UNLIKELY(v, -1.0f, 1.0f);
185 s = (int16_t) (v * 0x7FFF);
186 *(b++) = INT16_TO(s);
187 }
188 }
189
190 void pa_sconv_s32le_from_float32re(unsigned n, const float *a, int32_t *b) {
191 pa_assert(a);
192 pa_assert(b);
193
194 for (; n > 0; n--) {
195 int32_t s;
196 float v = *(a++);
197 uint32_t *j = (uint32_t*) &v;
198 *j = PA_UINT32_SWAP(*j);
199 v = PA_CLAMP_UNLIKELY(v, -1.0f, 1.0f);
200 s = (int32_t) ((double) v * 0x7FFFFFFF);
201 *(b++) = INT32_TO(s);
202 }
203 }
204
205 void pa_sconv_s32le_to_s16ne(unsigned n, const int32_t*a, int16_t *b) {
206 pa_assert(a);
207 pa_assert(b);
208
209 for (; n > 0; n--) {
210 *b = (int16_t) (INT32_FROM(*a) >> 16);
211 a++;
212 b++;
213 }
214 }
215
216 void pa_sconv_s32le_to_s16re(unsigned n, const int32_t*a, int16_t *b) {
217 pa_assert(a);
218 pa_assert(b);
219
220 for (; n > 0; n--) {
221 int16_t s = (int16_t) (INT32_FROM(*a) >> 16);
222 *b = PA_INT16_SWAP(s);
223 a++;
224 b++;
225 }
226 }
227
228 void pa_sconv_s32le_from_s16ne(unsigned n, const int16_t *a, int32_t *b) {
229 pa_assert(a);
230 pa_assert(b);
231
232 for (; n > 0; n--) {
233 *b = INT32_TO(((int32_t) *a) << 16);
234 a++;
235 b++;
236 }
237 }
238
239 void pa_sconv_s32le_from_s16re(unsigned n, const int16_t *a, int32_t *b) {
240 pa_assert(a);
241 pa_assert(b);
242
243 for (; n > 0; n--) {
244 int32_t s = ((int32_t) PA_INT16_SWAP(*a)) << 16;
245 *b = INT32_TO(s);
246 a++;
247 b++;
248 }
249 }