]>
code.delx.au - pulseaudio/blob - src/pulsecore/sconv-s16le.c
2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
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.
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.
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
26 /* Despite the name of this file we implement S32 and S24 handling here, too. */
31 #include <liboil/liboilfuncs.h>
33 #include <pulsecore/sconv.h>
34 #include <pulsecore/macro.h>
35 #include <pulsecore/log.h>
37 #include "endianmacros.h"
39 #include "sconv-s16le.h"
42 #define INT16_FROM PA_INT16_FROM_LE
46 #define INT16_TO PA_INT16_TO_LE
50 #define INT32_FROM PA_INT32_FROM_LE
54 #define INT32_TO PA_INT32_TO_LE
58 #define READ24 PA_READ24LE
62 #define WRITE24 PA_WRITE24LE
66 #ifdef WORDS_BIGENDIAN
73 void pa_sconv_s16le_to_float32ne(unsigned n
, const int16_t *a
, float *b
) {
81 *(b
++) = ((float) INT16_FROM(s
))/(float) 0x7FFF;
86 static const double add
= 0, factor
= 1.0/0x7FFF;
87 oil_scaleconv_f32_s16(b
, a
, (int) n
, &add
, &factor
);
92 void pa_sconv_s32le_to_float32ne(unsigned n
, const int32_t *a
, float *b
) {
100 *(b
++) = (float) (((double) INT32_FROM(s
))/0x7FFFFFFF);
105 static const double add
= 0, factor
= 1.0/0x7FFFFFFF;
106 oil_scaleconv_f32_s32(b
, a
, (int) n
, &add
, &factor
);
111 void pa_sconv_s16le_from_float32ne(unsigned n
, const float *a
, int16_t *b
) {
121 v
= PA_CLAMP_UNLIKELY(v
, -1.0f
, 1.f
);
122 s
= (int16_t) lrintf(v
* 0x7FFF);
123 *(b
++) = INT16_TO(s
);
128 static const double add
= 0, factor
= 0x7FFF;
129 oil_scaleconv_s16_f32(b
, a
, (int) n
, &add
, &factor
);
134 void pa_sconv_s32le_from_float32ne(unsigned n
, const float *a
, int32_t *b
) {
144 v
= PA_CLAMP_UNLIKELY(v
, -1.0f
, 1.0f
);
145 s
= (int32_t) lrint((double) v
* (double) 0x7FFFFFFF);
146 *(b
++) = INT32_TO(s
);
151 static const double add
= 0, factor
= 0x7FFFFFFF;
152 oil_scaleconv_s32_f32(b
, a
, (int) n
, &add
, &factor
);
157 void pa_sconv_s16le_to_float32re(unsigned n
, const int16_t *a
, float *b
) {
163 float k
= ((float) INT16_FROM(s
))/0x7FFF;
164 k
= PA_FLOAT32_SWAP(k
);
169 void pa_sconv_s32le_to_float32re(unsigned n
, const int32_t *a
, float *b
) {
175 float k
= (float) (((double) INT32_FROM(s
))/0x7FFFFFFF);
176 k
= PA_FLOAT32_SWAP(k
);
181 void pa_sconv_s16le_from_float32re(unsigned n
, const float *a
, int16_t *b
) {
188 v
= PA_FLOAT32_SWAP(v
);
189 v
= PA_CLAMP_UNLIKELY(v
, -1.0f
, 1.0f
);
190 s
= (int16_t) lrintf(v
* 0x7FFF);
191 *(b
++) = INT16_TO(s
);
195 void pa_sconv_s32le_from_float32re(unsigned n
, const float *a
, int32_t *b
) {
202 v
= PA_FLOAT32_SWAP(v
);
203 v
= PA_CLAMP_UNLIKELY(v
, -1.0f
, 1.0f
);
204 s
= (int32_t) lrint((double) v
* 0x7FFFFFFF);
205 *(b
++) = INT32_TO(s
);
209 void pa_sconv_s32le_to_s16ne(unsigned n
, const int32_t*a
, int16_t *b
) {
214 *b
= (int16_t) (INT32_FROM(*a
) >> 16);
220 void pa_sconv_s32le_to_s16re(unsigned n
, const int32_t*a
, int16_t *b
) {
225 int16_t s
= (int16_t) (INT32_FROM(*a
) >> 16);
226 *b
= PA_INT16_SWAP(s
);
232 void pa_sconv_s32le_from_s16ne(unsigned n
, const int16_t *a
, int32_t *b
) {
237 *b
= INT32_TO(((int32_t) *a
) << 16);
243 void pa_sconv_s32le_from_s16re(unsigned n
, const int16_t *a
, int32_t *b
) {
248 int32_t s
= ((int32_t) PA_INT16_SWAP(*a
)) << 16;
255 void pa_sconv_s24le_to_s16ne(unsigned n
, const uint8_t *a
, int16_t *b
) {
260 *b
= (int16_t) (READ24(a
) >> 8);
266 void pa_sconv_s24le_from_s16ne(unsigned n
, const int16_t *a
, uint8_t *b
) {
271 WRITE24(b
, ((uint32_t) *a
) << 8);
277 void pa_sconv_s24le_to_s16re(unsigned n
, const uint8_t *a
, int16_t *b
) {
282 int16_t s
= (int16_t) (READ24(a
) >> 8);
283 *b
= PA_INT16_SWAP(s
);
289 void pa_sconv_s24le_from_s16re(unsigned n
, const int16_t *a
, uint8_t *b
) {
294 uint32_t s
= ((uint32_t) PA_INT16_SWAP(*a
)) << 8;
301 void pa_sconv_s24le_to_float32ne(unsigned n
, const uint8_t *a
, float *b
) {
306 int32_t s
= READ24(a
) << 8;
307 *b
= ((float) s
) / 0x7FFFFFFF;
313 void pa_sconv_s24le_from_float32ne(unsigned n
, const float *a
, uint8_t *b
) {
320 v
= PA_CLAMP_UNLIKELY(v
, -1.0f
, 1.0f
);
321 s
= (int32_t) lrint((double) v
* (double) 0x7FFFFFFF);
322 WRITE24(b
, ((uint32_t) s
) >> 8);
328 void pa_sconv_s24le_to_float32re(unsigned n
, const uint8_t *a
, float *b
) {
333 int32_t s
= READ24(a
) << 8;
334 float k
= ((float) s
) / 0x7FFFFFFF;
335 *b
= PA_FLOAT32_SWAP(k
);
341 void pa_sconv_s24le_from_float32re(unsigned n
, const float *a
, uint8_t *b
) {
348 v
= PA_FLOAT32_SWAP(v
);
349 v
= PA_CLAMP_UNLIKELY(v
, -1.0f
, 1.0f
);
350 s
= (int32_t) lrint((double) v
* (double) 0x7FFFFFFF);
351 WRITE24(b
, ((uint32_t) s
) >> 8);