~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to sflphone-common/libs/pjproject/pjmedia/include/pjmedia/alaw_ulaw.h

  • Committer: Package Import Robot
  • Author(s): Francois Marier
  • Date: 2011-11-25 13:24:12 UTC
  • mfrom: (4.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20111125132412-dc4qvhyosk74cd42
Tags: 1.0.1-4
Don't assume that arch:all packages will get built (closes: #649726)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: alaw_ulaw.h 2506 2009-03-12 18:11:37Z bennylp $ */
2
 
/* 
3
 
 * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
4
 
 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5
 
 *
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.
10
 
 *
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.
15
 
 *
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 
19
 
 *
20
 
 *  Additional permission under GNU GPL version 3 section 7:
21
 
 *
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.
30
 
 */
31
 
#ifndef __PJMEDIA_ALAW_ULAW_H__
32
 
#define __PJMEDIA_ALAW_ULAW_H__
33
 
 
34
 
#include <pjmedia/types.h>
35
 
 
36
 
PJ_BEGIN_DECL
37
 
 
38
 
#if defined(PJMEDIA_HAS_ALAW_ULAW_TABLE) && PJMEDIA_HAS_ALAW_ULAW_TABLE!=0
39
 
 
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];
44
 
 
45
 
 
46
 
/**
47
 
 * Convert 16-bit linear PCM value to 8-bit A-Law.
48
 
 *
49
 
 * @param pcm_val   16-bit linear PCM value.
50
 
 * @return          8-bit A-Law value.
51
 
 */
52
 
#define pjmedia_linear2alaw(pcm_val)    \
53
 
            pjmedia_linear2alaw_tab[(((pj_int16_t)pcm_val) >> 2) & 0x3fff]
54
 
 
55
 
/**
56
 
 * Convert 8-bit A-Law value to 16-bit linear PCM value.
57
 
 *
58
 
 * @param chara_val 8-bit A-Law value.
59
 
 * @return          16-bit linear PCM value.
60
 
 */
61
 
#define pjmedia_alaw2linear(chara_val)  \
62
 
            pjmedia_alaw2linear_tab[chara_val]
63
 
 
64
 
/**
65
 
 * Convert 16-bit linear PCM value to 8-bit U-Law.
66
 
 *
67
 
 * @param pcm_val   16-bit linear PCM value.
68
 
 * @return          U-bit A-Law value.
69
 
 */
70
 
#define pjmedia_linear2ulaw(pcm_val)    \
71
 
            pjmedia_linear2ulaw_tab[(((pj_int16_t)pcm_val) >> 2) & 0x3fff]
72
 
 
73
 
/**
74
 
 * Convert 8-bit U-Law value to 16-bit linear PCM value.
75
 
 *
76
 
 * @param u_val     8-bit U-Law value.
77
 
 * @return          16-bit linear PCM value.
78
 
 */
79
 
#define pjmedia_ulaw2linear(u_val)      \
80
 
            pjmedia_ulaw2linear_tab[u_val]
81
 
 
82
 
/**
83
 
 * Convert 8-bit A-Law value to 8-bit U-Law value.
84
 
 *
85
 
 * @param aval      8-bit A-Law value.
86
 
 * @return          8-bit U-Law value.
87
 
 */
88
 
#define pjmedia_alaw2ulaw(aval)         \
89
 
            pjmedia_linear2ulaw(pjmedia_alaw2linear(aval))
90
 
 
91
 
/**
92
 
 * Convert 8-bit U-Law value to 8-bit A-Law value.
93
 
 *
94
 
 * @param uval      8-bit U-Law value.
95
 
 * @return          8-bit A-Law value.
96
 
 */
97
 
#define pjmedia_ulaw2alaw(uval)         \
98
 
            pjmedia_linear2alaw(pjmedia_ulaw2linear(uval))
99
 
 
100
 
 
101
 
#else
102
 
 
103
 
/**
104
 
 * Convert 16-bit linear PCM value to 8-bit A-Law.
105
 
 *
106
 
 * @param pcm_val   16-bit linear PCM value.
107
 
 * @return          8-bit A-Law value.
108
 
 */
109
 
PJ_DECL(pj_uint8_t) pjmedia_linear2alaw(int pcm_val);
110
 
 
111
 
