1 /*
2  * SpanDSP - a series of DSP components for telephony
3  *
4  * g726.h - ITU G.726 codec.
5  *
6  * Written by Steve Underwood <steveu@coppice.org>
7  *
8  * Copyright (C) 2006 Steve Underwood
9  *
10  * All rights reserved.
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 2.1,
14  * as published by the Free Software Foundation.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this program; if not, write to the Free Software
23  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25 
26 /*! \file */
27 
28 #if !defined(_SPANDSP_G726_H_)
29 #define _SPANDSP_G726_H_
30 
31 /*! \page g726_page G.726 encoding and decoding
32 \section g726_page_sec_1 What does it do?
33 
34 The G.726 module is a bit exact implementation of the full ITU G.726 specification.
35 It supports:
36     - 16 kbps, 24kbps, 32kbps, and 40kbps operation.
37     - Tandem adjustment, for interworking with A-law and u-law.
38     - Annex A support, for use in environments not using A-law or u-law.
39 
40 It passes the ITU tests.
41 
42 \section g726_page_sec_2 How does it work?
43 ???.
44 */
45 
46 enum
47 {
48     G726_ENCODING_LINEAR = 0,   /* Interworking with 16 bit signed linear */
49     G726_ENCODING_ULAW,         /* Interworking with u-law */
50     G726_ENCODING_ALAW          /* Interworking with A-law */
51 };
52 
53 enum
54 {
55     G726_PACKING_NONE = 0,
56     G726_PACKING_LEFT = 1,
57     G726_PACKING_RIGHT = 2
58 };
59 
60 /*!
61     G.726 state
62  */
63 typedef struct g726_state_s g726_state_t;
64 
65 typedef int16_t (*g726_decoder_func_t)(g726_state_t *s, uint8_t code);
66 
67 typedef uint8_t (*g726_encoder_func_t)(g726_state_t *s, int16_t amp);
68 
69 #if defined(__cplusplus)
70 extern "C"
71 {
72 #endif
73 
74 /*! Initialise a G.726 encode or decode context.
75     \param s The G.726 context.
76     \param bit_rate The required bit rate for the ADPCM data.
77            The valid rates are 16000, 24000, 32000 and 40000.
78     \param ext_coding The coding used outside G.726.
79     \param packing One of the G.726_PACKING_xxx options.
80     \return A pointer to the G.726 context, or NULL for error. */
81 SPAN_DECLARE(g726_state_t *) g726_init(g726_state_t *s, int bit_rate, int ext_coding, int packing);
82 
83 /*! Release a G.726 encode or decode context.
84     \param s The G.726 context.
85     \return 0 for OK. */
86 SPAN_DECLARE(int) g726_release(g726_state_t *s);
87 
88 /*! Free a G.726 encode or decode context.
89     \param s The G.726 context.
90     \return 0 for OK. */
91 SPAN_DECLARE(int) g726_free(g726_state_t *s);
92 
93 /*! Decode a buffer of G.726 ADPCM data to linear PCM, a-law or u-law.
94     \param s The G.726 context.
95     \param amp The audio sample buffer.
96     \param g726_data
97     \param g726_bytes
98     \return The number of samples returned. */
99 SPAN_DECLARE(int) g726_decode(g726_state_t *s,
100                               int16_t amp[],
101                               const uint8_t g726_data[],
102                               int g726_bytes);
103 
104 /*! Encode a buffer of linear PCM data to G.726 ADPCM.
105     \param s The G.726 context.
106     \param g726_data The G.726 data produced.
107     \param amp The audio sample buffer.
108     \param len The number of samples in the buffer.
109     \return The number of bytes of G.726 data produced. */
110 SPAN_DECLARE(int) g726_encode(g726_state_t *s,
111                               uint8_t g726_data[],
112                               const int16_t amp[],
113                               int len);
114 
115 #if defined(__cplusplus)
116 }
117 #endif
118 
119 #endif
120 /*- End of file ------------------------------------------------------------*/
121