]>
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 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 #ifdef WORDS_BIGENDIAN
65 void pa_sconv_s16le_to_float32ne(unsigned n
, const int16_t *a
, float *b
) {
73 *(b
++) = ((float) INT16_FROM(s
))/(float) 0x7FFF;
78 static const double add
= 0, factor
= 1.0/0x7FFF;
79 oil_scaleconv_f32_s16(b
, a
, (int) n
, &add
, &factor
);
84 void pa_sconv_s32le_to_float32ne(unsigned n
, const int32_t *a
, float *b
) {
92 *(b
++) = (float) (((double) INT32_FROM(s
))/0x7FFFFFFF);
97 static const double add
= 0, factor
= 1.0/0x7FFFFFFF;
98 oil_scaleconv_f32_s32(b
, a
, (int) n
, &add
, &factor
);
103 void pa_sconv_s16le_from_float32ne(unsigned n
, const float *a
, int16_t *b
) {
113 v
= PA_CLAMP_UNLIKELY(v
, -1.0f
, 1.f
);
114 s
= (int16_t) (v
* 0x7FFF);
115 *(b
++) = INT16_TO(s
);
120 static const double add
= 0, factor
= 0x7FFF;
121 oil_scaleconv_s16_f32(b
, a
, (int) n
, &add
, &factor
);
126 void pa_sconv_s32le_from_float32ne(unsigned n
, const float *a
, int32_t *b
) {
136 v
= PA_CLAMP_UNLIKELY(v
, -1.0f
, 1.0f
);
137 s
= (int32_t) ((double) v
* (double) 0x7FFFFFFF);
138 *(b
++) = INT32_TO(s
);
143 static const double add
= 0, factor
= 0x7FFFFFFF;
144 oil_scaleconv_s32_f32(b
, a
, (int) n
, &add
, &factor
);
149 void pa_sconv_s16le_to_float32re(unsigned n
, const int16_t *a
, float *b
) {
155 float k
= ((float) INT16_FROM(s
))/0x7FFF;
156 uint32_t *j
= (uint32_t*) &k
;
157 *j
= PA_UINT32_SWAP(*j
);
162 void pa_sconv_s32le_to_float32re(unsigned n
, const int32_t *a
, float *b
) {
168 float k
= (float) (((double) INT32_FROM(s
))/0x7FFFFFFF);
169 uint32_t *j
= (uint32_t*) &k
;
170 *j
= PA_UINT32_SWAP(*j
);
175 void pa_sconv_s16le_from_float32re(unsigned n
, const float *a
, int16_t *b
) {
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
);
190 void pa_sconv_s32le_from_float32re(unsigned n
, const float *a
, int32_t *b
) {
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
);
205 void pa_sconv_s32le_to_s16ne(unsigned n
, const int32_t*a
, int16_t *b
) {
210 *b
= (int16_t) (INT32_FROM(*a
) >> 16);
216 void pa_sconv_s32le_to_s16re(unsigned n
, const int32_t*a
, int16_t *b
) {
221 int16_t s
= (int16_t) (INT32_FROM(*a
) >> 16);
222 *b
= PA_INT16_SWAP(s
);
228 void pa_sconv_s32le_from_s16ne(unsigned n
, const int16_t *a
, int32_t *b
) {
233 *b
= INT32_TO(((int32_t) *a
) << 16);
239 void pa_sconv_s32le_from_s16re(unsigned n
, const int16_t *a
, int32_t *b
) {
244 int32_t s
= ((int32_t) PA_INT16_SWAP(*a
)) << 16;