1 #ifndef _PCM_H\r
2 #define _PCM_H\r
3 \r
4 /** \r
5 * @file pcm.h\r
6 * @brief Contains external API for PCM (G.711) encoder/decoder module.\r
7 *\r
8 * Copyright (c) 2007 \96 2013 Texas Instruments Incorporated
9 *
10 * All rights reserved not granted herein.
11 *
12 * Limited License.
13 *
14 * Texas Instruments Incorporated grants a world-wide, royalty-free,
15 * non-exclusive license under copyrights and patents it now or hereafter owns
16 * or controls to make, have made, use, import, offer to sell and sell
17 * ("Utilize") this software subject to the terms herein. With respect to the
18 * foregoing patent license, such license is granted solely to the extent that
19 * any such patent is necessary to Utilize the software alone. The patent
20 * license shall not apply to any combinations which include this software,
21 * other than combinations with devices manufactured by or for TI (\93TI
22 * Devices\94). No hardware patent is licensed hereunder.
23 *
24 * Redistributions must preserve existing copyright notices and reproduce this
25 * license (including the above copyright notice and the disclaimer and (if
26 * applicable) source code license limitations below) in the documentation
27 * and/or other materials provided with the distribution
28 *
29 * Redistribution and use in binary form, without modification, are permitted
30 * provided that the following conditions are met:
31 *
32 * * No reverse engineering, decompilation, or disassembly of this software
33 * is permitted with respect to any software provided in binary form.
34 *
35 * * any redistribution and use are licensed by TI for use only with TI
36 * Devices.
37 *
38 * * Nothing shall obligate TI to provide you with source code for the
39 * software licensed and provided to you in object code.
40 *
41 * If software source code is provided to you, modification and redistribution
42 * of the source code are permitted provided that the following conditions are
43 * met:
44 *
45 * * any redistribution and use of the source code, including any resulting
46 * derivative works, are licensed by TI for use only with TI Devices.
47 *
48 * * any redistribution and use of any object code compiled from the source
49 * code and any resulting derivative works, are licensed by TI for use only
50 * with TI Devices.
51 *
52 * Neither the name of Texas Instruments Incorporated nor the names of its
53 * suppliers may be used to endorse or promote products derived from this
54 * software without specific prior written permission.
55 *
56 * DISCLAIMER.
57 *
58 * THIS SOFTWARE IS PROVIDED BY TI AND TI\92S LICENSORS "AS IS" AND ANY EXPRESS
59 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
60 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
61 * DISCLAIMED. IN NO EVENT SHALL TI AND TI\92S LICENSORS BE LIABLE FOR ANY
62 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
63 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
64 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
65 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
68 * DAMAGE. \r
69 */\r
70 \r
71 #include <ti/mas/types/types.h> /* DSP types */\r
72 \r
73 /**\r
74 * @brief PCM mu-law encoder.\r
75 *\r
76 * @param[in] lin_in Input frame of 16-bit linear samples. \r
77 * For each linear sample, the 14 MSBs are taken to\r
78 * generate the mu-law codeword according to ITU-T \r
79 * G.711. The 2 LSBs are ignored.\r
80 * @param[in] frame_len Length of the input frame. It MUST be an integer\r
81 * multiple of 4. \r
82 * @param[out] ulaw_out Output frame of G.711 mu-law codewords. \r
83 * The codewords will be stored in an array of type \r
84 * "tword". The total number of elements in this array\r
85 * is frame_len. For CPUs with 16-bit machine word,\r
86 * each codeword will occupy the lower byte, as \r
87 * illustrated below (L = frame_len):\r
88 * @verbatim\r
89 * output buffer upper byte lower byte\r
90 * ulaw_out[0]: 0 ulaw(lin_in[0])\r
91 * ulaw_out[1]: 0 ulaw(lin_in[1])\r
92 * ulaw_out[2]: 0 ulaw(lin_in[2])\r
93 * ulaw_out[L-1]: 0 ulaw(lin_in[L-1])\r
94 * \endverbatim\r
95 * For CPUs with 8-bit machine word, each\r
96 * codeword occupies one byte, as illustrated below:\r
97 * @verbatim \r
98 * ulaw_out[0]: ulaw(lin_in[0])\r
99 * ulaw_out[1]: ulaw(lin_in[1])\r
100 * ulaw_out[2]: ulaw(lin_in[2])\r
101 * ulaw_out[L-1]: ulaw(lin_in[L-1])\r
102 * \endverbatim\r
103 */ \r
104 void pcmUlawEncoder(linSample *lin_in, tword *ulaw_out, tint frame_len);\r
105 \r
106 /** \r
107 * @brief PCM A-law encoder.\r
108 * @param[in] lin_in Input frame of 16-bit linear samples. \r
109 * For each linear sample, the 13 MSBs are taken to\r
110 * generate the A-law codeword according to ITU-T \r
111 * G.711. The 3 LSBs are ignored.\r
112 * @param[in] frame_len Length of the input frame. It MUST be an integer\r
113 * multiple of 4. \r
114 * @param[out] alaw_out Output frame of G.711 A-law codewords. Refer to\r
115 * pcmUlawEncoder() for output format. \r
116 */\r
117 void pcmAlawEncoder(linSample *lin_in, tword *alaw_out, tint frame_len);\r
118 \r
119 \r
120 /**\r
121 * @brief PCM mu-law decoder.\r
122 *\r
123 * @param[in] frame_len Length of the input frame. It MUST be an integer\r
124 * multiple of 4. \r
125 * @param[in] ulaw_in Input frame of G.711 mu-law codewords. \r
126 * The codewords must be provided in an array of type \r
127 * "tword". The total number of elements in this array\r
128 * is frame_len. For CPUs with 16-bit machine word,\r
129 * each codeword occupies the lower byte, as \r
130 * illustrated below (L = frame_len):\r
131 * @verbatim\r
132 * input buffer upper byte lower byte\r
133 * ulaw_in[0]: 0 ulaw codeword 0\r
134 * ulaw_in[1]: 0 ulaw codeword 1\r
135 * ulaw_in[2]: 0 ulaw codeword 2\r
136 * ulaw_in[L-1]: 0 ulaw codeword L-1\r
137 * \endverbatim\r
138 * For CPUs with 8-bit machine word, each\r
139 * codeword occupies one byte, as illustrated below:\r
140 * @verbatim \r
141 * ulaw_in[0]: ulaw codeword 0\r
142 * ulaw_in[1]: ulaw codeword 1\r
143 * ulaw_in[2]: ulaw codeword 2\r
144 * ulaw_in[L-1]: ulaw codeword L-1\r
145 * \endverbatim\r
146 * @param[out] lin_out Output frame of 16-bit linear samples. \r
147 * Each u-law codeword will be decoded according to \r
148 * ITU-T G.711 and the decoded value will be placed \r
149 * into the 14 MSBs of each linear sample. The 2 LSBs \r
150 * will be filled with 0's. \r
151 */ \r
152 void pcmUlawDecoder(tword *ulaw_in, linSample *lin_out, tint frame_len);\r
153 \r
154 /**\r
155 * @brief PCM A-law decoder.\r
156 *\r
157 * @param[in] frame_len Length of the input frame. It MUST be an integer\r
158 * multiple of 4. \r
159 * @param[in] alaw_in Input frame of G.711 A-law codewords. \r
160 * The codewords must be provided in an array of type \r
161 * "tword". The total number of elements in this array\r
162 * is frame_len. For input format, refer to \r
163 * pcmUlawDecoder().\r
164 * @param[out] lin_out Output frame of 16-bit linear samples. \r
165 * Each A-law codeword will be decoded according to \r
166 * ITU-T G.711 and the decoded value will be placed \r
167 * into the 13 MSBs of each linear sample. The 3 LSBs \r
168 * will be filled with 0's. \r
169 */ \r
170 void pcmAlawDecoder(tword *alaw_in, linSample *lin_out, tint frame_len);\r
171 \r
172 /**\r
173 * @brief PCM mu-law encoder with packed output codewords.\r
174 *\r
175 * @param[in] frame_len Length of the input frame. It MUST be an integer\r
176 * multiple of 4. \r
177 * @param[in] lin_in Input frame of 16-bit linear samples. \r
178 * Refer to pcmUlawEncoder() for input format.\r
179 * @param[out] ulaw_out Output frame of G.711 mu-law codewords. \r
180 * The codewords will be packed and stored in an array\r
181 * of type "tuint" in big endian format, as \r
182 * illustrated below (L = frame_len):\r
183 * @verbatim\r
184 * output buffer upper byte lower byte\r
185 * ulaw_out[0]: ulaw(lin_in[0]) ulaw(lin_in[1])\r
186 * ulaw_out[1]: ulaw(lin_in[2]) ulaw(lin_in[3])\r
187 * ulaw_out[2]: ulaw(lin_in[4]) ulaw(lin_in[5])\r
188 * ulaw_out[L/2-1]: ulaw(lin_in[L-2]) ulaw(lin_in[L-1])\r
189 * \endverbatim\r
190 */ \r
191 void pcmUlawEncoderP(linSample *lin_in, tuint *ulaw_out, tint frame_len);\r
192 \r
193 /** \r
194 * @brief PCM A-law encoder with packed output codewords.\r
195 *\r
196 * @param[in] frame_len Length of the input frame. It MUST be an integer\r
197 * multiple of 4. \r
198 * @param[in] lin_in Input frame of 16-bit linear samples. \r
199 * Refer to pcmAlawEncoder() for input format.\r
200 * @param[out] alaw_out Output frame of G.711 A-law codewords. Refer to\r
201 * pcmUlawEncoderP() for output format. \r
202 */\r
203 void pcmAlawEncoderP(linSample *lin_in, tuint *alaw_out, tint frame_len);\r
204 \r
205 /**\r
206 * @brief PCM mu-law decoder with packed input codewords.\r
207 *\r
208 * @param[in] frame_len Length of the input frame, ie. the number of mu-law \r
209 * codewords to be decoded. It MUST be an integer\r
210 * multiple of 4. \r
211 * @param[in] ulaw_in Input frame of G.711 mu-law codewords. \r
212 * The codewords must be packed and stored in an array\r
213 * of type "tuint" in big endian format,\r
214 * as illustrated below (L = frame_len):\r
215 * @verbatim \r
216 * input buffer upper byte lower byte\r
217 * ulaw_in[0]: ulaw codeword 0 ulaw codeword 1\r
218 * ulaw_in[1]: ulaw codeword 2 ulaw codeword 3\r
219 * ulaw_in[2]: ulaw codeword 4 ulaw codeword 5\r
220 * ulaw_in[L/2-1]: ulaw codeword L-2 ulaw codeword L-1\r
221 * \endverbatim\r
222 * @param[out] lin_out Output frame of 16-bit linear samples. \r
223 * Refer to pcmUlawDecoder() for output format.\r
224 */ \r
225 void pcmUlawDecoderP(tuint *ulaw_in, linSample *lin_out, tint frame_len);\r
226 \r
227 /**\r
228 * @brief PCM A-law decoder with packed input codewords.\r
229 *\r
230 * @param[in] frame_len Length of the input frame, ie. the number of A-law \r
231 * codewords to be decoded. It MUST be an integer\r
232 * multiple of 4. \r
233 * @param[in] alaw_in Input frame of G.711 A-law codewords. \r
234 * The codewords must be packed and stored in an array\r
235 * of type "tuint" in big endian format. Refer to \r
236 * pcmUlawDecoderP() for format. \r
237 * @param[out] lin_out Output frame of 16-bit linear samples. Linear sample\r
238 * value of 32767 corresponds to load capacity of \r
239 * 3.17dBm0 according to ITU-T G.711. \r
240 */ \r
241 void pcmAlawDecoderP(tuint *alaw_in, linSample *lin_out, tint frame_len);\r
242 \r
243 #endif\r
244 /* Nothing past this point */\r