spandsp  0.0.6
ima_adpcm.h
Go to the documentation of this file.
1 /*
2  * SpanDSP - a series of DSP components for telephony
3  *
4  * ima_adpcm.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  * All rights reserved.
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License version 2.1,
15  * as published by the Free Software Foundation.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with this program; if not, write to the Free Software
24  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25  *
26  * Based on a bit from here, a bit from there, eye of toad,
27  * ear of bat, etc - plus, of course, my own 2 cents.
28  */
29 
30 /*! \file */
31 
32 #if !defined(_SPANDSP_IMA_ADPCM_H_)
33 #define _SPANDSP_IMA_ADPCM_H_
34 
35 /*! \page ima_adpcm_page IMA/DVI/Intel ADPCM encoding and decoding
36 \section ima_adpcm_page_sec_1 What does it do?
37 IMA ADPCM offers a good balance of simplicity and quality at a rate of
38 32kbps.
39 
40 \section ima_adpcm_page_sec_2 How does it work?
41 
42 \section ima_adpcm_page_sec_3 How do I use it?
43 */
44 
45 enum
46 {
47  /*! IMA4 is the original IMA ADPCM variant */
49  /*! DVI4 is the IMA ADPCM variant defined in RFC3551 */
51  /*! VDVI is the variable bit rate IMA ADPCM variant defined in RFC3551 */
52  IMA_ADPCM_VDVI = 2
53 };
54 
55 /*!
56  IMA (DVI/Intel) ADPCM conversion state descriptor. This defines the state of
57  a single working instance of the IMA ADPCM converter. This is used for
58  either linear to ADPCM or ADPCM to linear conversion.
59 */
61 
62 #if defined(__cplusplus)
63 extern "C"
64 {
65 #endif
66 
67 /*! Initialise an IMA ADPCM encode or decode context.
68  \param s The IMA ADPCM context.
69  \param variant IMA_ADPCM_IMA4, IMA_ADPCM_DVI4, or IMA_ADPCM_VDVI.
70  \param chunk_size The size of a chunk, in samples. A chunk size of
71  zero sample samples means treat each encode or decode operation
72  as a chunk.
73  \return A pointer to the IMA ADPCM context, or NULL for error. */
75  int variant,
76  int chunk_size);
77 
78 /*! Release an IMA ADPCM encode or decode context.
79  \param s The IMA ADPCM context.
80  \return 0 for OK. */
81 SPAN_DECLARE(int) ima_adpcm_release(ima_adpcm_state_t *s);
82 
83 /*! Free an IMA ADPCM encode or decode context.
84  \param s The IMA ADPCM context.
85  \return 0 for OK. */
86 SPAN_DECLARE(int) ima_adpcm_free(ima_adpcm_state_t *s);
87 
88 /*! Encode a buffer of linear PCM data to IMA ADPCM.
89  \param s The IMA ADPCM context.
90  \param ima_data The IMA ADPCM data produced.
91  \param amp The audio sample buffer.
92  \param len The number of samples in the buffer.
93  \return The number of bytes of IMA ADPCM data produced. */
94 SPAN_DECLARE(int) ima_adpcm_encode(ima_adpcm_state_t *s,
95  uint8_t ima_data[],
96  const int16_t amp[],
97  int len);
98 
99 /*! Decode a buffer of IMA ADPCM data to linear PCM.
100  \param s The IMA ADPCM context.
101  \param amp The audio sample buffer.
102  \param ima_data The IMA ADPCM data
103  \param ima_bytes The number of bytes of IMA ADPCM data
104  \return The number of samples returned. */
105 SPAN_DECLARE(int) ima_adpcm_decode(ima_adpcm_state_t *s,
106  int16_t amp[],
107  const uint8_t ima_data[],
108  int ima_bytes);
109 
110 #if defined(__cplusplus)
111 }
112 #endif
113 
114 #endif
115 /*- End of file ------------------------------------------------------------*/
hdlc_rx_stats_t::aborts
unsigned long int aborts
The number of HDLC aborts received.
Definition: hdlc.h:70
ima_adpcm.h
SIG_STATUS_ABORT
@ SIG_STATUS_ABORT
An abort signal (e.g. an HDLC abort) has been received.
Definition: async.h:73
hdlc_tx_init
hdlc_tx_state_t * hdlc_tx_init(hdlc_tx_state_t *s, int crc32, int inter_frame_flags, int progressive, hdlc_underflow_handler_t handler, void *user_data)
Initialise an HDLC transmitter context.
Definition: hdlc.c:626
hdlc_rx_set_max_frame_len
void hdlc_rx_set_max_frame_len(hdlc_rx_state_t *s, size_t max_len)
Set the maximum frame length for an HDLC receiver context.
Definition: hdlc.c:300
ima_adpcm_encode
int ima_adpcm_encode(ima_adpcm_state_t *s, uint8_t ima_data[], const int16_t amp[], int len)
Definition: ima_adpcm.c:425
hdlc_rx_stats_t::length_errors
unsigned long int length_errors
The number of too short and too long frames received.
Definition: hdlc.h:68
ima_adpcm_state_s::last
int last
The last state of the ADPCM algorithm.
Definition: private/ima_adpcm.h:44
hdlc_rx_set_octet_counting_report_interval
void hdlc_rx_set_octet_counting_report_interval(hdlc_rx_state_t *s, int interval)
Set the octet counting report interval.
Definition: hdlc.c:307
hdlc_rx_stats_t::good_frames
unsigned long int good_frames
The number of good frames received.
Definition: hdlc.h:64
SIG_STATUS_FRAMING_OK
@ SIG_STATUS_FRAMING_OK
Packet framing (e.g. HDLC framing) is OK.
Definition: async.h:69
signal_status_to_str
const char * signal_status_to_str(int status)
Convert a signal status to a short text description.
Definition: async.c:42
ima_adpcm_release
int ima_adpcm_release(ima_adpcm_state_t *s)
Definition: ima_adpcm.c:296
ima_adpcm_free
int ima_adpcm_free(ima_adpcm_state_t *s)
Definition: ima_adpcm.c:302
IMA_ADPCM_IMA4
@ IMA_ADPCM_IMA4
Definition: ima_adpcm.h:48
ima_adpcm_state_s::step_index
int step_index
Current index into the step size table.
Definition: private/ima_adpcm.h:46
ima_adpcm_state_s::ima_byte
uint16_t ima_byte
The current IMA code byte in progress.
Definition: private/ima_adpcm.h:48
saturated.h
hdlc_rx_state_s
Definition: private/hdlc.h:33
IMA_ADPCM_DVI4
@ IMA_ADPCM_DVI4
Definition: ima_adpcm.h:50
ima_adpcm_release
int ima_adpcm_release(ima_adpcm_state_t *s)
Definition: ima_adpcm.c:296
ima_adpcm_state_s
Definition: private/ima_adpcm.h:39
hdlc_rx_get_stats
int hdlc_rx_get_stats(hdlc_rx_state_t *s, hdlc_rx_stats_t *t)
Get the current receive statistics.
Definition: hdlc.c:377
hdlc_rx_stats_t::bytes
unsigned long int bytes
The number of bytes of good frames received (CRC not included).
Definition: hdlc.h:62
ima_adpcm_free
int ima_adpcm_free(ima_adpcm_state_t *s)
Definition: ima_adpcm.c:302
hdlc_rx_init
hdlc_rx_state_t * hdlc_rx_init(hdlc_rx_state_t *s, int crc32, int report_bad_frames, int framing_ok_threshold, hdlc_frame_handler_t handler, void *user_data)
Initialise an HDLC receiver context.
Definition: hdlc.c:327
IMA_ADPCM_VDVI
@ IMA_ADPCM_VDVI
Definition: ima_adpcm.h:52
ima_adpcm_init
ima_adpcm_state_t * ima_adpcm_init(ima_adpcm_state_t *s, int variant, int chunk_size)
Definition: ima_adpcm.c:279
ima_adpcm_decode
int ima_adpcm_decode(ima_adpcm_state_t *s, int16_t amp[], const uint8_t ima_data[], int ima_bytes)
Definition: ima_adpcm.c:309
ima_adpcm_state_s::chunk_size
int chunk_size
The size of a chunk, in samples.
Definition: private/ima_adpcm.h:42
hdlc_tx_corrupt_frame
int hdlc_tx_corrupt_frame(hdlc_tx_state_t *s)
Corrupt the frame currently being transmitted, by giving it the wrong CRC.
Definition: hdlc.c:450
hdlc_rx_stats_t
Definition: hdlc.h:60
hdlc_tx_state_s
Definition: private/hdlc.h:92
hdlc_rx_stats_t::crc_errors
unsigned long int crc_errors
The number of frames with CRC errors received.
Definition: hdlc.h:66
hdlc_tx_frame
int hdlc_tx_frame(hdlc_tx_state_t *s, const uint8_t *frame, size_t len)
Transmit a frame.
Definition: hdlc.c:389
ima_adpcm_init
ima_adpcm_state_t * ima_adpcm_init(ima_adpcm_state_t *s, int variant, int chunk_size)
Definition: ima_adpcm.c:279
ima_adpcm_decode
int ima_adpcm_decode(ima_adpcm_state_t *s, int16_t amp[], const uint8_t ima_data[], int ima_bytes)
Definition: ima_adpcm.c:309
hdlc_tx_abort
int hdlc_tx_abort(hdlc_tx_state_t *s)
Send an abort.
Definition: hdlc.c:440
STEP_MAX
#define STEP_MAX
Definition: ima_adpcm.c:117
hdlc_tx_flags
int hdlc_tx_flags(hdlc_tx_state_t *s, int len)
Transmit a specified quantity of flag octets, typically as a preamble.
Definition: hdlc.c:424
ima_adpcm_encode
int ima_adpcm_encode(ima_adpcm_state_t *s, uint8_t ima_data[], const int16_t amp[], int len)
Definition: ima_adpcm.c:425