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 static const float scale = 1. / (32768. * 4096.);
67 for (i = 0; i < c; ++i) {
68 *dst++ = *src++ * scale;
72 void downmix_to_mono_i16_from_stereo_i16(int16_t *dst, const int16_t *src, size_t count)
75 *dst++ = (int16_t)(((int32_t)src[0] + (int32_t)src[1]) >> 1);
80 void upmix_to_stereo_i16_from_mono_i16(int16_t *dst, const int16_t *src, size_t count)
83 int32_t temp = *src++;