2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
15 #ifdef WEBRTC_ARCH_BIG_ENDIAN
19 #include "webrtc/typedefs.h"
21 #define HIGHEND 0xFF00
26 /* Encoder with int16_t Output */
27 int16_t WebRtcPcm16b_EncodeW16(const int16_t* speechIn16b,
28 int16_t length_samples,
29 int16_t* speechOut16b)
31 #ifdef WEBRTC_ARCH_BIG_ENDIAN
32 memcpy(speechOut16b, speechIn16b, length_samples * sizeof(int16_t));
35 for (i = 0; i < length_samples; i++) {
36 speechOut16b[i]=(((uint16_t)speechIn16b[i])>>8)|((((uint16_t)speechIn16b[i])<<8)&0xFF00);
39 return length_samples << 1;
43 /* Encoder with char Output (old version) */
44 int16_t WebRtcPcm16b_Encode(int16_t *speech16b,
46 unsigned char *speech8b)
48 int16_t samples=len*2;
52 for (pos=0;pos<len;pos++) {
53 short1=HIGHEND & speech16b[pos];
54 short2=LOWEND & speech16b[pos];
56 speech8b[pos*2]=(unsigned char) short1;
57 speech8b[pos*2+1]=(unsigned char) short2;
63 /* Decoder with int16_t Input instead of char when the int16_t Encoder is used */
64 int16_t WebRtcPcm16b_DecodeW16(int16_t *speechIn16b,
66 int16_t *speechOut16b,
69 #ifdef WEBRTC_ARCH_BIG_ENDIAN
70 memcpy(speechOut16b, speechIn16b, length_bytes);
73 int samples = length_bytes >> 1;
75 for (i=0;i<samples;i++) {
76 speechOut16b[i]=(((uint16_t)speechIn16b[i])>>8)|(((uint16_t)(speechIn16b[i]&0xFF))<<8);
82 return length_bytes >> 1;
85 /* "old" version of the decoder that uses char as input (not used in NetEq any more) */
86 int16_t WebRtcPcm16b_Decode(unsigned char *speech8b,
90 int16_t samples=len>>1;
93 for (pos=0;pos<samples;pos++) {
94 shortval=((unsigned short) speech8b[pos*2]);
95 shortval=(shortval<<8)&HIGHEND;
96 shortval=shortval|(((unsigned short) speech8b[pos*2+1])&LOWEND);
97 speech16b[pos]=shortval;