1
/* $Id: alaw_ulaw.h 2506 2009-03-12 18:11:37Z bennylp $ */
3
* Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
* Additional permission under GNU GPL version 3 section 7:
22
* If you modify this program, or any covered work, by linking or
23
* combining it with the OpenSSL project's OpenSSL library (or a
24
* modified version of that library), containing parts covered by the
25
* terms of the OpenSSL or SSLeay licenses, Teluu Inc. (http://www.teluu.com)
26
* grants you additional permission to convey the resulting work.
27
* Corresponding Source for a non-source form of such a combination
28
* shall include the source code for the parts of OpenSSL used as well
29
* as that of the covered work.
31
#ifndef __PJMEDIA_ALAW_ULAW_H__
32
#define __PJMEDIA_ALAW_ULAW_H__
34
#include <pjmedia/types.h>
38
#if defined(PJMEDIA_HAS_ALAW_ULAW_TABLE) && PJMEDIA_HAS_ALAW_ULAW_TABLE!=0
40
extern const pj_uint8_t pjmedia_linear2ulaw_tab[16384];
41
extern const pj_uint8_t pjmedia_linear2alaw_tab[16384];
42
extern const pj_int16_t pjmedia_ulaw2linear_tab[256];
43
extern const pj_int16_t pjmedia_alaw2linear_tab[256];
47
* Convert 16-bit linear PCM value to 8-bit A-Law.
49
* @param pcm_val 16-bit linear PCM value.
50
* @return 8-bit A-Law value.
52
#define pjmedia_linear2alaw(pcm_val) \
53
pjmedia_linear2alaw_tab[(((pj_int16_t)pcm_val) >> 2) & 0x3fff]
56
* Convert 8-bit A-Law value to 16-bit linear PCM value.
58
* @param chara_val 8-bit A-Law value.
59
* @return 16-bit linear PCM value.
61
#define pjmedia_alaw2linear(chara_val) \
62
pjmedia_alaw2linear_tab[chara_val]
65
* Convert 16-bit linear PCM value to 8-bit U-Law.
67
* @param pcm_val 16-bit linear PCM value.
68
* @return U-bit A-Law value.
70
#define pjmedia_linear2ulaw(pcm_val) \
71
pjmedia_linear2ulaw_tab[(((pj_int16_t)pcm_val) >> 2) & 0x3fff]
74
* Convert 8-bit U-Law value to 16-bit linear PCM value.
76
* @param u_val 8-bit U-Law value.
77
* @return 16-bit linear PCM value.
79
#define pjmedia_ulaw2linear(u_val) \
80
pjmedia_ulaw2linear_tab[u_val]
83
* Convert 8-bit A-Law value to 8-bit U-Law value.
85
* @param aval 8-bit A-Law value.
86
* @return 8-bit U-Law value.
88
#define pjmedia_alaw2ulaw(aval) \
89
pjmedia_linear2ulaw(pjmedia_alaw2linear(aval))
92
* Convert 8-bit U-Law value to 8-bit A-Law value.
94
* @param uval 8-bit U-Law value.
95
* @return 8-bit A-Law value.
97
#define pjmedia_ulaw2alaw(uval) \
98
pjmedia_linear2alaw(pjmedia_ulaw2linear(uval))
104
* Convert 16-bit linear PCM value to 8-bit A-Law.
106
* @param pcm_val 16-bit linear PCM value.
107
* @return 8-bit A-Law value.
109
PJ_DECL(pj_uint8_t) pjmedia_linear2alaw(int pcm_val);
112
* Convert 8-bit A-Law value to 16-bit linear PCM value.
114
* @param chara_val 8-bit A-Law value.
115
* @return 16-bit linear PCM value.
117
PJ_DECL(int) pjmedia_alaw2linear(unsigned chara_val);
120
* Convert 16-bit linear PCM value to 8-bit U-Law.
122
* @param pcm_val 16-bit linear PCM value.
123
* @return U-bit A-Law value.
125
PJ_DECL(unsigned char) pjmedia_linear2ulaw(int pcm_val);
128
* Convert 8-bit U-Law value to 16-bit linear PCM value.
130
* @param u_val 8-bit U-Law value.
131
* @return 16-bit linear PCM value.
133
PJ_DECL(int) pjmedia_ulaw2linear(unsigned char u_val);
136
* Convert 8-bit A-Law value to 8-bit U-Law value.
138
* @param aval 8-bit A-Law value.
139
* @return 8-bit U-Law value.
141
PJ_DECL(unsigned char) pjmedia_alaw2ulaw(unsigned char aval);
144
* Convert 8-bit U-Law value to 8-bit A-Law value.
146
* @param uval 8-bit U-Law value.
147
* @return 8-bit A-Law value.
149
PJ_DECL(unsigned char) pjmedia_ulaw2alaw(unsigned char uval);
154
* Encode 16-bit linear PCM data to 8-bit U-Law data.
156
* @param dst Destination buffer for 8-bit U-Law data.
157
* @param src Source, 16-bit linear PCM data.
158
* @param count Number of samples.
160
PJ_INLINE(void) pjmedia_ulaw_encode(pj_uint8_t *dst, const pj_int16_t *src,
163
const pj_int16_t *end = src + count;
166
*dst++ = pjmedia_linear2ulaw(*src++);
171
* Encode 16-bit linear PCM data to 8-bit A-Law data.
173
* @param dst Destination buffer for 8-bit A-Law data.
174
* @param src Source, 16-bit linear PCM data.
175
* @param count Number of samples.
177
PJ_INLINE(void) pjmedia_alaw_encode(pj_uint8_t *dst, const pj_int16_t *src,
180
const pj_int16_t *end = src + count;
183
*dst++ = pjmedia_linear2alaw(*src++);
188
* Decode 8-bit U-Law data to 16-bit linear PCM data.
190
* @param dst Destination buffer for 16-bit PCM data.
191
* @param src Source, 8-bit U-Law data.
192
* @param len Encoded frame/source length in bytes.
194
PJ_INLINE(void) pjmedia_ulaw_decode(pj_int16_t *dst, const pj_uint8_t *src,
197
const pj_uint8_t *end = src + len;
200
*dst++ = pjmedia_ulaw2linear(*src++);
205
* Decode 8-bit A-Law data to 16-bit linear PCM data.
207
* @param dst Destination buffer for 16-bit PCM data.
208
* @param src Source, 8-bit A-Law data.
209
* @param len Encoded frame/source length in bytes.
211
PJ_INLINE(void) pjmedia_alaw_decode(pj_int16_t *dst, const pj_uint8_t *src,
214
const pj_uint8_t *end = src + len;
217
*dst++ = pjmedia_alaw2linear(*src++);
223
#endif /* __PJMEDIA_ALAW_ULAW_H__ */