spandsp: gsm0610.h Source File

spandsp 0.0.6

gsm0610.h
1/*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * gsm0610.h - GSM 06.10 full rate speech 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#if !defined(_SPANDSP_GSM0610_H_)
27#define _SPANDSP_GSM0610_H_
28
29/*! \page gsm0610_page GSM 06.10 encoding and decoding
30\section gsm0610_page_sec_1 What does it do?
31
32The GSM 06.10 module is an version of the widely used GSM FR codec software
33available from http://kbs.cs.tu-berlin.de/~jutta/toast.html. This version
34was produced since some versions of this codec are not bit exact, or not
35very efficient on modern processors. This implementation can use MMX instructions
36on Pentium class processors, or alternative methods on other processors. It
37passes all the ETSI test vectors. That is, it is a tested bit exact implementation.
38
39This implementation supports encoded data in one of three packing formats:
40 - Unpacked, with the 76 parameters of a GSM 06.10 code frame each occupying a
41 separate byte. (note that none of the parameters exceed 8 bits).
42 - Packed the the 33 byte per frame, used for VoIP, where 4 bits per frame are wasted.
43 - Packed in WAV49 format, where 2 frames are packed into 65 bytes.
44
45\section gsm0610_page_sec_2 How does it work?
46???.
47*/
48
49enum
50{
51 GSM0610_PACKING_NONE,
52 GSM0610_PACKING_WAV49,
53 GSM0610_PACKING_VOIP
54};
55
56/*!
57 GSM 06.10 FR codec unpacked frame.
58*/
59 typedef struct
60{
61 int16_t LARc[8];
62 int16_t Nc[4];
63 int16_t bc[4];
64 int16_t Mc[4];
65 int16_t xmaxc[4];
66 int16_t xMc[4][13];
67} gsm0610_frame_t;
68
69/*!
70 GSM 06.10 FR codec state descriptor. This defines the state of
71 a single working instance of the GSM 06.10 FR encoder or decoder.
72*/
73typedef struct gsm0610_state_s gsm0610_state_t;
74
75#if defined(__cplusplus)
76extern "C"
77{
78#endif
79
80/*! Initialise a GSM 06.10 encode or decode context.
81 \param s The GSM 06.10 context
82 \param packing One of the GSM0610_PACKING_xxx options.
83 \return A pointer to the GSM 06.10 context, or NULL for error. */
84SPAN_DECLARE(gsm0610_state_t *) gsm0610_init(gsm0610_state_t *s, int packing);
85
86/*! Release a GSM 06.10 encode or decode context.
87 \param s The GSM 06.10 context
88 \return 0 for success, else -1. */
89SPAN_DECLARE(int) gsm0610_release(gsm0610_state_t *s);
90
91/*! Free a GSM 06.10 encode or decode context.
92 \param s The GSM 06.10 context
93 \return 0 for success, else -1. */
94SPAN_DECLARE(int) gsm0610_free(gsm0610_state_t *s);
95
96/*! Set the packing format for a GSM 06.10 encode or decode context.
97 \param s The GSM 06.10 context
98 \param packing One of the GSM0610_PACKING_xxx options.
99 \return 0 for success, else -1. */
100SPAN_DECLARE(int) gsm0610_set_packing(gsm0610_state_t *s, int packing);
101
102/*! Encode a buffer of linear PCM data to GSM 06.10.
103 \param s The GSM 06.10 context.
104 \param code The GSM 06.10 data produced.
105 \param amp The audio sample buffer.
106 \param len The number of samples in the buffer.
107 \return The number of bytes of GSM 06.10 data produced. */
108SPAN_DECLARE(int) gsm0610_encode(gsm0610_state_t *s, uint8_t code[], const int16_t amp[], int len);
109
110/*! Decode a buffer of GSM 06.10 data to linear PCM.
111 \param s The GSM 06.10 context.
112 \param amp The audio sample buffer.
113 \param code The GSM 06.10 data.
114 \param len The number of bytes of GSM 06.10 data to be decoded.
115 \return The number of samples returned. */
116SPAN_DECLARE(int) gsm0610_decode(gsm0610_state_t *s, int16_t amp[], const uint8_t code[], int len);
117
118SPAN_DECLARE(int) gsm0610_pack_none(uint8_t c[], const gsm0610_frame_t *s);
119
120/*! Pack a pair of GSM 06.10 frames in the format used for wave files (wave type 49).
121 \param c The buffer for the packed data. This must be at least 65 bytes long.
122 \param s A pointer to the frames to be packed.
123 \return The number of bytes generated. */
124SPAN_DECLARE(int) gsm0610_pack_wav49(uint8_t c[], const gsm0610_frame_t *s);
125
126/*! Pack a GSM 06.10 frames in the format used for VoIP.
127 \param c The buffer for the packed data. This must be at least 33 bytes long.
128 \param s A pointer to the frame to be packed.
129 \return The number of bytes generated. */
130SPAN_DECLARE(int) gsm0610_pack_voip(uint8_t c[], const gsm0610_frame_t *s);
131
132SPAN_DECLARE(int) gsm0610_unpack_none(gsm0610_frame_t *s, const uint8_t c[]);
133
134/*! Unpack a pair of GSM 06.10 frames from the format used for wave files (wave type 49).
135 \param s A pointer to a buffer into which the frames will be packed.
136 \param c The buffer containing the data to be unpacked. This must be at least 65 bytes long.
137 \return The number of bytes absorbed. */
138SPAN_DECLARE(int) gsm0610_unpack_wav49(gsm0610_frame_t *s, const uint8_t c[]);
139
140/*! Unpack a GSM 06.10 frame from the format used for VoIP.
141 \param s A pointer to a buffer into which the frame will be packed.
142 \param c The buffer containing the data to be unpacked. This must be at least 33 bytes long.
143 \return The number of bytes absorbed. */
144SPAN_DECLARE(int) gsm0610_unpack_voip(gsm0610_frame_t *s, const uint8_t c[]);
145
146#if defined(__cplusplus)
147}
148#endif
149
150#endif
151/*- End of include ---------------------------------------------------------*/
gsm0610_unpack_wav49
int gsm0610_unpack_wav49(gsm0610_frame_t *s, const uint8_t c[])
Definition gsm0610_decode.c:125
gsm0610_decode
int gsm0610_decode(gsm0610_state_t *s, int16_t amp[], const uint8_t code[], int len)
Definition gsm0610_decode.c:312
gsm0610_encode
int gsm0610_encode(gsm0610_state_t *s, uint8_t code[], const int16_t amp[], int len)
Definition gsm0610_encode.c:310
gsm0610_init
gsm0610_state_t * gsm0610_init(gsm0610_state_t *s, int packing)
Definition gsm0610_encode.c:114
gsm0610_free
int gsm0610_free(gsm0610_state_t *s)
Definition gsm0610_encode.c:136
gsm0610_set_packing
int gsm0610_set_packing(gsm0610_state_t *s, int packing)
Definition gsm0610_encode.c:107
gsm0610_pack_wav49
int gsm0610_pack_wav49(uint8_t c[], const gsm0610_frame_t *s)
Definition gsm0610_encode.c:168
gsm0610_release
int gsm0610_release(gsm0610_state_t *s)
Definition gsm0610_encode.c:130
gsm0610_frame_t
Definition gsm0610.h:60
gsm0610_state_s
Definition private/gsm0610.h:34
gsm0610_state_s::packing
int packing
One of the packing modes.
Definition private/gsm0610.h:36