blob: 0cff5dd29d1d18909d9f34e0aa43c4641d739a6c [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
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.
9 */
10
11
12#include "pcm16b.h"
13
turajs@google.com74c640a2011-08-30 20:44:24 +000014#include <stdlib.h>
15
niklase@google.com470e71d2011-07-07 08:21:25 +000016#include "typedefs.h"
17
18#ifdef WEBRTC_BIG_ENDIAN
19#include "signal_processing_library.h"
20#endif
21
22#define HIGHEND 0xFF00
23#define LOWEND 0xFF
24
25
26
27/* Encoder with WebRtc_Word16 Output */
28WebRtc_Word16 WebRtcPcm16b_EncodeW16(WebRtc_Word16 *speechIn16b,
29 WebRtc_Word16 len,
30 WebRtc_Word16 *speechOut16b)
31{
32#ifdef WEBRTC_BIG_ENDIAN
33 WEBRTC_SPL_MEMCPY_W16(speechOut16b, speechIn16b, len);
34#else
35 int i;
36 for (i=0;i<len;i++) {
37 speechOut16b[i]=(((WebRtc_UWord16)speechIn16b[i])>>8)|((((WebRtc_UWord16)speechIn16b[i])<<8)&0xFF00);
38 }
39#endif
40 return(len<<1);
41}
42
43
44/* Encoder with char Output (old version) */
45WebRtc_Word16 WebRtcPcm16b_Encode(WebRtc_Word16 *speech16b,
46 WebRtc_Word16 len,
47 unsigned char *speech8b)
48{
49 WebRtc_Word16 samples=len*2;
50 WebRtc_Word16 pos;
51 WebRtc_Word16 short1;
52 WebRtc_Word16 short2;
53 for (pos=0;pos<len;pos++) {
54 short1=HIGHEND & speech16b[pos];
55 short2=LOWEND & speech16b[pos];
56 short1=short1>>8;
57 speech8b[pos*2]=(unsigned char) short1;
58 speech8b[pos*2+1]=(unsigned char) short2;
59 }
60 return(samples);
61}
62
63
64/* Decoder with WebRtc_Word16 Input instead of char when the WebRtc_Word16 Encoder is used */
65WebRtc_Word16 WebRtcPcm16b_DecodeW16(void *inst,
66 WebRtc_Word16 *speechIn16b,
67 WebRtc_Word16 len,
68 WebRtc_Word16 *speechOut16b,
69 WebRtc_Word16* speechType)
70{
71#ifdef WEBRTC_BIG_ENDIAN
72 WEBRTC_SPL_MEMCPY_W8(speechOut16b, speechIn16b, ((len*sizeof(WebRtc_Word16)+1)>>1));
73#else
74 int i;
75 int samples=len>>1;
76
77 for (i=0;i<samples;i++) {
78 speechOut16b[i]=(((WebRtc_UWord16)speechIn16b[i])>>8)|(((WebRtc_UWord16)(speechIn16b[i]&0xFF))<<8);
79 }
80#endif
81
82 *speechType=1;
tommi@webrtc.orgc7d5f622011-08-31 12:11:24 +000083
84 // Avoid warning.
85 (void)(inst = NULL);
86
niklase@google.com470e71d2011-07-07 08:21:25 +000087 return(len>>1);
88}
89
90/* "old" version of the decoder that uses char as input (not used in NetEq any more) */
91WebRtc_Word16 WebRtcPcm16b_Decode(unsigned char *speech8b,
92 WebRtc_Word16 len,
93 WebRtc_Word16 *speech16b)
94{
95 WebRtc_Word16 samples=len>>1;
96 WebRtc_Word16 pos;
97 WebRtc_Word16 shortval;
98 for (pos=0;pos<samples;pos++) {
99 shortval=((unsigned short) speech8b[pos*2]);
100 shortval=(shortval<<8)&HIGHEND;
101 shortval=shortval|(((unsigned short) speech8b[pos*2+1])&LOWEND);
102 speech16b[pos]=shortval;
103 }
104 return(samples);
105}