2 * Copyright (C) 2011 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <audio_utils/primitives.h>
19 void ditherAndClamp(int32_t* out, const int32_t *sums, size_t c)
22 for (i=0 ; i<c ; i++) {
29 *out++ = (r<<16) | (l & 0xFFFF);
33 void memcpy_to_i16_from_u8(int16_t *dst, const uint8_t *src, size_t count)
38 *--dst = (int16_t)(*--src - 0x80) << 8;
42 void memcpy_to_u8_from_i16(uint8_t *dst, const int16_t *src, size_t count)
45 *dst++ = (*src++ >> 8) + 0x80;
49 void memcpy_to_i16_from_i32(int16_t *dst, const int32_t *src, size_t count)
52 *dst++ = *src++ >> 16;
56 void memcpy_to_i16_from_float(int16_t *dst, const float *src, size_t count)
59 *dst++ = clamp16FromFloat(*src++);
63 void memcpy_to_float_from_q19_12(float *dst, const int32_t *src, size_t c)
66 for (i = 0; i < c; ++i) {
67 *dst++ = float_from_q19_12(*src++);
71 void memcpy_to_float_from_i16(float *dst, const int16_t *src, size_t count)
74 *dst++ = float_from_i16(*src++);
78 void memcpy_to_float_from_p24(float *dst, const uint8_t *src, size_t count)
81 *dst++ = float_from_p24(src);
86 void memcpy_to_i16_from_p24(int16_t *dst, const uint8_t *src, size_t count)
89 #ifdef HAVE_BIG_ENDIAN
90 *dst++ = src[1] | (src[0] << 8);
92 *dst++ = src[1] | (src[2] << 8);
98 void memcpy_to_p24_from_i16(uint8_t *dst, const int16_t *src, size_t count)
101 #ifdef HAVE_BIG_ENDIAN
108 *dst++ = *src++ >> 8;
113 void memcpy_to_p24_from_float(uint8_t *dst, const float *src, size_t count)
116 int32_t ival = clamp24_from_float(*src++);
118 #ifdef HAVE_BIG_ENDIAN
130 void downmix_to_mono_i16_from_stereo_i16(int16_t *dst, const int16_t *src, size_t count)
133 *dst++ = (int16_t)(((int32_t)src[0] + (int32_t)src[1]) >> 1);
138 void upmix_to_stereo_i16_from_mono_i16(int16_t *dst, const int16_t *src, size_t count)
141 int32_t temp = *src++;
148 size_t nonZeroMono32(const int32_t *samples, size_t count)
151 while (count-- > 0) {
152 if (*samples++ != 0) {
159 size_t nonZeroMono16(const int16_t *samples, size_t count)
162 while (count-- > 0) {
163 if (*samples++ != 0) {
170 size_t nonZeroStereo32(const int32_t *frames, size_t count)
173 while (count-- > 0) {
174 if (frames[0] != 0 || frames[1] != 0) {
182 size_t nonZeroStereo16(const int16_t *frames, size_t count)
185 while (count-- > 0) {
186 if (frames[0] != 0 || frames[1] != 0) {