spandsp  0.0.6
g726.h
Go to the documentation of this file.
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 ------------------------------------------------------------*/
g726_state_s::yu
int16_t yu
Definition: private/g726.h:52
g726_state_s::bits_per_sample
int bits_per_sample
Definition: private/g726.h:45
g726_state_s::enc_func
g726_encoder_func_t enc_func
The current encoder function.
Definition: private/g726.h:79
g726_state_s::dms
int16_t dms
Definition: private/g726.h:54
g726_state_s::ext_coding
int ext_coding
Definition: private/g726.h:43
g726_release
int g726_release(g726_state_t *s)
Definition: g726.c:1058
g722_decode_init
g722_decode_state_t * g722_decode_init(g722_decode_state_t *s, int rate, int options)
Definition: g722.c:256
g726_decode
int g726_decode(g726_state_t *s, int16_t amp[], const uint8_t g726_data[], int g726_bytes)
Definition: g726.c:1071
dds_phase_ratef
int32_t dds_phase_ratef(float frequency)
Find the phase rate equivalent to a frequency, in Hz.
Definition: dds_float.c:2109
g726_state_s::dec_func
g726_decoder_func_t dec_func
The current decoder function.
Definition: private/g726.h:81
g722_decode_state_s::itu_test_mode
int itu_test_mode
Definition: private/g722.h:87
g726_state_s::bs
bitstream_state_t bs
The bit stream processing context.
Definition: private/g726.h:76
g726_state_s
Definition: private/g726.h:39
power_meter_update
int32_t power_meter_update(power_meter_t *s, int16_t amp)
Update a power meter.
Definition: power_meter.c:84
g726_state_s::a
int16_t a[2]
Definition: private/g726.h:61
g711.h
g726_state_s::pk
int16_t pk[2]
Definition: private/g726.h:65
g726_decode
int g726_decode(g726_state_t *s, int16_t amp[], const uint8_t g726_data[], int g726_bytes)
Definition: g726.c:1071
power_meter_t
Definition: power_meter.h:49
g726_init
g726_state_t * g726_init(g726_state_t *s, int bit_rate, int ext_coding, int packing)
Definition: g726.c:998
g726_state_s::yl
int32_t yl
Definition: private/g726.h:50
g722_encode
int g722_encode(g722_encode_state_t *s, uint8_t g722_data[], const int16_t amp[], int len)
Definition: g722.c:476
bitstream_state_s::bitstream
uint32_t bitstream
Definition: private/bitstream.h:33
g726_init
g726_state_t * g726_init(g726_state_t *s, int bit_rate, int ext_coding, int packing)
Definition: g726.c:998
g726_state_s::rate
int rate
Definition: private/g726.h:41
g722.h
bit_operations.h
dc_restore.h
g722_decode_state_s
Definition: private/g722.h:84
g726_encode
int g726_encode(g726_state_t *s, uint8_t g726_data[], const int16_t amp[], int len)
Definition: g726.c:1127
g726_state_s::packing
int packing
Definition: private/g726.h:47
dds_modf
float dds_modf(uint32_t *phase_acc, int32_t phase_rate, float scale, int32_t phase)
Generate a floating point tone sample, with modulation.
Definition: dds_float.c:2155
g726_release
int g726_release(g726_state_t *s)
Definition: g726.c:1058
g726_state_s::b
int16_t b[6]
Definition: private/g726.h:63
g722_encode_state_s
Definition: private/g722.h:56
g726.h
bitstream.h
g726_state_s::dml
int16_t dml
Definition: private/g726.h:56
swept_tone_state_s
Definition: private/swept_tone.h:30
g726_state_s::ap
int16_t ap
Definition: private/g726.h:58
g726_free
int g726_free(g726_state_t *s)
Definition: g726.c:1064
bitstream_init
bitstream_state_t * bitstream_init(bitstream_state_t *s, int lsb_first)
Initialise a bitstream context.
Definition: bitstream.c:131
g726_free
int g726_free(g726_state_t *s)
Definition: g726.c:1064
g726_state_s::dq
int16_t dq[6]
Definition: private/g726.h:68
g722_decode
int g722_decode(g722_decode_state_t *s, int16_t amp[], const uint8_t g722_data[], int len)
Definition: g722.c:295
g722_encode_init
g722_encode_state_t * g722_encode_init(g722_encode_state_t *s, int rate, int options)
Definition: g722.c:437
g722_encode_state_s::itu_test_mode
int itu_test_mode
Definition: private/g722.h:59
power_meter_init
power_meter_t * power_meter_init(power_meter_t *s, int shift)
Initialise a power meter context.
Definition: power_meter.c:50
bitstream_state_s::residue
int residue
Definition: private/bitstream.h:35
dds_scaling_dbm0f
float dds_scaling_dbm0f(float level)
Find the scaling factor equivalent to a dBm0 value.
Definition: dds_float.c:2121
g726_state_s::td
int td
Definition: private/g726.h:73
g726_encode
int g726_encode(g726_state_t *s, uint8_t g726_data[], const int16_t amp[], int len)
Definition: g726.c:1127
g726_state_s::sr
int16_t sr[2]
Definition: private/g726.h:71