comparison spandsp-0.0.3/spandsp-0.0.3/src/spandsp/oki_adpcm.h @ 5:f762bf195c4b

import spandsp-0.0.3
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Fri, 25 Jun 2010 16:00:21 +0200
parents
children
comparison
equal deleted inserted replaced
4:26cd8f1ef0b1 5:f762bf195c4b
1 /*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * oki_adpcm.h - Conversion routines between linear 16 bit PCM data and
5 * OKI (Dialogic) ADPCM format.
6 *
7 * Written by Steve Underwood <steveu@coppice.org>
8 *
9 * Copyright (C) 2001 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: oki_adpcm.h,v 1.13 2006/10/24 13:45:28 steveu Exp $
30 */
31
32 /*! \file */
33
34 #if !defined(_OKI_ADPCM_H_)
35 #define _OKI_ADPCM_H_
36
37 /*! \page okiadpcm_page OKI (Dialogic) ADPCM encoding and decoding
38 \section okiadpcm_page_sec_1 What does it do?
39 OKI ADPCM is widely used in the CTI industry because it is the principal format
40 supported by Dialogic. As the market leader, they tend to define "common
41 practice". It offers a good balance of simplicity and quality at rates of
42 24kbps or 32kbps. 32kbps is obtained by ADPCM compressing 8k samples/second linear
43 PCM. 24kbps is obtained by resampling to 6k samples/second and using the same ADPCM
44 compression algorithm on the slower samples.
45
46 The algorithms for this ADPCM codec can be found in "PC Telephony - The complete guide
47 to designing, building and programming systems using Dialogic and Related Hardware"
48 by Bob Edgar. pg 272-276. */
49
50 /*!
51 Oki (Dialogic) ADPCM conversion state descriptor. This defines the state of
52 a single working instance of the Oki ADPCM converter. This is used for
53 either linear to ADPCM or ADPCM to linear conversion.
54 */
55 typedef struct
56 {
57 int bit_rate;
58 int16_t last;
59 int16_t step_index;
60 uint8_t oki_byte;
61 int16_t history[32];
62 int ptr;
63 int mark;
64 int phase;
65 } oki_adpcm_state_t;
66
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70
71 /*! Initialise an Oki ADPCM encode or decode context.
72 \param s The Oki ADPCM context.
73 \param bit_rate The required bit rate for the ADPCM data.
74 The valid rates are 24000 and 32000.
75 \return A pointer to the Oki ADPCM context, or NULL for error. */
76 oki_adpcm_state_t *oki_adpcm_init(oki_adpcm_state_t *s, int bit_rate);
77
78 /*! Free an Oki ADPCM encode or decode context.
79 \param s The Oki ADPCM context.
80 \return 0 for OK. */
81 int oki_adpcm_release(oki_adpcm_state_t *s);
82
83 /*! Decode a buffer of Oki ADPCM data to linear PCM.
84 \param s The Oki ADPCM context.
85 \param amp The audio sample buffer.
86 \param oki_data
87 \param oki_bytes
88 \return The number of samples returned. */
89 int oki_adpcm_decode(oki_adpcm_state_t *s,
90 int16_t amp[],
91 const uint8_t oki_data[],
92 int oki_bytes);
93
94 /*! Encode a buffer of linear PCM data to Oki ADPCM.
95 \param s The Oki ADPCM context.
96 \param oki_data The Oki ADPCM data produced
97 \param amp The audio sample buffer.
98 \param len The number of samples in the buffer.
99 \return The number of bytes of Oki ADPCM data produced. */
100 int oki_adpcm_encode(oki_adpcm_state_t *s,
101 uint8_t oki_data[],
102 const int16_t amp[],
103 int len);
104
105 #ifdef __cplusplus
106 }
107 #endif
108
109 #endif
110 /*- End of file ------------------------------------------------------------*/

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.