5
|
1 /*
|
|
2 * SpanDSP - a series of DSP components for telephony
|
|
3 *
|
|
4 * imaadpcm.c - Conversion routines between linear 16 bit PCM data and
|
|
5 * IMA/DVI/Intel ADPCM format.
|
|
6 *
|
|
7 * Written by Steve Underwood <steveu@coppice.org>
|
|
8 *
|
|
9 * Copyright (C) 2004 Steve Underwood
|
|
10 *
|
|
11 * Based on a bit from here, a bit from there, eye of toad,
|
|
12 * ear of bat, etc - plus, of course, my own 2 cents.
|
|
13 *
|
|
14 * All rights reserved.
|
|
15 *
|
|
16 * This program is free software; you can redistribute it and/or modify
|
|
17 * it under the terms of the GNU General Public License version 2, as
|
|
18 * published by the Free Software Foundation.
|
|
19 *
|
|
20 * This program is distributed in the hope that it will be useful,
|
|
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
23 * GNU General Public License for more details.
|
|
24 *
|
|
25 * You should have received a copy of the GNU General Public License
|
|
26 * along with this program; if not, write to the Free Software
|
|
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
28 *
|
|
29 * $Id: ima_adpcm.h,v 1.12 2006/10/24 13:45:28 steveu Exp $
|
|
30 */
|
|
31
|
|
32 /*! \file */
|
|
33
|
|
34 #if !defined(_IMA_ADPCM_H_)
|
|
35 #define _IMA_ADPCM_H_
|
|
36
|
|
37 /*! \page ima_adpcm_page IMA/DVI/Intel ADPCM encoding and decoding
|
|
38 \section ima_adpcm_page_sec_1 What does it do?
|
|
39 IMA ADPCM offers a good balance of simplicity and quality at a rate of
|
|
40 32kbps.
|
|
41
|
|
42 \section ima_adpcm_page_sec_2 How does it work?
|
|
43
|
|
44 \section ima_adpcm_page_sec_3 How do I use it?
|
|
45 */
|
|
46
|
|
47 enum
|
|
48 {
|
|
49 IMA_ADPCM_DVI4 = 0,
|
|
50 IMA_ADPCM_VDVI = 1
|
|
51 };
|
|
52
|
|
53 /*!
|
|
54 IMA (DVI/Intel) ADPCM conversion state descriptor. This defines the state of
|
|
55 a single working instance of the IMA ADPCM converter. This is used for
|
|
56 either linear to ADPCM or ADPCM to linear conversion.
|
|
57 */
|
|
58 typedef struct
|
|
59 {
|
|
60 int variant;
|
|
61 int last;
|
|
62 int step_index;
|
|
63 uint16_t ima_byte;
|
|
64 int bits;
|
|
65 } ima_adpcm_state_t;
|
|
66
|
|
67 #ifdef __cplusplus
|
|
68 extern "C" {
|
|
69 #endif
|
|
70
|
|
71 /*! Initialise an IMA ADPCM encode or decode context.
|
|
72 \param s The IMA ADPCM context
|
|
73 \param variant ???
|
|
74 \return A pointer to the IMA ADPCM context, or NULL for error. */
|
|
75 ima_adpcm_state_t *ima_adpcm_init(ima_adpcm_state_t *s, int variant);
|
|
76
|
|
77 /*! Free an IMA ADPCM encode or decode context.
|
|
78 \param s The IMA ADPCM context.
|
|
79 \return 0 for OK. */
|
|
80 int ima_adpcm_release(ima_adpcm_state_t *s);
|
|
81
|
|
82 /*! Encode a buffer of linear PCM data to IMA ADPCM.
|
|
83 \param s The IMA ADPCM context.
|
|
84 \param ima_data The IMA ADPCM data produced.
|
|
85 \param amp The audio sample buffer.
|
|
86 \param len The number of samples in the buffer.
|
|
87 \return The number of bytes of IMA ADPCM data produced. */
|
|
88 int ima_adpcm_encode(ima_adpcm_state_t *s,
|
|
89 uint8_t ima_data[],
|
|
90 const int16_t amp[],
|
|
91 int len);
|
|
92
|
|
93 /*! Decode a buffer of IMA ADPCM data to linear PCM.
|
|
94 \param s The IMA ADPCM context.
|
|
95 \param amp The audio sample buffer.
|
|
96 \param ima_data
|
|
97 \param ima_bytes
|
|
98 \return The number of samples returned. */
|
|
99 int ima_adpcm_decode(ima_adpcm_state_t *s,
|
|
100 int16_t amp[],
|
|
101 const uint8_t ima_data[],
|
|
102 int ima_bytes);
|
|
103
|
|
104 #ifdef __cplusplus
|
|
105 }
|
|
106 #endif
|
|
107
|
|
108 #endif
|
|
109 /*- End of file ------------------------------------------------------------*/
|