]>
code.delx.au - pulseaudio/blob - src/pulsecore/sconv-s16le.c
4 This file is part of PulseAudio.
6 Copyright 2004-2006 Lennart Poettering
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.
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.
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
28 /* Despite the name of this file we implement S32 handling here, too. */
33 #include <liboil/liboilfuncs.h>
35 #include <pulsecore/sconv.h>
36 #include <pulsecore/macro.h>
37 #include <pulsecore/log.h>
39 #include "endianmacros.h"
41 #include "sconv-s16le.h"
44 #define INT16_FROM PA_INT16_FROM_LE
48 #define INT16_TO PA_INT16_TO_LE
52 #define INT32_FROM PA_INT32_FROM_LE
56 #define INT32_TO PA_INT32_TO_LE
60 #ifdef WORDS_BIGENDIAN
67 void pa_sconv_s16le_to_float32ne(unsigned n
, const int16_t *a
, float *b
) {
75 *(b
++) = ((float) INT16_FROM(s
))/0x7FFF;
80 static const double add
= 0, factor
= 1.0/0x7FFF;
81 oil_scaleconv_f32_s16(b
, a
, n
, &add
, &factor
);
86 void pa_sconv_s32le_to_float32ne(unsigned n
, const int32_t *a
, float *b
) {
94 *(b
++) = (float) (((double) INT32_FROM(s
))/0x7FFFFFFF);
99 static const double add
= 0, factor
= 1.0/0x7FFFFFFF;
100 oil_scaleconv_f32_s32(b
, a
, n
, &add
, &factor
);
105 void pa_sconv_s16le_from_float32ne(unsigned n
, const float *a
, int16_t *b
) {
115 v
= PA_CLAMP_UNLIKELY(v
, -1, 1);
116 s
= (int16_t) (v
* 0x7FFF);
117 *(b
++) = INT16_TO(s
);
122 static const double add
= 0, factor
= 0x7FFF;
123 oil_scaleconv_s16_f32(b
, a
, n
, &add
, &factor
);
128 void pa_sconv_s32le_from_float32ne(unsigned n
, const float *a
, int32_t *b
) {
138 v
= PA_CLAMP_UNLIKELY(v
, -1, 1);
139 s
= (int32_t) ((double) v
* (double) 0x7FFFFFFF);
140 *(b
++) = INT32_TO(s
);
145 static const double add
= 0, factor
= 0x7FFFFFFF;
146 oil_scaleconv_s32_f32(b
, a
, n
, &add
, &factor
);
151 void pa_sconv_s16le_to_float32re(unsigned n
, const int16_t *a
, float *b
) {
157 float k
= ((float) INT16_FROM(s
))/0x7FFF;
158 uint32_t *j
= (uint32_t*) &k
;
159 *j
= PA_UINT32_SWAP(*j
);
164 void pa_sconv_s32le_to_float32re(unsigned n
, const int32_t *a
, float *b
) {
170 float k
= (float) (((double) INT32_FROM(s
))/0x7FFFFFFF);
171 uint32_t *j
= (uint32_t*) &k
;
172 *j
= PA_UINT32_SWAP(*j
);
177 void pa_sconv_s16le_from_float32re(unsigned n
, const float *a
, int16_t *b
) {
184 uint32_t *j
= (uint32_t*) &v
;
185 *j
= PA_UINT32_SWAP(*j
);
186 v
= PA_CLAMP_UNLIKELY(v
, -1, 1);
187 s
= (int16_t) (v
* 0x7FFF);
188 *(b
++) = INT16_TO(s
);
192 void pa_sconv_s32le_from_float32re(unsigned n
, const float *a
, int32_t *b
) {
199 uint32_t *j
= (uint32_t*) &v
;
200 *j
= PA_UINT32_SWAP(*j
);
201 v
= PA_CLAMP_UNLIKELY(v
, -1, 1);
202 s
= (int32_t) ((double) v
* 0x7FFFFFFF);
203 *(b
++) = INT32_TO(s
);
207 void pa_sconv_s32le_to_s16ne(unsigned n
, const int32_t*a
, int16_t *b
) {
212 *b
= (int16_t) (INT32_FROM(*a
) >> 16);
218 void pa_sconv_s32le_to_s16re(unsigned n
, const int32_t*a
, int16_t *b
) {
223 int16_t s
= (int16_t) (INT32_FROM(*a
) >> 16);
224 *b
= PA_UINT32_SWAP(s
);
230 void pa_sconv_s32le_from_s16ne(unsigned n
, const int16_t *a
, int32_t *b
) {
235 *b
= INT32_TO(((int32_t) *a
) << 16);
241 void pa_sconv_s32le_from_s16re(unsigned n
, const int16_t *a
, int32_t *b
) {
246 int32_t s
= ((int32_t) PA_UINT16_SWAP(*a
)) << 16;