/**
112
 
 * Convert 8-bit A-Law value to 16-bit linear PCM value.
113
 
 *
114
 
 * @param chara_val 8-bit A-Law value.
115
 
 * @return          16-bit linear PCM value.
116
 
 */
117
 
PJ_DECL(int) pjmedia_alaw2linear(unsigned chara_val);
118
 
 
119
 
/**
120
 
 * Convert 16-bit linear PCM value to 8-bit U-Law.
121
 
 *
122
 
 * @param pcm_val   16-bit linear PCM value.
123
 
 * @return          U-bit A-Law value.
124
 
 */
125
 
PJ_DECL(unsigned char) pjmedia_linear2ulaw(int pcm_val);
126
 
 
127
 
/**
128
 
 * Convert 8-bit U-Law value to 16-bit linear PCM value.
129
 
 *
130
 
 * @param u_val     8-bit U-Law value.
131
 
 * @return          16-bit linear PCM value.
132
 
 */
133
 
PJ_DECL(int) pjmedia_ulaw2linear(unsigned char u_val);
134
 
 
135
 
/**
136
 
 * Convert 8-bit A-Law value to 8-bit U-Law value.
137
 
 *
138
 
 * @param aval      8-bit A-Law value.
139
 
 * @return          8-bit U-Law value.
140
 
 */
141
 
PJ_DECL(unsigned char) pjmedia_alaw2ulaw(unsigned char aval);
142
 
 
143
 
/**
144
 
 * Convert 8-bit U-Law value to 8-bit A-Law value.
145
 
 *
146
 
 * @param uval      8-bit U-Law value.
147
 
 * @return          8-bit A-Law value.
148
 
 */
149
 
PJ_DECL(unsigned char) pjmedia_ulaw2alaw(unsigned char uval);
150
 
 
151
 
#endif
152
 
 
153
 
/**
154
 
 * Encode 16-bit linear PCM data to 8-bit U-Law data.
155
 
 *
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.
159
 
 */
160
 
PJ_INLINE(void) pjmedia_ulaw_encode(pj_uint8_t *dst, const pj_int16_t *src, 
161
 
                                    pj_size_t count)
162
 
{
163
 
    const pj_int16_t *end = src + count;
164
 
    
165
 
    while (src < end) {
166
 
        *dst++ = pjmedia_linear2ulaw(*src++);
167
 
    }
168
 
}
169
 
 
170
 
/**
171
 
 * Encode 16-bit linear PCM data to 8-bit A-Law data.
172
 
 *
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.
176
 
 */
177
 
PJ_INLINE(void) pjmedia_alaw_encode(pj_uint8_t *dst, const pj_int16_t *src, 
178
 
                                    pj_size_t count)
179
 
{
180
 
    const pj_int16_t *end = src + count;
181
 
    
182
 
    while (src < end) {
183
 
        *dst++ = pjmedia_linear2alaw(*src++);
184
 
    }
185
 
}
186
 
 
187
 
/**
188
 
 * Decode 8-bit U-Law data to 16-bit linear PCM data.
189
 
 *
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.
193
 
 */
194
 
PJ_INLINE(void) pjmedia_ulaw_decode(pj_int16_t *dst, const pj_uint8_t *src, 
195
 
                                    pj_size_t len)
196
 
{
197
 
    const pj_uint8_t *end = src + len;
198
 
    
199
 
    while (src < end) {
200
 
        *dst++ = pjmedia_ulaw2linear(*src++);
201
 
    }
202
 
}
203
 
 
204
 
/**
205
 
 * Decode 8-bit A-Law data to 16-bit linear PCM data.
206
 
 *
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.
210
 
 */
211
 
PJ_INLINE(void) pjmedia_alaw_decode(pj_int16_t *dst, const pj_uint8_t *src, 
212
 
                                    pj_size_t len)
213
 
{
214
 
    const pj_uint8_t *end = src + len;
215
 
    
216
 
    while (src < end) {
217
 
        *dst++ = pjmedia_alaw2linear(*src++);
218
 
    }
219
 
}
220
 
 
221
 
PJ_END_DECL
222
 
 
223
 
#endif  /* __PJMEDIA_ALAW_ULAW_H__ */
224